1
0

check_newsfragment.sh 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/env bash
  2. #
  3. # A script which checks that an appropriate news file has been added on this
  4. # branch.
  5. #
  6. # As first argument, it requires the PR number, so that it can check that the
  7. # newsfragment has the correct name.
  8. #
  9. # Usage:
  10. # ./scripts-dev/check_newsfragment.sh 382
  11. #
  12. # Exit codes:
  13. # 0: all is well
  14. # 1: the newsfragment is wrong in some way
  15. # 9: the script has not been invoked properly
  16. echo -e "+++ \e[32mChecking newsfragment\e[m"
  17. set -e
  18. if [ -z "$1" ]; then
  19. echo "Please specify the PR number as the first argument (e.g. 382)."
  20. exit 9
  21. fi
  22. pull_request_number="$1"
  23. # Print a link to the contributing guide if the user makes a mistake
  24. CONTRIBUTING_GUIDE_TEXT="!! Please see the contributing guide for help writing your changelog entry:
  25. https://github.com/matrix-org/sydent/blob/main/CONTRIBUTING.md#changelog"
  26. # If towncrier returns a non-zero exit code, print the contributing guide link and exit
  27. python -m towncrier.check --compare-with="origin/main" || (echo -e "$CONTRIBUTING_GUIDE_TEXT" >&2 && exit 1)
  28. echo
  29. echo "--------------------------"
  30. echo
  31. matched=0
  32. for f in `git diff --name-only origin/main... -- changelog.d`; do
  33. # check that any modified newsfiles on this branch end with a full stop.
  34. lastchar=`tr -d '\n' < $f | tail -c 1`
  35. if [ $lastchar != '.' -a $lastchar != '!' ]; then
  36. echo -e "\e[31mERROR: newsfragment $f does not end with a '.' or '!'\e[39m" >&2
  37. echo -e "$CONTRIBUTING_GUIDE_TEXT" >&2
  38. exit 1
  39. fi
  40. # see if this newsfile corresponds to the right PR
  41. [[ -n "$pull_request_number" && "$f" == changelog.d/"$pull_request_number".* ]] && matched=1
  42. done
  43. if [[ -n "$pull_request_number" && "$matched" -eq 0 ]]; then
  44. echo -e "\e[31mERROR: Did not find a news fragment with the right number: expected changelog.d/$pull_request_number.*.\e[39m" >&2
  45. echo -e "$CONTRIBUTING_GUIDE_TEXT" >&2
  46. exit 1
  47. fi