Last active
March 7, 2025 17:51
-
-
Save lynsei/322a93e7f2a0f9236f5e79fa885993e4 to your computer and use it in GitHub Desktop.
Nushell get usage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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