Use search API to retrieve information about PRs#38
Open
ooshlablu wants to merge 1 commit intooprypin:masterfrom
Open
Use search API to retrieve information about PRs#38ooshlablu wants to merge 1 commit intooprypin:masterfrom
ooshlablu wants to merge 1 commit intooprypin:masterfrom
Conversation
ghost
approved these changes
May 9, 2022
ghost
suggested changes
May 14, 2022
Repository owner
deleted a comment
May 14, 2022
Repository owner
deleted a comment
May 14, 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This allows PRs from forked repositories to be found and commented on by the commenter bot.
Fixes #37