Skip to content

Commit 06262b8

Browse files
Merge pull request #198 from rocky-linux/feature/url-check
Add automated URL checker for downloads.json
2 parents 9fa299c + 121287b commit 06262b8

File tree

2 files changed

+116
-12
lines changed

2 files changed

+116
-12
lines changed

.github/workflows/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ chmod +x scripts/check-download-urls.js
4040
- **Progress indicator**: Shows real-time progress when run locally
4141
- **Detailed reporting**: Shows the JSON path and error details for each failed URL
4242
- **GitHub integration**: Automatically comments on PRs and creates issues for scheduled runs
43+
- **Smart notifications**:
44+
- Updates existing PR comments instead of creating duplicates
45+
- Updates existing issues instead of creating new ones daily
46+
- Automatically closes issues when all URLs are fixed
47+
- **Prevents spam**: Only one issue and one PR comment per problem
4348

4449
#### Expected behavior:
4550

.github/workflows/check-download-urls.yml

Lines changed: 111 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,54 @@ jobs:
2929
node-version: '20'
3030

3131
- name: Extract and check URLs
32+
id: url-check
3233
run: node scripts/check-download-urls.js
3334
env:
3435
GITHUB_ACTIONS: true
36+
continue-on-error: true
3537

3638
- name: Comment PR on failure
37-
if: failure() && github.event_name == 'pull_request'
39+
if: steps.url-check.outcome == 'failure' && github.event_name == 'pull_request'
3840
uses: actions/github-script@v7
3941
with:
4042
script: |
4143
const fs = require('fs');
4244
if (fs.existsSync('url-check-summary.md')) {
4345
const summary = fs.readFileSync('url-check-summary.md', 'utf8');
44-
github.rest.issues.createComment({
46+
47+
// Check for existing comments from this workflow
48+
const comments = await github.rest.issues.listComments({
4549
issue_number: context.issue.number,
4650
owner: context.repo.owner,
47-
repo: context.repo.repo,
48-
body: summary
51+
repo: context.repo.repo
4952
});
53+
54+
const botComment = comments.data.find(comment =>
55+
comment.user.type === 'Bot' &&
56+
comment.body.includes('🚨 URL Check Failed')
57+
);
58+
59+
if (botComment) {
60+
// Update existing comment
61+
await github.rest.issues.updateComment({
62+
comment_id: botComment.id,
63+
owner: context.repo.owner,
64+
repo: context.repo.repo,
65+
body: summary + '\n\n*Updated: ' + new Date().toISOString() + '*'
66+
});
67+
} else {
68+
// Create new comment
69+
await github.rest.issues.createComment({
70+
issue_number: context.issue.number,
71+
owner: context.repo.owner,
72+
repo: context.repo.repo,
73+
body: summary
74+
});
75+
}
5076
}
5177
52-
- name: Create issue on scheduled run failure
53-
if: failure() && github.event_name == 'schedule'
78+
- name: Create or update issue on scheduled run failure
79+
if: steps.url-check.outcome == 'failure' && github.event_name == 'schedule'
5480
uses: actions/github-script@v7
5581
with:
5682
script: |
@@ -63,12 +89,85 @@ jobs:
6389
body += 'The URL checker found broken links in downloads.json. Please check the workflow logs for details.';
6490
}
6591
66-
body += '\n\n[View workflow run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})';
92+
body += '\n\n[View latest workflow run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})';
6793
68-
github.rest.issues.create({
94+
// Check for existing open issues
95+
const issues = await github.rest.issues.listForRepo({
6996
owner: context.repo.owner,
7097
repo: context.repo.repo,
71-
title: 'Broken download URLs detected',
72-
body: body,
73-
labels: ['bug', 'downloads']
74-
});
98+
state: 'open',
99+
labels: 'downloads,url-check-failed'
100+
});
101+
102+
const existingIssue = issues.data.find(issue =>
103+
issue.title === 'Broken download URLs detected'
104+
);
105+
106+
if (existingIssue) {
107+
// Add comment to existing issue
108+
await github.rest.issues.createComment({
109+
issue_number: existingIssue.number,
110+
owner: context.repo.owner,
111+
repo: context.repo.repo,
112+
body: body + '\n\n*Check performed at: ' + new Date().toISOString() + '*'
113+
});
114+
console.log(`Updated existing issue #${existingIssue.number}`);
115+
} else {
116+
// Create new issue
117+
await github.rest.issues.create({
118+
owner: context.repo.owner,
119+
repo: context.repo.repo,
120+
title: 'Broken download URLs detected',
121+
body: body + '\n\n*First detected: ' + new Date().toISOString() + '*\n\nThis issue will be automatically updated with new checks until resolved.',
122+
labels: ['bug', 'downloads', 'url-check-failed']
123+
});
124+
console.log('Created new issue for broken URLs');
125+
}
126+
127+
- name: Close issue if URLs are fixed
128+
if: steps.url-check.outcome == 'success' && github.event_name == 'schedule'
129+
uses: actions/github-script@v7
130+
with:
131+
script: |
132+
// Check for existing open issues
133+
const issues = await github.rest.issues.listForRepo({
134+
owner: context.repo.owner,
135+
repo: context.repo.repo,
136+
state: 'open',
137+
labels: ['downloads', 'url-check-failed']
138+
});
139+
140+
const existingIssue = issues.data.find(issue =>
141+
issue.title === 'Broken download URLs detected'
142+
);
143+
144+
if (existingIssue) {
145+
// Close the issue
146+
await github.rest.issues.update({
147+
issue_number: existingIssue.number,
148+
owner: context.repo.owner,
149+
repo: context.repo.repo,
150+
state: 'closed'
151+
});
152+
153+
// Add closing comment
154+
await github.rest.issues.createComment({
155+
issue_number: existingIssue.number,
156+
owner: context.repo.owner,
157+
repo: context.repo.repo,
158+
body: '✅ All URLs are now accessible! Closing this issue.\n\n*Verified at: ' + new Date().toISOString() + '*'
159+
});
160+
161+
console.log(`Closed issue #${existingIssue.number} - all URLs are fixed`);
162+
}
163+
164+
- name: Set workflow status
165+
if: always()
166+
run: |
167+
if [ "${{ steps.url-check.outcome }}" == "failure" ]; then
168+
echo "URL check failed - marking workflow as failed"
169+
exit 1
170+
else
171+
echo "URL check passed"
172+
exit 0
173+
fi

0 commit comments

Comments
 (0)