Retrieve workflow ID for a given PR #24709
-
Hi everyone! I need to get the artefacts from the last workflow run for a PR associated with a commit SHA. The steps I envisage are: 1. Retrieve PR by commit SHA I can do 1 with I have looked at the example response data for Is there an API that allows me to retrieve a workflow ID by using a PR’s ID? Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
I’ve been trying to do gymnastics like this for months. The GraphQL API lets you get from a Here’s a
Taking the
yields:
(I’ve left the top Taking the
go back
and switching to the
which includes:
And: I personally needed the Fwiw, afaict for my case, I actually must switch back and forth between the |
Beta Was this translation helpful? Give feedback.
-
Thanks for responding @jsoref, ‘gymnastics’ is definitely the right word! I’m afraid I still can’t see how to find the missing link between a PR and workflow runs though, as the PR doesn’t return check runs from what I can tell. I’ve just been delving into the GraphQL schema and can’t find a link there at all. It’s frustrating! The only thing I can think of at the moment is to loop over all workflow runs and find a way to filter them by the related commit SHA or PR number. This is obviously hugely wasteful when the GraphQL layer should (to my mind) be able to do the legwork for us. |
Beta Was this translation helpful? Give feedback.
-
I spoke to GH Support who confirmed that the only way to do this is to filter the workflow runs. This is the approach:
Query params:
|
Beta Was this translation helpful? Give feedback.
I spoke to GH Support who confirmed that the only way to do this is to filter the workflow runs.
This is the approach:
Use a given SHA to retrieve PR:
/repos/{owner}/{repo}/commits/{commit_sha}/pulls
Get all relevant workflows
/repos/{owner}/{repo}/actions/runs
Query params:
branch
:pr.head.ref
(wherepr
is the PR data object from step 1)event
:"pull_request"
Filter workflow runs for that particular commit using the commit SHA
where
workflow_run.head_sha
===commit_sha
Retrieve artefacts by using the workflow run ID from step 3
/repos/{owner}/{repo}/actions/runs/{run_id}/artifacts