how to test for broken links on incoming changes to the codebase (and not only validite URL syntax).
replace <1234>
with the desired MR number, and <main>
with the MR base branch name, and run
git mr upstream <1234> && git diff <main> mr-upstream-<1234> | grep '^+ ' | grep -Eo 'https?://\S+?\.html' | bash -c "$(curl -fsSL https://gist.githubusercontent.com/eliranmal/4c04e4fe93aea796e4d48ae1f1a6a5ac/raw/8ae356df273ea226de79c52f0cfb508e17ea4fc7/check-links.sh)"
-
checkout the MR branch locally (using the
git mr
alias)git mr upstream 1234
-
store changes to a patch file, diffing with the main branch
git diff main mr-upstream-1234 > mr-changes.patch
-
extract only the additions as input for the following step (in a patch file, these are simply lines that begin with a single plus sign)
cat mr-changes.patch | grep '^+ ' > mr-additions.patch
note: the above steps can be automated/made obsolete/encapsulated by use of git hooks to act on relevant changes alone.
-
further extract the links embedded in the diff text
cat mr-additions.patch | grep -Eo 'https?://\S+?\.html' > mr-links.txt
-
pass these links to a script that loops through them and invokes a network call for each, testing for successful response
cat mr-links.txt | bash -c "$(curl -fsSL https://gist.githubusercontent.com/eliranmal/4c04e4fe93aea796e4d48ae1f1a6a5ac/raw/8ae356df273ea226de79c52f0cfb508e17ea4fc7/check-links.sh)"