Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Github Actions API - Get person who approved the deployment on an environment

I am having a hard time trying to find where I can get the person who approved the deployment on GithubActions API.

There is an API to POST approve/reject , but no HTTP GET

Basically, it is the person marked on the image below:

enter image description here

enter image description here

like image 571
guilhermecgs Avatar asked Sep 06 '25 03:09

guilhermecgs


1 Answers

You can see approvals for a workflow run with /repos/{owner}/{repo}/actions/runs/{run_id}/approvals;

For the example workflow provided in the screenshot;

# gh api /repos/{OWNER}/{REPO}/actions/runs/{RUN_ID}/approvals
gh api /repos/guilhermecgs/actions/actions/runs/4939224294/approvals

You can jq this to just get the name of the person, for an approval, limiting the results to approvals of a specific environment;

gh api /repos/guilhermecgs/actions/actions/runs/4939224294/approvals --jq \
'.[] | select (.environments[] != null) | select(.environments[].name == "prd") | .user.login'

You can also query the deployments at /repos/guilhermecgs/actions/deployments;

# gh api /repos/{OWNER}/{REPO}/deployments?environment={ENV}
gh api /repos/guilhermecgs/actions/deployments?environment=prd

If you also know the commit sha that the workflow ran on from which the deployment was made, you can query on that and jq those results;

# gh api /repos/{OWNER}/{REPO}/deployments?environment={ENV}\&sha={COMMIT_SHA}
gh api /repos/guilhermecgs/actions/deployments?environment=prd\
\&sha=d2000155e0d7a65e4e159b828951890f2658f371 \
--jq '.[].creator.login'

The example workflow seems to have been run three times for that combination of environment and sha, so the deployments api will give you all three of those deployments, but doesn't tie them to a workflow from which they were triggered.

like image 169
Skenvy Avatar answered Sep 07 '25 22:09

Skenvy