GitHub Action pull_request
attribute empty in workflow_run
event object for PR from forked repo
#25220
Replies: 9 comments 12 replies
-
I have the same problem. I’ve done other tests and I think the problem is the fork. Did you have any success after this post? |
Beta Was this translation helpful? Give feedback.
-
Hi, Yes I did. When I figured that I can’t get a PR number reliably from the Details:
This method has worked for me ever since. You can check out the files here: |
Beta Was this translation helpful? Give feedback.
-
This issue persists, and is still not even documented by GitHub. It should not be considered “solved”, the solution provided above is merely a workaround. An alternative (perhaps easier and more comprehensive) workaround is to use the Get Workflow Origin action. It’s a bit of a kludge: it works around this issue by enumerating all PRs and finding the matching SHA for the workflow_run. But it works and requires minimal extra effort. See my implementation of this plugin for reference. |
Beta Was this translation helpful? Give feedback.
-
I would be nice if this info is available natively from the workflow_run event rather than resorting to finding the PR number |
Beta Was this translation helpful? Give feedback.
-
Actually even from the REST API the pull request array is empty and it's not even a fork.
A run that ran on a pull request In the payload below notice {
"id": 6223317359,
"name": "Java CI with Gradle",
"node_id": "WFR_kwLOEufiyM8AAAABcvBJbw",
"head_branch": "windows-failure",
"head_sha": "0a1e93ee775f4311bf61aa78171890c1937c7c6d",
"path": ".github/workflows/gradle.yml",
"display_title": "Understand windows failure",
"run_number": 242,
"event": "pull_request",
"status": "completed",
"conclusion": "success",
"workflow_id": 20103782,
"check_suite_id": 16285471685,
"check_suite_node_id": "CS_kwDOEufiyM8AAAADyrCTxQ",
"url": "https://api.github.com/repos/bric3/jufmt/actions/runs/6223317359",
"html_url": "https://github.com/bric3/jufmt/actions/runs/6223317359",
"pull_requests": [],
"created_at": "2023-09-18T13:35:21Z",
"updated_at": "2023-09-18T13:42:56Z",
"actor": {
"login": "bric3",
"id": 803621,
"node_id": "MDQ6VXNlcjgwMzYyMQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/803621?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/bric3",
"html_url": "https://github.com/bric3",
"followers_url": "https://api.github.com/users/bric3/followers",
"following_url": "https://api.github.com/users/bric3/following{/other_user}",
"gists_url": "https://api.github.com/users/bric3/gists{/gist_id}",
"starred_url": "https://api.github.com/users/bric3/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/bric3/subscriptions",
"organizations_url": "https://api.github.com/users/bric3/orgs",
"repos_url": "https://api.github.com/users/bric3/repos",
"events_url": "https://api.github.com/users/bric3/events{/privacy}",
"received_events_url": "https://api.github.com/users/bric3/received_events",
"type": "User",
"site_admin": false
},
"run_attempt": 1,
"referenced_workflows": [],
"run_started_at": "2023-09-18T13:35:21Z",
"triggering_actor": {
"login": "bric3",
"id": 803621,
"node_id": "MDQ6VXNlcjgwMzYyMQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/803621?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/bric3",
"html_url": "https://github.com/bric3",
"followers_url": "https://api.github.com/users/bric3/followers",
"following_url": "https://api.github.com/users/bric3/following{/other_user}",
"gists_url": "https://api.github.com/users/bric3/gists{/gist_id}",
"starred_url": "https://api.github.com/users/bric3/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/bric3/subscriptions",
"organizations_url": "https://api.github.com/users/bric3/orgs",
"repos_url": "https://api.github.com/users/bric3/repos",
"events_url": "https://api.github.com/users/bric3/events{/privacy}",
"received_events_url": "https://api.github.com/users/bric3/received_events",
"type": "User",
"site_admin": false
},
"jobs_url": "https://api.github.com/repos/bric3/jufmt/actions/runs/6223317359/jobs",
"logs_url": "https://api.github.com/repos/bric3/jufmt/actions/runs/6223317359/logs",
"check_suite_url": "https://api.github.com/repos/bric3/jufmt/check-suites/16285471685",
"artifacts_url": "https://api.github.com/repos/bric3/jufmt/actions/runs/6223317359/artifacts",
"cancel_url": "https://api.github.com/repos/bric3/jufmt/actions/runs/6223317359/cancel",
"rerun_url": "https://api.github.com/repos/bric3/jufmt/actions/runs/6223317359/rerun",
"previous_attempt_url": null,
"workflow_url": "https://api.github.com/repos/bric3/jufmt/actions/workflows/20103782",
"head_commit": {
"id": "0a1e93ee775f4311bf61aa78171890c1937c7c6d",
"tree_id": "e2e909cfe4c4b248531a510b444557f68f3ce506",
"message": "chore: Moves figlet test in lib, and use mockito in cli",
"timestamp": "2023-09-18T13:34:58Z",
"author": {
"name": "Brice Dutheil",
"email": "[email protected]"
},
"committer": {
"name": "Brice Dutheil",
"email": "[email protected]"
}
},
"repository": {
"id": 317186760,
"node_id": "MDEwOlJlcG9zaXRvcnkzMTcxODY3NjA=",
"name": "jufmt",
"full_name": "bric3/jufmt",
"private": false,
"owner": {
"login": "bric3",
"id": 803621,
"node_id": "MDQ6VXNlcjgwMzYyMQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/803621?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/bric3",
"html_url": "https://github.com/bric3",
"followers_url": "https://api.github.com/users/bric3/followers",
"following_url": "https://api.github.com/users/bric3/following{/other_user}",
"gists_url": "https://api.github.com/users/bric3/gists{/gist_id}",
"starred_url": "https://api.github.com/users/bric3/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/bric3/subscriptions",
"organizations_url": "https://api.github.com/users/bric3/orgs",
"repos_url": "https://api.github.com/users/bric3/repos",
"events_url": "https://api.github.com/users/bric3/events{/privacy}",
"received_events_url": "https://api.github.com/users/bric3/received_events",
"type": "User",
"site_admin": false
},
"html_url": "https://github.com/bric3/jufmt",
"description": "Java Unicode formatter",
"fork": false,
"url": "https://api.github.com/repos/bric3/jufmt",
"forks_url": "https://api.github.com/repos/bric3/jufmt/forks",
"keys_url": "https://api.github.com/repos/bric3/jufmt/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/bric3/jufmt/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/bric3/jufmt/teams",
"hooks_url": "https://api.github.com/repos/bric3/jufmt/hooks",
"issue_events_url": "https://api.github.com/repos/bric3/jufmt/issues/events{/number}",
"events_url": "https://api.github.com/repos/bric3/jufmt/events",
"assignees_url": "https://api.github.com/repos/bric3/jufmt/assignees{/user}",
"branches_url": "https://api.github.com/repos/bric3/jufmt/branches{/branch}",
"tags_url": "https://api.github.com/repos/bric3/jufmt/tags",
"blobs_url": "https://api.github.com/repos/bric3/jufmt/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/bric3/jufmt/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/bric3/jufmt/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/bric3/jufmt/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/bric3/jufmt/statuses/{sha}",
"languages_url": "https://api.github.com/repos/bric3/jufmt/languages",
"stargazers_url": "https://api.github.com/repos/bric3/jufmt/stargazers",
"contributors_url": "https://api.github.com/repos/bric3/jufmt/contributors",
"subscribers_url": "https://api.github.com/repos/bric3/jufmt/subscribers",
"subscription_url": "https://api.github.com/repos/bric3/jufmt/subscription",
"commits_url": "https://api.github.com/repos/bric3/jufmt/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/bric3/jufmt/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/bric3/jufmt/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/bric3/jufmt/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/bric3/jufmt/contents/{+path}",
"compare_url": "https://api.github.com/repos/bric3/jufmt/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/bric3/jufmt/merges",
"archive_url": "https://api.github.com/repos/bric3/jufmt/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/bric3/jufmt/downloads",
"issues_url": "https://api.github.com/repos/bric3/jufmt/issues{/number}",
"pulls_url": "https://api.github.com/repos/bric3/jufmt/pulls{/number}",
"milestones_url": "https://api.github.com/repos/bric3/jufmt/milestones{/number}",
"notifications_url": "https://api.github.com/repos/bric3/jufmt/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/bric3/jufmt/labels{/name}",
"releases_url": "https://api.github.com/repos/bric3/jufmt/releases{/id}",
"deployments_url": "https://api.github.com/repos/bric3/jufmt/deployments"
},
"head_repository": {
"id": 317186760,
"node_id": "MDEwOlJlcG9zaXRvcnkzMTcxODY3NjA=",
"name": "jufmt",
"full_name": "bric3/jufmt",
"private": false,
"owner": {
"login": "bric3",
"id": 803621,
"node_id": "MDQ6VXNlcjgwMzYyMQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/803621?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/bric3",
"html_url": "https://github.com/bric3",
"followers_url": "https://api.github.com/users/bric3/followers",
"following_url": "https://api.github.com/users/bric3/following{/other_user}",
"gists_url": "https://api.github.com/users/bric3/gists{/gist_id}",
"starred_url": "https://api.github.com/users/bric3/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/bric3/subscriptions",
"organizations_url": "https://api.github.com/users/bric3/orgs",
"repos_url": "https://api.github.com/users/bric3/repos",
"events_url": "https://api.github.com/users/bric3/events{/privacy}",
"received_events_url": "https://api.github.com/users/bric3/received_events",
"type": "User",
"site_admin": false
},
"html_url": "https://github.com/bric3/jufmt",
"description": "Java Unicode formatter",
"fork": false,
"url": "https://api.github.com/repos/bric3/jufmt",
"forks_url": "https://api.github.com/repos/bric3/jufmt/forks",
"keys_url": "https://api.github.com/repos/bric3/jufmt/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/bric3/jufmt/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/bric3/jufmt/teams",
"hooks_url": "https://api.github.com/repos/bric3/jufmt/hooks",
"issue_events_url": "https://api.github.com/repos/bric3/jufmt/issues/events{/number}",
"events_url": "https://api.github.com/repos/bric3/jufmt/events",
"assignees_url": "https://api.github.com/repos/bric3/jufmt/assignees{/user}",
"branches_url": "https://api.github.com/repos/bric3/jufmt/branches{/branch}",
"tags_url": "https://api.github.com/repos/bric3/jufmt/tags",
"blobs_url": "https://api.github.com/repos/bric3/jufmt/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/bric3/jufmt/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/bric3/jufmt/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/bric3/jufmt/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/bric3/jufmt/statuses/{sha}",
"languages_url": "https://api.github.com/repos/bric3/jufmt/languages",
"stargazers_url": "https://api.github.com/repos/bric3/jufmt/stargazers",
"contributors_url": "https://api.github.com/repos/bric3/jufmt/contributors",
"subscribers_url": "https://api.github.com/repos/bric3/jufmt/subscribers",
"subscription_url": "https://api.github.com/repos/bric3/jufmt/subscription",
"commits_url": "https://api.github.com/repos/bric3/jufmt/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/bric3/jufmt/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/bric3/jufmt/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/bric3/jufmt/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/bric3/jufmt/contents/{+path}",
"compare_url": "https://api.github.com/repos/bric3/jufmt/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/bric3/jufmt/merges",
"archive_url": "https://api.github.com/repos/bric3/jufmt/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/bric3/jufmt/downloads",
"issues_url": "https://api.github.com/repos/bric3/jufmt/issues{/number}",
"pulls_url": "https://api.github.com/repos/bric3/jufmt/pulls{/number}",
"milestones_url": "https://api.github.com/repos/bric3/jufmt/milestones{/number}",
"notifications_url": "https://api.github.com/repos/bric3/jufmt/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/bric3/jufmt/labels{/name}",
"releases_url": "https://api.github.com/repos/bric3/jufmt/releases{/id}",
"deployments_url": "https://api.github.com/repos/bric3/jufmt/deployments"
}
}, |
Beta Was this translation helpful? Give feedback.
-
This is still a problem. Interestingly, the
You can access the PR ID in the following steps with The things you have to do to simply comment on a PR originated from a fork is unreal. |
Beta Was this translation helpful? Give feedback.
-
I just came across the issue and found out (yet) another workaround. I prefer to avoid using artifacts to send the PR number information as those could be altered. It's inspired on @danepowell 's workaround in the GH Action Get Workflow Origin. It lists latest PRs in repository and looks for the one whose head commit SHA matches the workflow run head SHA (which we have in the event payload). It's a bit hacky, given we can't specify in the API call that we want the PR whose head SHA is that one and we have to look in the list of latest PRs in the repository. Also, the action is not maintained anymore 😢 So you'd have to copy that piece into a GitHub script step. Then I found out that using GitHub's issues & PRs search API we can look for the PR given the head SHA Here's the magic script: 🪄 - name: Find associated pull request
id: pr
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
with:
script: |
const response = await github.rest.search.issuesAndPullRequests({
q: 'repo:${{ github.repository }} is:pr sha:${{ github.event.workflow_run.head_sha }}',
per_page: 1,
})
const items = response.data.items
if (items.length < 1) {
console.error('No PRs found')
return
}
const pullRequestNumber = items[0].number
console.info("Pull request number is", pullRequestNumber)
return pullRequestNumber And here's how the PR number is used - name: Find bundle size PR comment
uses: peter-evans/find-comment@d5fe37641ad8451bdd80312415672ba26c86575e # v3
id: fc
with:
issue-number: ${{ steps.pr.outputs.result }} # 👈
comment-author: 'github-actions[bot]'
body-includes: ${{ env.BUNDLE_SIZE_COMMENT_ID_PREFIX }}${{ matrix.version }} |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
jobs:
|
Beta Was this translation helpful? Give feedback.
-
2024-03-06 EDIT
Issue not solved. Workarounds are available below. I'll unmark my answer since others have come up with other solutions. This will also hopefully get GitHub to work on a native fix for this problem, which is needed to do tasks like commenting on a PR from a forked repo.
-----Hello there,
I notice a weird issue with the workflow_run event object when it involves a PR from a forked repo.
Context:
- I have a
workflow_run
workflow that will run after a specificpull_request
workflow- I wanted to find the PR number of the pull_request using the
github.event
context.Problem:
-If the PR is from a local branch inside the repo, the
pull_request
attribute of thegithub.event
context is populatedLink to Action log: Merge pull request #24 from Thomas-Boi/develop · Thomas-Boi/devicon@d0884eb · GitHub
-If the PR is from a forked branch outside the repo, the
pull_request
attribute of thegithub.event
context is empty(no picture because GitHub prevented me from posting more than one picture as a new user)
Link to Action log: Merge pull request #24 from Thomas-Boi/develop · Thomas-Boi/devicon@d0884eb · GitHub
This makes it unstable to find the PR number using the
github.event
attribute. I wonder if this is intentional for security reasons.Code and Replication:
PR workflow (example of what I’m trying to do)
workflow_run
workflow (example of what I’m trying to do)To replicate this issue:
- Create a repo and add these workflows in the
master
branch.- Fork that repo
- Create a branch in the original repo. Add any change to it, push, then open a PR into
master
.- This will trigger the
pull_request
workflow and theworkflow_run
workflow afterwards.- View the log in the Actions tab
- Create a branch in the forked repo. Add any change to it, push, then open a PR into the original branch.
- View the log in the Actions tab
- This will trigger the
pull_request
workflow and theworkflow_run
workflow afterwardsBeta Was this translation helpful? Give feedback.
All reactions