new hook fix-broken-links#2027
Draft
jhauga wants to merge 2 commits into
Draft
Conversation
Contributor
🔒 PR Risk Scan ResultsScanned 6 changed file(s).
|
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds a “Fix Broken Links” Copilot hook that scans recently changed web-related files for http(s) links, reports non-200 URLs, offers interactive fixes (replace/remove/skip), and flags generic SEO anchor text.
Changes:
- Introduces Bash and PowerShell implementations for scanning/checking links and offering interactive remediation.
- Adds hook configuration (
hooks.json) to run after tool usage. - Documents the hook and lists it in the repository hooks index.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| hooks/fix-broken-links/link-fix.sh | Bash hook to discover changed files, extract URLs, check status, suggest alternatives, and interactively apply fixes. |
| hooks/fix-broken-links/link-fix.ps1 | PowerShell 7+ port of the hook with equivalent behavior using .NET web requests/regex. |
| hooks/fix-broken-links/hooks.json | Registers the hook command(s) for Copilot hook execution. |
| hooks/fix-broken-links/README.md | Installation/usage documentation for the new hook. |
| docs/README.hooks.md | Adds the new hook entry to the hooks catalog table. |
Comment on lines
+209
to
+214
| # Replace a literal URL everywhere in a file (pure bash, no regex). | ||
| replace_url() { | ||
| local file="$1" old="$2" new="$3" content | ||
| read_file content "$file" | ||
| printf '%s' "${content//"$old"/"$new"}" > "$file" | ||
| } |
Comment on lines
+228
to
+230
| while [[ $content =~ $re ]]; do | ||
| content="${content//"${BASH_REMATCH[0]}"/"${BASH_REMATCH[1]}"}" | ||
| done |
| # --data-urlencode keeps the URL's own ?query¶ms from corrupting our request. | ||
| wayback_lookup() { | ||
| local url="$1" | ||
| curl -s -G --max-time 8 "http://archive.org/wayback/available" \ |
| param([string]$Url) | ||
| try { | ||
| $enc = [uri]::EscapeDataString($Url) | ||
| $r = Invoke-RestMethod -Uri "http://archive.org/wayback/available?url=$enc" ` |
Comment on lines
+9
to
+11
| Scans recently-changed web files for broken hyperlinks after each GitHub Copilot | ||
| tool use. For each broken URL the hook tries common spelling variations, queries | ||
| DuckDuckGo for a replacement, and presents an interactive fix menu. Generic |
|
|
||
| ## Configuration | ||
|
|
||
| The hook is configured in `hooks.json` to run on the `userPromptSubmitted` event: |
| { | ||
| "version": 1, | ||
| "hooks": { | ||
| "userPromptSubmitted": [ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request Checklist
npm startand verified thatREADME.mdis up to date.stagedbranch for this pull request.Description
For full test results
ctrl + clicksupport-repo.Prompt
Context
Two links were broken:
And one could use SEO and/or better link text:
Results
Links fixed. I'm not entirely sure it was the hook, but ran
copilot, pasted prompt, and results were as expected. To confirm ran:pwsh .github/hooks/fix-broken-links/link-fix.ps1 index.html Checking 5 link(s) in index.html ... No broken links found.Type of Contribution
By submitting this pull request, I confirm that my contribution abides by the Code of Conduct and will be licensed under the MIT License.