This script will list all active repositories in an organization with GitHub Actions workflows.
- Generate Access Token with
repo
scope and replace<TOKEN>
- Replace
<ORGANIZATION>
with your organizaiton name - Save to file and run the script
#!/bin/sh
token="<TOKEN>"
query='query {
organization(login: \"<ORGANIZATION>\") {
repositories(first: 100) {
nodes {
name
object(expression: \"HEAD:.github/workflows\") {
... on Tree {
entries {
path
}
}
}
isArchived
}
edges {
cursor
}
}
}
}'
cursor=""
run=true
while $run; do
if [[ "$cursor" != "" ]]; then
w='repositories(after: \\"'$cursor'\\"'
q=$(echo $query | sed "s/repositories(/$w, /g" | tr -d '\n')
else
q=$(echo $query | tr -d '\n')
fi
result=$(curl -s -X POST -H "Content-Type: application/json" -H "Authorization: bearer $token" -d "{ \"query\": \"$q\" }" https://api.github.com/graphql)
echo $result | jq -r ".data.organization.repositories.nodes | .[] | select(.object != null) | select(.isArchived == false) | .name"
cursor=$(echo $result | jq -r ".data.organization.repositories.edges | .[-1].cursor")
if [[ "$cursor" == "null" ]]; then
run=false
fi
done