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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With