Skip to content

Use search API to retrieve information about PRs#38

Open
ooshlablu wants to merge 1 commit intooprypin:masterfrom
ooshlablu:master
Open

Use search API to retrieve information about PRs#38
ooshlablu wants to merge 1 commit intooprypin:masterfrom
ooshlablu:master

Conversation

@ooshlablu
Copy link
Copy Markdown

@ooshlablu ooshlablu commented Apr 22, 2022

This allows PRs from forked repositories to be found and commented on by the commenter bot.

Fixes #37

Copy link
Copy Markdown

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate of #38

Copy link
Copy Markdown

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate of #38

Repository owner deleted a comment May 14, 2022
Repository owner deleted a comment May 14, 2022
@vchernin
Copy link
Copy Markdown

vchernin commented Jul 31, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PR Commenting bot doesn't work with forked repo's creating a PR

2 participants