Skip to content

Instantly share code, notes, and snippets.

@anton-yurchenko
Last active April 16, 2022 08:30
Show Gist options
  • Save anton-yurchenko/2816c86a76cb5928f360e699115605f0 to your computer and use it in GitHub Desktop.
Save anton-yurchenko/2816c86a76cb5928f360e699115605f0 to your computer and use it in GitHub Desktop.
List Active Repositories with GitHub Actions Flows

This script will list all active repositories in an organization with GitHub Actions workflows.

  1. Generate Access Token with repo scope and replace <TOKEN>
  2. Replace <ORGANIZATION> with your organizaiton name
  3. 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment