From 3c231dbfef7d81a78d06677348cb76022266833e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jalil=20David=20Salam=C3=A9=20Messina?= Date: Sun, 15 Dec 2024 21:11:15 +0100 Subject: [PATCH] fix(action): use token when fetching prs Failing to do so causes it to fail when running in a private repo. --- action.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index 2257e90..858f3f7 100644 --- a/action.yml +++ b/action.yml @@ -42,17 +42,22 @@ runs: with: path: size-report.md name: ${{ inputs.artifact-name }} - - name: Upload Report + - name: Comment Report if: inputs.comment-on-pr == 'true' run: | 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 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" \ - -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') # Protect against running before a PR is made or if it is triggered on the main branch