fix(action): use token when fetching prs
Failing to do so causes it to fail when running in a private repo.
This commit is contained in:
parent
e0d48ae08a
commit
3c231dbfef
1 changed files with 8 additions and 3 deletions
11
action.yml
11
action.yml
|
@ -42,17 +42,22 @@ runs:
|
||||||
with:
|
with:
|
||||||
path: size-report.md
|
path: size-report.md
|
||||||
name: ${{ inputs.artifact-name }}
|
name: ${{ inputs.artifact-name }}
|
||||||
- name: Upload Report
|
- name: Comment Report
|
||||||
if: inputs.comment-on-pr == 'true'
|
if: inputs.comment-on-pr == 'true'
|
||||||
run: |
|
run: |
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
|
echo 'Determine head_ref'
|
||||||
# For push & tag events it'll bet GITHUB_REF_NAME, for pull_request events it'll be GITHUB_HEAD_REF
|
# For push & tag events it'll bet GITHUB_REF_NAME, for pull_request events it'll be GITHUB_HEAD_REF
|
||||||
head_ref=${GITHUB_REF_NAME-$GITHUB_HEAD_REF}
|
head_ref=${GITHUB_REF_NAME-$GITHUB_HEAD_REF}
|
||||||
|
|
||||||
pr_number=$(curl -X 'GET' \
|
echo "Get PR number for $head_ref"
|
||||||
|
prs=$(curl -X 'GET' \
|
||||||
"$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/pulls?state=open&sort=recentupdate" \
|
"$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/pulls?state=open&sort=recentupdate" \
|
||||||
-H 'accept: application/json' |
|
-H "Authorization: token $GITHUB_TOKEN" \
|
||||||
|
-H 'accept: application/json')
|
||||||
|
|
||||||
|
pr_number=$(echo "$prs" |
|
||||||
jq --arg head_ref "$head_ref" '.[] | select(.head.ref == $head_ref) | .number')
|
jq --arg head_ref "$head_ref" '.[] | select(.head.ref == $head_ref) | .number')
|
||||||
|
|
||||||
# Protect against running before a PR is made or if it is triggered on the main branch
|
# Protect against running before a PR is made or if it is triggered on the main branch
|
||||||
|
|
Loading…
Reference in a new issue