Skip to content

Instantly share code, notes, and snippets.

@saimn
Last active February 25, 2019 15:06
Show Gist options
  • Save saimn/67d7b2af5031a32dc9903be0d858616c to your computer and use it in GitHub Desktop.
Save saimn/67d7b2af5031a32dc9903be0d858616c to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# Git pre commit hook which find the next PR number and replace occurences of
# GUESSPR in the changelog
files_modified=`git diff --cached --name-only --diff-filter=ACM`
if [[ $files_modified == *"CHANGES.rst"* ]]; then
ghurl="https://api.github.com/repos/astropy/astropy/issues?state=all&sort=created&direction=desc&per_page=1"
echo "Fetching PR number from $ghurl"
prnumber=$(curl -s $ghurl | \
python -c "import sys, json; print(json.load(sys.stdin)[0]['number'] + 1)")
sed -i "s/GUESSPR/#$prnumber/" CHANGES.rst && echo "Wrote PR number :)" || echo "FAILED"
git add CHANGES.rst
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment