Skip to content

Commit 6f5bd46

Browse files
committed
Add github action to file github issues based on errors detected in report
only for ill-formed and invalid w3c.json at this time. Part of #74
1 parent 71a88a0 commit 6f5bd46

9 files changed

+561
-5
lines changed

.github/workflows/clean-reports.yml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Clean reports when issues/PR are closed
2+
3+
on:
4+
schedule:
5+
- cron: '30 3 * * 3'
6+
workflow_dispatch:
7+
jobs:
8+
clean:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout validate-repos
12+
uses: actions/checkout@v3
13+
14+
- name: Setup node.js
15+
uses: actions/setup-node@v2
16+
with:
17+
node-version: 18
18+
19+
- name: Install dependencies
20+
run: |
21+
npm ci
22+
23+
- name: Drop reports locally when related issues/PR are closed
24+
run: node src/reporting/clean-reports.js
25+
env:
26+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27+
28+
- name: Create PR to drop reports from repo if needed
29+
uses: peter-evans/create-pull-request@v3
30+
env:
31+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32+
with:
33+
title: Drop reports whose related issues have been closed
34+
commit-message: "Drop reports whose related issues have been closed"
35+
body: ${{ env.dropped_reports }}
36+
assignees: dontcallmedom
37+
branch: clean-reports
38+
branch-suffix: timestamp
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
on:
2+
workflow_dispatch:
3+
4+
name: Submit draft issue reports from Strudy analysis
5+
jobs:
6+
update:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Setup node.js
10+
uses: actions/setup-node@v2
11+
with:
12+
node-version: 18
13+
- name: Checkout validate-repos
14+
uses: actions/checkout@v2
15+
- name: Install dependencies
16+
run: npm ci
17+
- name: Configure git
18+
run: |
19+
git config user.name "w3c-validate-bot"
20+
git config user.email "<>"
21+
git remote set-url --push origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
22+
- name: Run issue filer script
23+
run: node reporting/file-issue-for-review.js
24+
env:
25+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26+
27+

.github/workflows/submit-issue.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
on:
2+
workflow_dispatch:
3+
4+
name: Submit issue from validate-repos to relevant github repo
5+
jobs:
6+
update:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Setup node.js
10+
uses: actions/setup-node@v2
11+
with:
12+
node-version: 18
13+
- name: Checkout validate-repos
14+
uses: actions/checkout@v2
15+
- name: Install dependencies
16+
run: npm ci
17+
- name: Configure git
18+
run: |
19+
git config user.name "w3c-validate-bot"
20+
git config user.email "<>"
21+
git remote set-url --push origin https://x-access-token:${{ secrets.ISSUE_REPORT_GH_TOKEN }}@github.com/$GITHUB_REPOSITORY
22+
- name: Run issue submitter script
23+
run: node src/reporting/submit-issue.js
24+
env:
25+
GH_TOKEN: ${{ secrets.ISSUE_REPORT_GH_TOKEN }}
26+
27+

issue-reports/.gitkeep

Whitespace-only changes.

package-lock.json

+63-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"dependencies": {
1313
"@octokit/core": "^3.6.0",
1414
"@octokit/plugin-throttling": "^3.5.2",
15+
"gray-matter": "^4.0.3",
1516
"node-fetch": "^2.6.7",
1617
"node-w3capi": "^2.1.0"
1718
},

reporting/clean-reports.js

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/**
2+
* Check GitHub issues and pull requests referenced by reports and create
3+
* a pull request to drop reports that have been addressed.
4+
*/
5+
6+
const core = require('@actions/core');
7+
const octokit = require('../lib/octokit');
8+
const fs = require('fs');
9+
const path = require('path');
10+
const matter = require('gray-matter');
11+
12+
const issueReportDir = "issue-reports";
13+
14+
/**
15+
* Check GitHub issues and PR referenced by patch files and drop patch files
16+
* that only reference closed issues and PR.
17+
*
18+
* @function
19+
* @return {String} A GitHub flavored markdown string that describes what
20+
* patches got dropped and why. To be used in a possible PR. Returns an
21+
* empty string when there are no patches to drop.
22+
*/
23+
async function dropReportsWhenPossible () {
24+
const rootDir = path.join(__dirname, '../../issues');
25+
26+
console.log('Gather reports files');
27+
let reports = [];
28+
const files = fs.readdirSync(rootDir);
29+
for (const file of files) {
30+
if (file.endsWith('.md')) {
31+
const report = path.join(rootDir, file);
32+
console.log(`- add "${report}"`);
33+
reports.push({ name: report });
34+
}
35+
}
36+
37+
console.log();
38+
console.log('Extract list of issues');
39+
const issueUrl = /^https:\/\/github\.com\/([^/]+)\/([^/]+)\/(issues|pull)\/(\d+)$/;
40+
for (const report of reports) {
41+
let contents;
42+
try {
43+
contents = matter(await fs.promises.readFile(report.name, 'utf-8'));
44+
} catch (e) {
45+
console.error(`- "${report.name}" has invalid YAML`);
46+
continue;
47+
}
48+
const tracked = contents.data.Tracked;
49+
const m = tracked.match(issueUrl);
50+
if (m) {
51+
report.issue = {
52+
owner: m[1],
53+
repo: m[2],
54+
number: parseInt(m[4], 10),
55+
url: tracked
56+
};
57+
console.log(`- "${report.name}" linked to ${report.issue.url}`);
58+
} else {
59+
console.log(`- "${report.name}" not linked to any issue`);
60+
}
61+
}
62+
reports = reports.filter(report => report.issue);
63+
64+
console.log();
65+
console.log('Check status of GitHub issues/PR');
66+
for (const { issue } of reports) {
67+
const response = await octokit.issues.get({
68+
owner: issue.owner,
69+
repo: issue.repo,
70+
issue_number: issue.number
71+
});
72+
issue.state = response?.data?.state ?? 'unknown';
73+
console.log(`- [${issue.state}] ${issue.url}`);
74+
}
75+
76+
console.log();
77+
console.log('Drop reports when possible');
78+
reports = reports.filter(report => report.issue.state === 'closed');
79+
if (reports.length > 0) {
80+
const res = [];
81+
for (const report of reports) {
82+
console.log(`- drop "${report.name}"`);
83+
fs.unlinkSync(report.name);
84+
res.push(`- \`${report.name}\` was linked to now closed: [${report.issue.owner}/${report.issue.repo}#${report.issue.number}](${report.issue.url})`);
85+
}
86+
return res.join('\n');
87+
} else {
88+
console.log('- No report to drop at this time');
89+
return '';
90+
}
91+
}
92+
93+
94+
dropReportsWhenPossible()
95+
.then(res => {
96+
core.exportVariable('dropped_reports', res);
97+
console.log();
98+
console.log('Set dropped_reports env variable');
99+
console.log(res);
100+
console.log('== The end ==');
101+
})
102+
.catch(err => {
103+
console.error(err);
104+
process.exit(1);
105+
});

0 commit comments

Comments
 (0)