generate_changelog.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/bin/bash
  2. set -e
  3. set -x
  4. ## Usage :
  5. ## changelog PREVIOUS_TAG..HEAD
  6. # configure refs so we get pull-requests metadata
  7. git config --add remote.origin.fetch +refs/pull/*/head:refs/remotes/origin/pull/*
  8. git fetch origin
  9. RANGE=${1:-"$(git describe --tags --abbrev=0)..HEAD"}
  10. echo "Generate changelog for range ${RANGE}"
  11. echo
  12. pullrequests() {
  13. for commit in $(git log ${RANGE} --format='format:%H'); do
  14. # Get the oldest remotes/origin/pull/* branch to include this commit, i.e. the one to introduce it
  15. git branch -a --sort=committerdate --contains $commit --list 'origin/pull/*' | head -1 | cut -d'/' -f4
  16. done
  17. }
  18. changes=$(pullrequests | uniq)
  19. echo "pull requests merged within range:"
  20. echo $changes
  21. echo '#Features' > CHANGELOG.md
  22. for pr in $changes; do
  23. curl -fs -H "Authorization: token ${GITHUB_TOKEN}" https://api.github.com/repos/docker/compose/pulls/${pr} \
  24. | jq -r ' select( .labels[].name | contains("kind/feature") ) | "* "+.title' >> CHANGELOG.md
  25. done
  26. echo '#Bugs' >> CHANGELOG.md
  27. for pr in $changes; do
  28. curl -fs -H "Authorization: token ${GITHUB_TOKEN}" https://api.github.com/repos/docker/compose/pulls/${pr} \
  29. | jq -r ' select( .labels[].name | contains("kind/bug") ) | "* "+.title' >> CHANGELOG.md
  30. done