-
Notifications
You must be signed in to change notification settings - Fork 66.9k
Expand file tree
/
Copy pathpost-lints.js
More file actions
75 lines (63 loc) · 2.22 KB
/
post-lints.js
File metadata and controls
75 lines (63 loc) · 2.22 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { program } from 'commander'
import fs from 'fs'
import coreLib from '@actions/core'
import github from '#src/workflows/github.ts'
import { getEnvInputs } from '#src/workflows/get-env-inputs.ts'
import { createReportIssue, linkReports } from '#src/workflows/issue-report.js'
// [start-readme]
//
// This script runs once a week via a scheduled GitHub Action to lint
// the entire content and data directories based on our
// markdownlint.js rules.
//
// If errors or warnings are found, it will open up a new issue in the
// docs-content repo with the label "broken content markdown report".
//
// The Content FR will go through the issue and update the content and
// data files accordingly.
//
// [end-readme]
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()
// `GITHUB_TOKEN` is optional. If you need the token to post a comment
// or open an issue report, you might get cryptic error messages from Octokit.
getEnvInputs(['GITHUB_TOKEN'])
core.info(`Creating issue for errors and warnings...`)
let reportBody = 'The following files have markdown lint warnings/errors:\n\n'
for (const [file, flaws] of Object.entries(JSON.parse(lintResults))) {
reportBody += `File: \`${file}\`:\n`
reportBody += `\`\`\`json\n${JSON.stringify(flaws, null, 2)}\n\`\`\`\n`
}
const reportProps = {
core,
octokit,
reportTitle: `Error(s) and warning(s) in content markdown file(s)`,
reportBody,
reportRepository: REPORT_REPOSITORY,
reportLabel: REPORT_LABEL,
}
await createReportIssue(reportProps)
const linkProps = {
core,
octokit,
newReport: await createReportIssue(reportProps),
reportRepository: REPORT_REPOSITORY,
reportAuthor: REPORT_AUTHOR,
reportLabel: REPORT_LABEL,
}
await linkReports(linkProps)
}