Skip to content

Commit

Permalink
Adjust --update-mode options
Browse files Browse the repository at this point in the history
This makes the following changes to the `--update-mode` modes:
- Make "tracked" and "untracked" extend "old"
- Make "tracked" mean "tracked through a GitHub issue. As a corollary,
untracked now means "not tracked or tracked with a comment that is not a GitHub
URL".

The job now uses the "untracked" mode, meaning it will update reports that we
decided not to track when an update is detected.
  • Loading branch information
tidoust authored and dontcallmedom committed Sep 6, 2024
1 parent a00f72f commit c04a57c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/file-issue-for-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
run: |
node strudy.js inspect ../webref \
--issues issues \
--update-mode old \
--update-mode untracked \
--cc ${{ vars.CC }} \
--what brokenLinks \
--what discontinuedReferences \
Expand Down
14 changes: 8 additions & 6 deletions strudy.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,10 @@ Usage notes for some of the options:
"new" (default) preserve existing files
"old" preserve existing files but get rid of old ones for which
study reveals no more issue
"untracked" update existing files that do not have a "Tracked" URL
"tracked" update existing files that have a "Tracked" URL
"untracked" same as "old" but also update existing files that do not
have a "Tracked" URL
"tracked" same as "old" but also update existing files that have a
"Tracked" URL
"all" update all existing files, deleting them when needed
Strudy will always create new issue files, the mode only changes the behavior
Expand Down Expand Up @@ -335,6 +337,7 @@ Format must be one of "json" or "markdown".`)
// Caller wants to add/update issue files in the provided folder.
// Issue files are formatted with the gray-matter library to save useful
// metadata as front matter in the file.
const issueUrl = /^https:\/\/github\.com\/([^/]+)\/([^/]+)\/(issues|pull)\/(\d+)$/;
let reported = 0;
for (const entry of anomaliesReport.results) {
const filename = path.join(options.issues, `${entry.name}.md`);
Expand All @@ -348,8 +351,8 @@ Format must be one of "json" or "markdown".`)
}
existingReport = matter(await fs.readFile(filename, 'utf-8'));
tracked = existingReport.data.Tracked ?? 'N/A';
if ((options.updateMode === 'tracked' && tracked === 'N/A') ||
(options.updateMode === 'untracked' && tracked !== 'N/A')) {
if ((options.updateMode === 'tracked' && !tracked.match(issueUrl)) ||
(options.updateMode === 'untracked' && tracked.match(issueUrl))) {
console.warn(`- skip ${filename}, file already exists, with Tracked="${tracked}"`);
continue;
}
Expand Down Expand Up @@ -388,8 +391,7 @@ ${entry.content}
}
}

if (options.updateMode === 'old' ||
options.updateMode === 'all') {
if (options.updateMode !== 'new') {
const reportFiles = await fs.readdir(options.issues);
const todelete = reportFiles.filter(file =>
anomaliesReport.looksGood.find(name => file === `${name}.md`));
Expand Down

0 comments on commit c04a57c

Please sign in to comment.