-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add github action to file github issues based on errors detected in r…
…eport only for ill-formed and invalid w3c.json at this time. Part of #74
- Loading branch information
1 parent
71a88a0
commit 6f5bd46
Showing
9 changed files
with
561 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: Clean reports when issues/PR are closed | ||
|
||
on: | ||
schedule: | ||
- cron: '30 3 * * 3' | ||
workflow_dispatch: | ||
jobs: | ||
clean: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout validate-repos | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: 18 | ||
|
||
- name: Install dependencies | ||
run: | | ||
npm ci | ||
- name: Drop reports locally when related issues/PR are closed | ||
run: node src/reporting/clean-reports.js | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Create PR to drop reports from repo if needed | ||
uses: peter-evans/create-pull-request@v3 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
title: Drop reports whose related issues have been closed | ||
commit-message: "Drop reports whose related issues have been closed" | ||
body: ${{ env.dropped_reports }} | ||
assignees: dontcallmedom | ||
branch: clean-reports | ||
branch-suffix: timestamp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
on: | ||
workflow_dispatch: | ||
|
||
name: Submit draft issue reports from Strudy analysis | ||
jobs: | ||
update: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Setup node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: 18 | ||
- name: Checkout validate-repos | ||
uses: actions/checkout@v2 | ||
- name: Install dependencies | ||
run: npm ci | ||
- name: Configure git | ||
run: | | ||
git config user.name "w3c-validate-bot" | ||
git config user.email "<>" | ||
git remote set-url --push origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY | ||
- name: Run issue filer script | ||
run: node reporting/file-issue-for-review.js | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
on: | ||
workflow_dispatch: | ||
|
||
name: Submit issue from validate-repos to relevant github repo | ||
jobs: | ||
update: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Setup node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: 18 | ||
- name: Checkout validate-repos | ||
uses: actions/checkout@v2 | ||
- name: Install dependencies | ||
run: npm ci | ||
- name: Configure git | ||
run: | | ||
git config user.name "w3c-validate-bot" | ||
git config user.email "<>" | ||
git remote set-url --push origin https://x-access-token:${{ secrets.ISSUE_REPORT_GH_TOKEN }}@github.com/$GITHUB_REPOSITORY | ||
- name: Run issue submitter script | ||
run: node src/reporting/submit-issue.js | ||
env: | ||
GH_TOKEN: ${{ secrets.ISSUE_REPORT_GH_TOKEN }} | ||
|
||
|
Empty file.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/** | ||
* Check GitHub issues and pull requests referenced by reports and create | ||
* a pull request to drop reports that have been addressed. | ||
*/ | ||
|
||
const core = require('@actions/core'); | ||
const octokit = require('../lib/octokit'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const matter = require('gray-matter'); | ||
|
||
const issueReportDir = "issue-reports"; | ||
|
||
/** | ||
* Check GitHub issues and PR referenced by patch files and drop patch files | ||
* that only reference closed issues and PR. | ||
* | ||
* @function | ||
* @return {String} A GitHub flavored markdown string that describes what | ||
* patches got dropped and why. To be used in a possible PR. Returns an | ||
* empty string when there are no patches to drop. | ||
*/ | ||
async function dropReportsWhenPossible () { | ||
const rootDir = path.join(__dirname, '../../issues'); | ||
|
||
console.log('Gather reports files'); | ||
let reports = []; | ||
const files = fs.readdirSync(rootDir); | ||
for (const file of files) { | ||
if (file.endsWith('.md')) { | ||
const report = path.join(rootDir, file); | ||
console.log(`- add "${report}"`); | ||
reports.push({ name: report }); | ||
} | ||
} | ||
|
||
console.log(); | ||
console.log('Extract list of issues'); | ||
const issueUrl = /^https:\/\/github\.com\/([^/]+)\/([^/]+)\/(issues|pull)\/(\d+)$/; | ||
for (const report of reports) { | ||
let contents; | ||
try { | ||
contents = matter(await fs.promises.readFile(report.name, 'utf-8')); | ||
} catch (e) { | ||
console.error(`- "${report.name}" has invalid YAML`); | ||
continue; | ||
} | ||
const tracked = contents.data.Tracked; | ||
const m = tracked.match(issueUrl); | ||
if (m) { | ||
report.issue = { | ||
owner: m[1], | ||
repo: m[2], | ||
number: parseInt(m[4], 10), | ||
url: tracked | ||
}; | ||
console.log(`- "${report.name}" linked to ${report.issue.url}`); | ||
} else { | ||
console.log(`- "${report.name}" not linked to any issue`); | ||
} | ||
} | ||
reports = reports.filter(report => report.issue); | ||
|
||
console.log(); | ||
console.log('Check status of GitHub issues/PR'); | ||
for (const { issue } of reports) { | ||
const response = await octokit.issues.get({ | ||
owner: issue.owner, | ||
repo: issue.repo, | ||
issue_number: issue.number | ||
}); | ||
issue.state = response?.data?.state ?? 'unknown'; | ||
console.log(`- [${issue.state}] ${issue.url}`); | ||
} | ||
|
||
console.log(); | ||
console.log('Drop reports when possible'); | ||
reports = reports.filter(report => report.issue.state === 'closed'); | ||
if (reports.length > 0) { | ||
const res = []; | ||
for (const report of reports) { | ||
console.log(`- drop "${report.name}"`); | ||
fs.unlinkSync(report.name); | ||
res.push(`- \`${report.name}\` was linked to now closed: [${report.issue.owner}/${report.issue.repo}#${report.issue.number}](${report.issue.url})`); | ||
} | ||
return res.join('\n'); | ||
} else { | ||
console.log('- No report to drop at this time'); | ||
return ''; | ||
} | ||
} | ||
|
||
|
||
dropReportsWhenPossible() | ||
.then(res => { | ||
core.exportVariable('dropped_reports', res); | ||
console.log(); | ||
console.log('Set dropped_reports env variable'); | ||
console.log(res); | ||
console.log('== The end =='); | ||
}) | ||
.catch(err => { | ||
console.error(err); | ||
process.exit(1); | ||
}); |
Oops, something went wrong.