Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use search API to retrieve information about PRs #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ooshlablu
Copy link

@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

@unreal-person-666 unreal-person-666 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

@unreal-person-666 unreal-person-666 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 from unreal-person-666 May 14, 2022
Repository owner deleted a comment from unreal-person-666 May 14, 2022
@vchernin
Copy link

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
3 participants