Skip to content

Commit

Permalink
Reduce linkchecker spam (#1916)
Browse files Browse the repository at this point in the history
* Test linkchecker behavior

* Add permissions to linkchecker

* Removed test link failure

* Tidy up extraneous comment
  • Loading branch information
nikitawootten-nist authored and Arminta-Jenkins-NIST committed Sep 12, 2023
1 parent 53021fa commit 6661368
Showing 1 changed file with 62 additions and 7 deletions.
69 changes: 62 additions & 7 deletions .github/workflows/periodic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ jobs:
linkcheck:
name: Validate Markdown Links
runs-on: ubuntu-22.04
permissions:
# Needed to post comments and issues
issues: write
steps:
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744
with:
Expand All @@ -21,12 +24,64 @@ jobs:
run: |
make linkcheck
working-directory: build
- name: Create an issue if bad links are detected
- name: Create an issue or comment if bad links are detected
if: failure()
uses: peter-evans/create-issue-from-file@433e51abf769039ee20ba1293a088ca19d573b7f # v3.0.0
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410
with:
title: Scheduled Check of Markdown Documents Found Bad Hyperlinks
content-filepath: build/generated/mlc_report.log
labels: |
bug
Scope: Documentation
script: |
// Read the markdown linkcheck report
const fs = require('fs');
const body = fs.readFileSync('build/generated/mlc_report.log', 'utf8');
const title = "Scheduled Check of Markdown Documents Found Bad Hyperlinks";
const labels = ["bug", "Scope: Documentation"];
// Find open linkchecker issues
const query = `query($owner:String!, $name:String!, $labels:[String!], $user:String!) {
repository(owner:$owner, name:$name) {
issues(first: 100, orderBy: {
direction: DESC,
field: CREATED_AT
}, filterBy: {
createdBy: $user,
labels: $labels,
states: OPEN
}) {
nodes {
title
number
}
}
}
}`;
const result = await github.graphql(query, {
owner: context.repo.owner,
name: context.repo.repo,
labels: labels,
user: "github-actions[bot]"
});
// find the first issue with a matching title, and create a comment
for (const issue of result.repository.issues.nodes) {
if (issue.title !== title) {
continue;
}
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body
});
return;
}
// or, if none were found, create an issue
github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title,
body,
labels
});

0 comments on commit 6661368

Please sign in to comment.