| | import { program } from 'commander' |
| | import fs from 'fs' |
| | import coreLib from '@actions/core' |
| |
|
| | import github from '@/workflows/github' |
| | import { getEnvInputs } from '@/workflows/get-env-inputs' |
| | import { createReportIssue, linkReports } from '@/workflows/issue-report' |
| | import { getAllRuleNames } from '@/content-linter/lib/helpers/rule-utils' |
| |
|
| | |
| | const MAX_ISSUE_BODY_SIZE = 60000 |
| |
|
| | |
| | const MAX_WARNINGS_BEFORE_ALERT = 20 |
| |
|
| | |
| | |
| | |
| | export const reportingConfig = { |
| | |
| | includeSeverities: ['error', 'warning'], |
| | |
| | includeRules: ['expired-content'], |
| | } |
| |
|
| | interface LintFlaw { |
| | severity: string |
| | ruleNames: string[] |
| | errorDetail?: string |
| | } |
| |
|
| | |
| | |
| | |
| | function shouldIncludeInReport(flaw: LintFlaw): boolean { |
| | const allRuleNames = getAllRuleNames(flaw) |
| |
|
| | |
| | if (reportingConfig.includeSeverities.includes(flaw.severity)) { |
| | return true |
| | } |
| |
|
| | |
| | const hasIncludedRule = allRuleNames.some((ruleName: string) => |
| | reportingConfig.includeRules.includes(ruleName), |
| | ) |
| | if (hasIncludedRule) { |
| | return true |
| | } |
| |
|
| | return false |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | program |
| | .description( |
| | 'Opens an issue for Content FR with the errors and warnings from the weekly content/data linter.', |
| | ) |
| | .option( |
| | '-p, --path <path>', |
| | 'provide a path to the errors and warnings output json file that will be in the issue body', |
| | ) |
| | .parse(process.argv) |
| |
|
| | const { path } = program.opts() |
| |
|
| | main() |
| | async function main() { |
| | const lintResults = fs.readFileSync(`${path}`, 'utf8') |
| | const core = coreLib |
| | const { REPORT_REPOSITORY, REPORT_AUTHOR, REPORT_LABEL } = process.env |
| |
|
| | const octokit = github() |
| | |
| | |
| | getEnvInputs(['GITHUB_TOKEN']) |
| |
|
| | core.info(`Creating issue for configured lint rules...`) |
| |
|
| | const parsedResults = JSON.parse(lintResults) |
| |
|
| | |
| | let totalWarnings = 0 |
| |
|
| | |
| | const filteredResults: Record<string, LintFlaw[]> = {} |
| | for (const [file, flaws] of Object.entries(parsedResults)) { |
| | const filteredFlaws = (flaws as LintFlaw[]).filter((flaw) => shouldIncludeInReport(flaw)) |
| |
|
| | |
| | if (filteredFlaws.length > 0) { |
| | totalWarnings += filteredFlaws.filter((flaw) => flaw.severity === 'warning').length |
| | filteredResults[file] = filteredFlaws |
| | } |
| | } |
| | const totalFiles = Object.keys(filteredResults).length |
| |
|
| | const showTooManyWarningsAlert = totalWarnings > MAX_WARNINGS_BEFORE_ALERT |
| | const tooManyWarningsAlertText = showTooManyWarningsAlert |
| | ? `**Alert**: ${totalWarnings} warning-level issues have been found. These must be addressed ASAP so they do not continue to accumulate.\n\n` |
| | : '' |
| | let reportBody = `${tooManyWarningsAlertText}The following files have markdown lint issues that require attention:\n\n` |
| | let filesIncluded = 0 |
| | let truncated = false |
| |
|
| | for (const [file, flaws] of Object.entries(filteredResults)) { |
| | const fileEntry = `File: \`${file}\`:\n\`\`\`json\n${JSON.stringify(flaws, null, 2)}\n\`\`\`\n` |
| |
|
| | |
| | if (reportBody.length + fileEntry.length > MAX_ISSUE_BODY_SIZE) { |
| | truncated = true |
| | break |
| | } |
| |
|
| | reportBody += fileEntry |
| | filesIncluded++ |
| | } |
| |
|
| | |
| | if (truncated) { |
| | const remaining = totalFiles - filesIncluded |
| | reportBody += `\n---\n\n⚠️ **Output truncated**: Showing ${filesIncluded} of ${totalFiles} files with lint issues. ${remaining} additional files have been omitted to stay within GitHub's issue size limits.\n` |
| | reportBody += `\nTo see all results, run the linter locally:\n\`\`\`bash\nnpm run lint-content -- --paths content data\n\`\`\`\n` |
| | } |
| |
|
| | const reportProps = { |
| | core, |
| | octokit, |
| | reportTitle: `Content linting issues requiring attention`, |
| | reportBody, |
| | reportRepository: REPORT_REPOSITORY!, |
| | reportLabel: REPORT_LABEL!, |
| | } |
| |
|
| | const newReport = await createReportIssue(reportProps) |
| |
|
| | const linkProps = { |
| | core, |
| | octokit, |
| | newReport, |
| | reportRepository: REPORT_REPOSITORY!, |
| | reportAuthor: REPORT_AUTHOR!, |
| | reportLabel: REPORT_LABEL!, |
| | } |
| |
|
| | await linkReports(linkProps) |
| | } |
| |
|