configParameters.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. let outputStatuses = [];
  2. /**
  3. * Logs the status of a rule with padded formatting and stores it in the `outputStatuses` array.
  4. * If the rule already exists in the array, its status is updated.
  5. * @param message The name of the rule
  6. * @param status The output (exit) status of the rule
  7. */
  8. function recordRuleExitStatus(message, status) {
  9. // Check if the rule already exists in the array
  10. const existingRecord = outputStatuses.find(
  11. (rule) => rule.message === message
  12. );
  13. if (existingRecord) {
  14. // Update the status of the existing rule
  15. existingRecord.status = status;
  16. } else {
  17. // If the rule doesn't exist, add it to the array
  18. outputStatuses.push({ message, status });
  19. }
  20. }
  21. /**
  22. * Displays all the rule output statuses stored in the `outputStatuses` array.
  23. * Filters out any empty lines, sorts them alphabetically, and prints the statuses
  24. * with a header and separator.
  25. * These statuses are later displayed in CI job tracelog.
  26. */
  27. function displayAllOutputStatuses() {
  28. const lineLength = 100;
  29. const sortedStatuses = outputStatuses.sort((a, b) =>
  30. a.message.localeCompare(b.message)
  31. );
  32. const formattedLines = sortedStatuses.map((statusObj) => {
  33. const paddingLength =
  34. lineLength - statusObj.message.length - statusObj.status.length;
  35. const paddedMessage = statusObj.message.padEnd(
  36. statusObj.message.length + paddingLength,
  37. "."
  38. );
  39. return `${paddedMessage} ${statusObj.status}`;
  40. });
  41. console.log(
  42. "DangerJS checks (rules) output states:\n" + "=".repeat(lineLength + 2)
  43. );
  44. console.log(formattedLines.join("\n"));
  45. console.log("=".repeat(lineLength + 2));
  46. }
  47. module.exports = {
  48. displayAllOutputStatuses,
  49. recordRuleExitStatus,
  50. };