scripts/prepare_changelog: Replace python for with gh and jq commands

This change uses the GitHub CLI to obtain all pull-requests merged after
the latest release to help with updating the Packer CHANGELOG.
update/CHANGELOG-pre-1.10.0-branch
Wilken Rivera 2 years ago
parent b3280493e0
commit 360df8f257

@ -4,78 +4,52 @@
LAST_RELEASE=$1 LAST_RELEASE=$1
DO_PR_CHECK=1
set -o pipefail set -o pipefail
is_doc_or_tech_debt_pr(){
if ! (($+commands[jq])); then
DO_PR_CHECK=0
echo "jq not found"
return 1
fi
out=$(python3 -m json.tool < pull.json \
| jq '[.labels[].name == "docs" or .labels[].name == "tech-debt" or .labels[].name == "website"] | any')
grep -q true <<< $out
return $?
}
if [ -z $LAST_RELEASE ]; then if [ -z $LAST_RELEASE ]; then
echo "you need to give the previous release version. prepare_changelog.sh v<version>" echo "you need to give the previous release version. prepare_changelog.sh v<version>"
exit 1 exit 1
fi fi
if [ -z "$(which jq)" ]; then
echo "jq command not found"
return 1
fi
if [ -z "$(which jq)" ]; then
echo "gh command not found"
return 1
fi
get_prs(){ get_prs(){
# git log v0.10.2...c3861d167533fb797b0fae0c380806625712e5f7 | release_time="$(gh release view --json "createdAt" --jq '.createdAt' ${LAST_RELEASE})"
git log HEAD...${LAST_RELEASE} --first-parent --oneline --grep="Merge pull request #[0-9]\+" --grep="(#[0-9]\+)$" | gh pr list -s merged -S "merged:>=$release_time -label:documentation -label:automated -label:tech-debt -label:website -label:legal -label:docs -author:hc-github-team-packer" --json "number" --jq '.[]|.number' \
grep -o "#\([0-9]\+\)" | awk -F\# '{print $2}' | while read line | while read line
do do
grep -q "GH-${line}" CHANGELOG.md if grep -q "GH-${line}" CHANGELOG.md; then
if [ $? -ne 0 ]; then
echo $line echo $line
fi fi
done | while read PR_NUM done | while read PR_NUM
do do
if [[ -z "${GITHUB_TOKEN}" ]] || [[ -z "${GITHUB_USERNAME}" ]] ; then out=$(gh pr view ${PR_NUM} --json "title,labels,url" > pull.json)
out=$(curl -fsS "https://api.github.com/repos/hashicorp/packer/issues/${PR_NUM}" -o pull.json) if [ "$?" -ne 0 ]; then
else
# authenticated call
out=$(curl -u ${GITHUB_USERNAME}:${GITHUB_TOKEN} -fsS "https://api.github.com/repos/hashicorp/packer/issues/${PR_NUM}" -o pull.json)
fi
exy="$?"
if [ $exy -ne 0 ]; then
echo "bad response from github: manually check PR ${PR_NUM}" echo "bad response from github: manually check PR ${PR_NUM}"
continue continue
fi fi
if (($DO_PR_CHECK)) && is_doc_or_tech_debt_pr; then echo "$(jq -r '.title' < pull.json) - [GH-${PR_NUM}](https://github.com/hashicorp/packer/pull/${PR_NUM})"
echo "Skipping PR ${PR_NUM}: labeled as tech debt, docs or website. (waiting a second so we don't get rate-limited...)" rm -f pull.json
continue
fi
echo "$(python3 -m json.tool < pull.json | jq -r '.title') - [GH-${PR_NUM}](https://github.com/hashicorp/packer/pull/${PR_NUM})"
done done
} }
#is_doc_or_tech_debt_pr 52061111
# is_doc_or_tech_debt_pr 5206 # non-doc pr
#is_doc_or_tech_debt_pr 5434 # doc pr
#echo $?
#exit
# prpid=$!
# trap 'kill -9 ${prpid}; exit' INT TERM
get_prs | while read line; do get_prs | while read line; do
echo $line echo $line
if [[ "$line" =~ "bad" ]]; then if [[ "$line" =~ "bad" ]]; then
exit 1 exit 1
elif [[ "$line" =~ "Skipping" ]]; then
sleep 1 # GH will rate limit us if we have several in a row
continue
fi fi
rm -f pull.json echo "Press enter to continue with next entry.."
vared -ch ok vared -ch ok
done done
#TODO: just generate it automatically using PR titles and tags #TODO: just generate it automatically using PR titles and tags

Loading…
Cancel
Save