All files / libs/tools/plugin/src/executors/support-weather executor.ts

0% Statements 0/60
0% Branches 0/1
0% Functions 0/1
0% Lines 0/60

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61                                                                                                                         
import { type Executor } from '@nx/devkit';

import {
  buildComputationErrorMessage,
  buildRefreshmentsErrorMessage,
  getComputationLogs,
  getRefreshmentsLogs,
} from './gcpLogs';
import { getLastPipelineStatus, getPipelineStatusEmoji } from './gitlabApiCalls';
import { getJiraSupportTickets } from './jira-tickets';

const getDate = () => {
  const date = new Date();
  const month = `${date.getMonth() + 1}`.padStart(2, '0');
  const day = `${date.getDate()}`.padStart(2, '0');
  return `${date.getFullYear()}-${month}-${day}`;
};

export const executor: Executor = async () => {
  const jobsWithStatus = await getLastPipelineStatus();
  const supportIssues = await getJiraSupportTickets();
  const refreshmentsLogs = await getRefreshmentsLogs();
  const calculationLogs = await getComputationLogs();

  const weather = `Daily support weather *${getDate()}* -- Build ${getPipelineStatusEmoji(jobsWithStatus.build)}, Cypress ${getPipelineStatusEmoji(jobsWithStatus['e2e:mocked'])}, Sonar ${getPipelineStatusEmoji(jobsWithStatus.sonar)}

*Support*:

${supportIssues.map((issue) => `  - ${issue}`).join('\n')}

*Data imports*:
${Object.entries(Object.groupBy(refreshmentsLogs.errors, (error) => error.companyName ?? 'undefined'))
  .map(
    ([company, errors]) => `  - \`${company}\`:
${errors!.map((e) => `      - ${buildRefreshmentsErrorMessage(e)}`).join('\n')}\n`,
  )
  .join('')}

*Computations*:
${Object.entries(Object.groupBy(calculationLogs.errors, (error) => error.companyName ?? 'undefined'))
  .map(
    ([company, errors]) => `  - \`${company}\`:
${errors!.map((e) => `      - ${buildComputationErrorMessage(e)}`).join('\n')}\n`,
  )
  .join('')}
 `;

  // eslint-disable-next-line no-console
  console.log(weather);
  // eslint-disable-next-line no-console
  console.log(`Refreshments unknown errors: ${refreshmentsLogs.unknownErrors.length}`, refreshmentsLogs.unknownErrors);
  // eslint-disable-next-line no-console
  console.log(`Computation unknown errors: ${calculationLogs.unknownErrors.length}`, calculationLogs.unknownErrors);

  return {
    success: true,
  };
};

export default executor;