Skip to content

Commit

Permalink
Allow authenticated Github use in changelog script and improve error …
Browse files Browse the repository at this point in the history
…messages
  • Loading branch information
KnVerey committed Feb 1, 2023
1 parent 95edcc0 commit 0c34cf4
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions releasing/compile-changelog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ if [[ -z "${1-}" ]] || [[ -z "${2-}" ]]; then
exit 1
fi

if [[ -z "${GITHUB_USERNAME-}" ]] || [[ -z "${GITHUB_TOKEN-}" ]]; then
echo "WARNING: Please set GITHUB_USERNAME and GITHUB_TOKEN to avoid GitHub API rate limits."
github_auth_string=""
else
github_auth_string="-u ${GITHUB_USERNAME}:${GITHUB_TOKEN}"
fi

module=$1
fullTag=$2
changeLogFile="${3:-}"
Expand All @@ -49,10 +56,21 @@ results=""
for((i=0; i < ${#commits[@]}; i+=batchSize))
do
commitList=$(IFS="+"; echo "${commits[@]:i:batchSize}" | sed 's/ /+/g')
if newResults=$(curl -sSL "https://api.github.com/search/issues?q=$commitList+repo%3Akubernetes-sigs%2Fkustomize" | jq -r '[ .items[] | { number, title } ]'); then

if ! newResultsRaw=$(curl -sSL "https://api.github.com/search/issues?q=$commitList+repo%3Akubernetes-sigs%2Fkustomize+is:pull-request" "${github_auth_string}"); then
echo "Failed to fetch results for commits (exit code $?): $commitList"
exit 1
fi
if [[ "${newResultsRaw}" == *"API rate limit exceeded"* ]]; then
echo "GitHub API rate limit exceeded. Please set GITHUB_USERNAME and GITHUB_TOKEN to avoid this."
exit 1
fi

if [[ "${newResultsRaw}" == *"\"items\":"* ]] ; then
newResults=$(echo "$newResultsRaw" | jq -r '[ .items[] | { number, title } ]')
results=$(echo "$results" "$newResults" | jq -s '.[0] + .[1] | unique')
else
echo "Failed to fetch results for commits (exit code $?): $commitList"
echo "Request for commits $commitList returned invalid results"
exit 1
fi
done
Expand Down

0 comments on commit 0c34cf4

Please sign in to comment.