1
0
mirror of synced 2026-01-01 18:05:46 -05:00
Files
docs/.github/actions-scripts/post-lints.js
Grace Park 76a5f0dc36 Pretty print json (#42809)
Co-authored-by: Peter Bengtsson <peterbe@github.com>
2023-09-18 18:16:17 +00:00

76 lines
2.1 KiB
JavaScript

#!/usr/bin/env node
import { program } from 'commander'
import fs from 'fs'
import coreLib from '@actions/core'
import github from '../../script/helpers/github.js'
import { getEnvInputs } from './lib/get-env-inputs.js'
import { createReportIssue, linkReports } from './lib/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 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 from the weekly content/data linter.')
.option(
'-p, --path <path>',
'provide a path to the errors output json file that will be in the issue body',
)
.parse(process.argv)
const { path } = program.opts()
main()
async function main() {
const errors = 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...`)
let reportBody = 'The following files have markdown lint warnings/errors:\n\n'
for (const [file, flaws] of Object.entries(JSON.parse(errors))) {
reportBody += `File: \`${file}\`:\n`
reportBody += `\`\`\`json\n${JSON.stringify(flaws, null, 2)}\n\`\`\`\n`
}
const reportProps = {
core,
octokit,
reportTitle: `Error(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)
}