mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 09:24:23 +00:00
Allow authenticated Github use in changelog script and improve error messages
This commit is contained in:
@@ -27,6 +27,13 @@ if [[ -z "${1-}" ]] || [[ -z "${2-}" ]]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
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
|
module=$1
|
||||||
fullTag=$2
|
fullTag=$2
|
||||||
changeLogFile="${3:-}"
|
changeLogFile="${3:-}"
|
||||||
@@ -49,10 +56,21 @@ results=""
|
|||||||
for((i=0; i < ${#commits[@]}; i+=batchSize))
|
for((i=0; i < ${#commits[@]}; i+=batchSize))
|
||||||
do
|
do
|
||||||
commitList=$(IFS="+"; echo "${commits[@]:i:batchSize}" | sed 's/ /+/g')
|
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')
|
results=$(echo "$results" "$newResults" | jq -s '.[0] + .[1] | unique')
|
||||||
else
|
else
|
||||||
echo "Failed to fetch results for commits (exit code $?): $commitList"
|
echo "Request for commits $commitList returned invalid results"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|||||||
Reference in New Issue
Block a user