Use at your own risk and verify your input/output before performing any (potentially destructive) call against the Github API.
gh CLI environment, i.e. authenticated with at least repo-level permissions (see docs).
Retrieve accessible Github Repositories:
gh api graphql --paginate -f query='
query($endCursor: String) {
viewer {
repositories(first: 100, after: $endCursor) {
nodes { nameWithOwner }
pageInfo {
hasNextPage
endCursor
}
}
}
}
' > repos-raw.jsonInspect the output, e.g. remove repositories where you want to keep Github Actions enabled. Especially for repositories that you are contributing to, but not the (sole) owner of.
The trimmed down input (file) for the subsequent commands should look like:
cat repos-cleaned.txt
ghusername/myrepo1
ghusername/myrepo2
ghusername/myrepo3cat repos-cleaned.txt | xargs -I{} sh -c 'echo {}; gh api /repos/{}/actions/permissions'Example response:
ghusername/myrepo1
{
"enabled": true,
"allowed_actions": "all"
}
ghusername/myrepo2
{
"enabled": false
}
ghusername/myrepo3
{
"enabled": false
}gh api will handle pagination, throttling, etc. for you. The HTTP response headers will be printed (-i parameter) for further inspection (204 is what we want).
To disable Github Actions in all repositories specified in repos-cleaned.txt run the following command:
cat repos-cleaned.txt| xargs -I{} gh api -i -X PUT /repos/{}/actions/permissions -F enabled=falseRepo API: https://docs.github.com/en/rest/reference/repos#list-repositories-for-the-authenticated-user Actions API: https://docs.github.com/en/rest/reference/actions#set-github-actions-permissions-for-a-repository
Note that there's separate APIs of org-level scopes/permissions.