@@ -54,13 +54,90 @@ jobs:
5454 name : link-check-report
5555 path : lychee-report.md
5656
57- - name : Create issue from failed link check
57+ - name : Create actionable issue for broken links
5858 if : failure() && github.event_name == 'schedule'
59- uses : peter-evans/create-issue-from-file@v5
59+ uses : actions/github-script@v7
6060 with :
61- title : " Broken links detected in documentation"
62- content-filepath : ./lychee-report.md
63- labels : |
64- documentation
65- broken-links
66- automated
61+ github-token : ${{ secrets.GITHUB_TOKEN }}
62+ script : |
63+ const fs = require('fs');
64+ const report = fs.readFileSync('./lychee-report.md', 'utf8');
65+
66+ // Parse the lychee report to extract broken links
67+ const lines = report.split('\n');
68+ const brokenLinks = [];
69+ let currentFile = '';
70+
71+ for (const line of lines) {
72+ // Match file paths in the report
73+ if (line.includes('.md') && !line.includes('|')) {
74+ currentFile = line.trim().replace(/^\*\*/, '').replace(/\*\*$/, '');
75+ }
76+ // Match broken links
77+ if (line.includes('[') && line.includes('](') && line.includes('Failed')) {
78+ const match = line.match(/\[.*?\]\((.*?)\)/);
79+ if (match) {
80+ brokenLinks.push({
81+ file: currentFile,
82+ url: match[1],
83+ line: line.trim()
84+ });
85+ }
86+ }
87+ }
88+
89+ const issueBody = `## Broken Links Detected
90+
91+ The automated link checker found ${brokenLinks.length} broken link(s) in the documentation that need to be fixed.
92+
93+ ### Instructions for fixing:
94+
95+ Please update the following broken links in the documentation files. For each broken link, either:
96+ 1. Update the URL to the correct destination
97+ 2. Remove the link if it's no longer relevant
98+ 3. Replace with an archived version from Wayback Machine if appropriate
99+
100+ ### Broken Links to Fix:
101+
102+ ${brokenLinks.map((link, index) =>
103+ `${index + 1}. **File:** \`${link.file}\`
104+ **Broken URL:** ${link.url}
105+ **Action:** Find this URL in the file and update or remove it
106+ `).join('\n')}
107+
108+ ### Full Report:
109+
110+ <details>
111+ <summary>Click to see the full lychee report</summary>
112+
113+ \`\`\`
114+ ${report}
115+ \`\`\`
116+
117+ </details>
118+
119+ ---
120+ *This issue was automatically generated by the dead link checker workflow.*`;
121+
122+ await github.rest.issues.create({
123+ owner: context.repo.owner,
124+ repo: context.repo.repo,
125+ title: `Fix ${brokenLinks.length} broken link(s) in documentation`,
126+ body: issueBody,
127+ labels: ['documentation', 'broken-links', 'automated', 'good first issue']
128+ });
129+
130+ - name : Comment PR with link check results
131+ if : failure() && github.event_name == 'pull_request'
132+ uses : actions/github-script@v7
133+ with :
134+ github-token : ${{ secrets.GITHUB_TOKEN }}
135+ script : |
136+ const fs = require('fs');
137+ const report = fs.readFileSync('./lychee-report.md', 'utf8');
138+ await github.rest.issues.createComment({
139+ owner: context.repo.owner,
140+ repo: context.repo.repo,
141+ issue_number: context.issue.number,
142+ body: `## ❌ Dead Links Found\n\n${report}\n\nPlease fix these broken links before merging.`
143+ });
0 commit comments