nightly.link
nightly.link copied to clipboard
Use search API to retrieve information about PRs
This allows PRs from forked repositories to be found and commented on by the commenter bot.
Fixes #37
I found with this change getting the PR number failed when the same head commit exists on two PRs on github, since multiple numbers exist.
To avoid this I filtered by repo and then always use the 0th item.
diff --git a/.github/workflows/artifact-pr-comment.yaml b/.github/workflows/artifact-pr-comment.yaml
index f465fdea2..2159e04d3 100644
--- a/.github/workflows/pr-comment.yaml
+++ b/.github/workflows/pr-comment.yaml
@@ -27,8 +27,11 @@ jobs:
run: |
# Query the issue search API to get the PR associated with it
PR_RAW=$(curl 'https://api.github.com/search/issues?q=${{ github.event.workflow_run.head_commit.id }}')
+
# Get the event number from the search results, which will be the PR number
- PR_NUM=$(echo $PR_RAW | jq '.items[].number')
+ # Filter by PRs only in this repository, as a PR with an identical head commit may be made in another repository (e.g. a fork)
+ # Assume the 0th index in the array of found PRs is the correct one (it seems to usually be the latest one)
+ PR_NUM=$(echo $PR_RAW | jq '.items | map(select(.repository_url=="https://api.github.com/repos/${{ github.repository }}")) | .[0].number')
echo "PR_NUM=${PR_NUM}" >> ${GITHUB_ENV}
- name: Comment on PR