gen_release_notes.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/env bash
  2. set -e
  3. function help() {
  4. print="
  5. To run this command,
  6. 1. verify you are selecting right branch from GitHub UI dropdown menu
  7. 2. enter the tag you want to create
  8. "
  9. echo "$print"
  10. exit 1
  11. }
  12. if [ -z "${GITHUB_USER}" ] || [ -z "${GITHUB_TOKEN}" ]; then
  13. echo "requires both GITHUB_USER and GITHUB_TOKEN to be set as env variable"
  14. help
  15. fi
  16. pr_list=$(git log --pretty="%s" --merges --left-only "${FROM_BRANCH}"..."${TO_TAG}" | grep pull | awk '/Merge pull request/ {print $4}' | cut -c 2-)
  17. # for releases notes
  18. function release_notes() {
  19. for pr in $pr_list; do
  20. # get PR title
  21. backport_pr=$(curl -s -u "${GITHUB_USER}":"${GITHUB_TOKEN}" "https://api.github.com/repos/rook/rook/pulls/${pr}" | jq '.title')
  22. # with upstream/release-1.6 v1.6.8, it was giving extra PR numbers, so removing after PR for changing tag is merged.
  23. if [[ "$backport_pr" =~ ./*"build: Update build version to $TO_TAG"* ]]; then
  24. break
  25. fi
  26. # check if it is manual backport PR or not, for mergify backport PR it will contain "(backport"
  27. if [[ "$backport_pr" =~ .*"(backport".* ]]; then
  28. # find the PR number after the #
  29. original_pr=$(echo "$backport_pr" | sed -n -e 's/^.*#//p' | grep -E0o '[0-9]' | tr -d '\n')
  30. else
  31. # in manual backport PR, we'll directly fetch the owner and title from the PR number
  32. original_pr=$pr
  33. fi
  34. # get the PR title and PR owner in required format
  35. title_with_user=$(curl -s -u "${GITHUB_USER}":"${GITHUB_TOKEN}" "https://api.github.com/repos/rook/rook/pulls/${original_pr}" | jq '.title+ " (#, @"+.user.login+")"')
  36. # add PR number after "#"
  37. result=$(echo "$title_with_user" | sed "s/(#/(#$original_pr/" |tail -c +2)
  38. # remove last `"`
  39. result=${result%\"}
  40. echo "$result"
  41. done
  42. }
  43. release_notes