Skip to content

Instantly share code, notes, and snippets.

@lynsei
Last active March 7, 2025 17:51
Show Gist options
  • Select an option

  • Save lynsei/322a93e7f2a0f9236f5e79fa885993e4 to your computer and use it in GitHub Desktop.

Select an option

Save lynsei/322a93e7f2a0f9236f5e79fa885993e4 to your computer and use it in GitHub Desktop.
Nushell get usage
function get_ci_usage
set org "your-org-name" # Replace with your GitHub Organization Name
echo "Fetching workflow run counts for all repositories in $org..."
set query '
{
organization(login: "'$org'") {
repositories(first: 100) {
nodes {
name
workflows {
totalCount
}
}
}
}
}'
# Fetch data using GraphQL
set results (gh api graphql -f query="$query" | jq -r '.data.organization.repositories.nodes[] | "\(.name) \(.workflows.totalCount)"')
# Format output as a table
echo -e "Repository Workflow_Runs\n$results" | sort -k2 -nr | column -t
end
def get_ci_usage [] {
let org = "your-org-name" # Replace with your GitHub Organization Name
print $"Fetching workflow run counts for all repositories in ($org)..."
let query = {
"query": $"{
organization(login: \"($org)\") {
repositories(first: 100) {
nodes {
name
workflows {
totalCount
}
}
}
}
}"
}
# Fetch data using GraphQL
let results = (gh api graphql --json $query | from json)
# Process and display results in a sorted table
$results.data.organization.repositories.nodes
| each {|repo| { repo: $repo.name, workflow_runs: $repo.workflows.totalCount }}
| sort-by workflow_runs -r
| table
}
gh api graphql -f query='
{
repository(owner: "your-org-name", name: "your-repo-name") {
workflows {
totalCount
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment