Skip to content

Instantly share code, notes, and snippets.

@szhu
Created March 2, 2024 00:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save szhu/a4f05f6e3599b6451732de8bdc01edbc to your computer and use it in GitHub Desktop.
Save szhu/a4f05f6e3599b6451732de8bdc01edbc to your computer and use it in GitHub Desktop.
set -e
verbose() {
echo $ "$@" >&2
"$@"
}
COMPARISON="${1:-origin/prod...origin/main}"
OUT=".git/changelog.out.html"
true >"$OUT"
echo "<title>$COMPARISON</title>" >>"$OUT"
echo "<style>:root { font: 14px sans-serif; } </style>" >>"$OUT"
echo "<ul>" >>"$OUT"
out=$(verbose git log --merges --oneline "$COMPARISON") && echo "$out" | while read line; do
PR_NUMBER=$(sed -n 's/.*Merge pull request #\([0-9]*\).*/\1/p' <<<"$line")
verbose gh pr view "$PR_NUMBER" --json title,number,url |
node -e 'x = JSON.parse(require("fs").readFileSync(0, "utf-8")); console.log(`<li><a href="${x.url}">${x.title.replace(/&/g, `&amp;`).replace(/</g, `&lt;`)} #${x.number}</a></li>`)' >>"$OUT"
done
test $? -eq 0 || exit 1
echo "</ul>" >>"$OUT"
echo "Changelog generated: $OUT"
if command -v xdg-open &>/dev/null; then
xdg-open "$OUT"
elif command -v open &>/dev/null; then
open "$OUT"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment