Skip to content

Instantly share code, notes, and snippets.

@sjungling
Created February 16, 2023 00:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sjungling/95581e4eea561e75141046f97637aa88 to your computer and use it in GitHub Desktop.
Save sjungling/95581e4eea561e75141046f97637aa88 to your computer and use it in GitHub Desktop.
CSV of all organizational repositories and default branch that I have access to that are not archived and have been updated in the last 2 years
#!/usr/bin/env bash
gh api graphql --paginate=true \
-f query='query (
$numOrgs: Int = 100
$numRepos: Int = 100
$endCursor: String
) {
viewer {
organizations(first: $numOrgs) {
edges {
node {
repositories(
first: $numRepos
after: $endCursor
isFork: false
isLocked: false
) {
pageInfo {
hasNextPage
endCursor
}
edges {
node {
nameWithOwner
pushedAt
defaultBranchRef {
name
}
isArchived
isPrivate
}
}
}
}
}
}
}
}
' \
--jq '.data.viewer.organizations.edges[].node.repositories.edges[].node | select(.isArchived == false and (.pushedAt | fromdateiso8601 | strflocaltime("%Y-%m-%d") > (now - 60 * 60 * 730) ) ) | [.nameWithOwner, .defaultBranchRef.name] | @csv '
@sjungling
Copy link
Author

This has the limitation of the gh CLI auto-pagination, which is only able to do one level of recursion. I chose repositories because I believe those to be far more numerous than organizations an individual might belong to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment