Skip to content

Commit

Permalink
Correctly handle missing GITHUB_TOKEN as well as urlencoding gh_api c…
Browse files Browse the repository at this point in the history
…alls
  • Loading branch information
blast-hardcheese committed Dec 23, 2023
1 parent bac7601 commit b945069
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions support/current-pr-labels.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ module_name="$1"

gh_api() {
path="$1"; shift
token_args=()
if [ -n "${GITHUB_TOKEN}" ]; then
token_args=( -H "Authorization: Bearer ${GITHUB_TOKEN}" )
fi
curl -s \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
"${token_args[@]}" \
"$@" \
"https://api.github.com/$path"
}
Expand All @@ -28,7 +32,7 @@ labels_since_last_release() {
echo '{"labels":[]}'
else
module_released_on="$(git show "${latest_tag}" --format=%cI)"
gh_api "search/issues?q=repo:guardrail-dev/guardrail+type:pr+is:merged+closed:>${module_released_on}+label:${module_name}" \
gh_api "search/issues" -G --data-urlencode "q=repo:guardrail-dev/guardrail+type:pr+is:merged+closed:>${module_released_on}+label:${module_name}" \
| jq -cM '{labels: ((.items // []) | map(.labels) | flatten | map(.name) | unique | map({ name: . })) }'
fi
}
Expand Down

0 comments on commit b945069

Please sign in to comment.