Skip to content

Instantly share code, notes, and snippets.

@joelittlejohn
Last active March 4, 2021 18:50
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joelittlejohn/5937573 to your computer and use it in GitHub Desktop.
Save joelittlejohn/5937573 to your computer and use it in GitHub Desktop.
Instant CHANGELOG.md from your GitHub issues
#!/usr/bin/env bash
# Generates this kind of thing:
# https://github.com/joelittlejohn/jsonschema2pojo/blob/master/CHANGELOG.md
#
# If your issue has 'breaking' label, the issue will be shown in the changelog with bold text
#
# All versions of this script are dedicated to the Public Domain, no rights reserved,
# as per https://creativecommons.org/publicdomain/zero/1.0/
#
if [ "$#" -ne 2 ]; then
echo "Usage: ./generate-changelog.sh user/repo <github token>"
exit 1
fi
IFS=$'\n'
echo "# Changelog" > CHANGELOG.md
for m in $(
curl -s -H "Authorization: token $2" "https://api.github.com/repos/$1/milestones?state=closed&per_page=100" \
| jq -c '.[] | [.title, .number]' \
| sed 's/-/\!/' | sort -rV | sed 's/\!/-/' # sed trick to put -alpha, -beta, etc earlier than GA release
); do
echo "Processing milestone: $m..."
echo $m | sed 's/\["\(.*\)",.*\]/\n## \1/' >> CHANGELOG.md
mid=$(echo $m | sed 's/.*,\(.*\)]/\1/')
for i in $(curl -s -H "Authorization: token $2" "https://api.github.com/repos/$1/issues?milestone=$mid&state=closed" | jq -r '.[] | [.html_url, .number, .title, (.labels[] | select(.name == "breaking") | .name)] | @tsv'); do
if [ "$(echo "$i" | cut -f 4)" = "breaking" ]; then
echo "* **$(echo "$i" | cut -f 3 | sed 's/_/\\_/g') ([#$(echo "$i" | cut -f 2)]($(echo "$i" | cut -f 1)))**" >> CHANGELOG.md
else
echo "* $(echo "$i" | cut -f 3 | sed 's/_/\\_/g') ([#$(echo "$i" | cut -f 2)]($(echo "$i" | cut -f 1)))" >> CHANGELOG.md
fi
done
done
@steevee
Copy link

steevee commented Jun 10, 2014

@joelittlejohn, thanks for the script, very handy.

To make sure you password stays out of your history:

#!/bin/bash

if [ "$#" -ne 2 ]; then
    echo "Usage: ./generate-changelog.sh user/repo <username>"
    exit 1
fi

read -s -p "@$2 password: " PASS

IFS=$'\n'
echo "# Changelog" > CHANGELOG.md

for m in $(curl -s "https://$2:$PASS@api.github.com/repos/$1/milestones?state=closed" | jq -c '.[] | [.title, .number]' | sort -rV); do
    echo "Processing milestone: $m..."
    echo $m | sed 's/\["\(.*\)",.*\]/\n## \1/' >> CHANGELOG.md
    mid=$(echo $m | sed 's/.*,\(.*\)]/\1/')
    for i in $(curl -s "https://$2:$PASS@api.github.com/repos/$1/issues?milestone=$mid&state=closed" | jq -c '.[] | [.html_url, .number, .title]'); do
        echo $i | sed 's/\["\(.*\)",\(.*\),\"\(.*\)\"\]/* \3 ([#\2](\1))/' | sed 's/\\"/"/g' >> CHANGELOG.md
    done
done

@hrieke
Copy link

hrieke commented Apr 14, 2020

You have a license for your shell script?
Thanks

@joelittlejohn
Copy link
Author

@hrieke I've added a note to the file, CC0 👍

@hrieke
Copy link

hrieke commented Apr 14, 2020

@hrieke I've added a note to the file, CC0 👍

Thanks! Made my day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment