diff --git a/gh-cli/README.md b/gh-cli/README.md index f3c6617..a5c4b53 100644 --- a/gh-cli/README.md +++ b/gh-cli/README.md @@ -1319,6 +1319,26 @@ Generates a CSV with 4 columns: This script is useful when doing migrations, to determine the kind of actions that might be needed based on the webhooks inventory. +### get-repositories-with-copilot-instructions.sh + +Get repositories that have Copilot custom instruction files, checking for both repository-wide (`.github/copilot-instructions.md`) and path-specific (`.github/instructions/`) instructions + +Usage: + +```shell +./get-repositories-with-copilot-instructions.sh my-org +``` + +### get-repositories-without-copilot-instructions.sh + +Get repositories that do not have any Copilot custom instruction files (neither `.github/copilot-instructions.md` nor `.github/instructions/`) + +Usage: + +```shell +./get-repositories-without-copilot-instructions.sh my-org +``` + ### get-repository-languages-for-organization.sh Get the repository language information (ie: JavaScript, Python, etc) for all repositories in an organization. Can specify how many language results to return (top X). diff --git a/gh-cli/get-repositories-with-copilot-instructions.sh b/gh-cli/get-repositories-with-copilot-instructions.sh new file mode 100755 index 0000000..960aadd --- /dev/null +++ b/gh-cli/get-repositories-with-copilot-instructions.sh @@ -0,0 +1,55 @@ +#!/bin/bash + +# Get repositories that have Copilot custom instruction files +# Checks for: +# - .github/copilot-instructions.md (repository-wide custom instructions) +# - .github/instructions/ directory (path-specific custom instructions) +# +# +# Authentication: +# Requires a GitHub CLI token with at least read:org and repo scopes +# Example: gh auth refresh -h github.com -s read:org,repo +# +# Usage: +# ./get-repositories-with-copilot-instructions.sh +# If you want to see the results in a nicely formatted table, you can pipe the output to `column`: +# ./get-repositories-with-copilot-instructions.sh | column -ts $'\t' + +if [ -z "$1" ]; then + echo "Usage: $0 " + exit 1 +fi + +org=$1 + +echo -e "Repository\tRepo-Wide\tPath-Specific Files" + +gh api graphql --paginate -F owner="$org" -H "X-Github-Next-Global-ID: 1" -f query=' + query ($owner: String!, $endCursor: String = null) { + organization(login: $owner) { + repositories( + first: 100 + orderBy: { field: NAME, direction: ASC } + after: $endCursor + ) { + totalCount + pageInfo {hasNextPage endCursor} + nodes { + nameWithOwner + repoWide: object(expression: "HEAD:.github/copilot-instructions.md") { + ... on Blob { + byteSize + } + } + pathSpecific: object(expression: "HEAD:.github/instructions/") { + ... on Tree { + entries { + path + } + } + } + } + } + } + } +' --jq '.data.organization.repositories.nodes[] | select(.repoWide != null or .pathSpecific != null) | [.nameWithOwner, (if .repoWide != null then "yes" else "no" end), (if .pathSpecific != null then (.pathSpecific.entries | length | tostring) else "0" end)] | @tsv' diff --git a/gh-cli/get-repositories-without-copilot-instructions.sh b/gh-cli/get-repositories-without-copilot-instructions.sh new file mode 100755 index 0000000..6dc0647 --- /dev/null +++ b/gh-cli/get-repositories-without-copilot-instructions.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +# Get repositories that do not have any Copilot custom instruction files +# Checks for the absence of both: +# - .github/copilot-instructions.md (repository-wide custom instructions) +# - .github/instructions/ directory (path-specific custom instructions) +# +# Authentication: +# Requires a GitHub CLI token with at least read:org and repo scopes +# Example: gh auth refresh -h github.com -s read:org,repo +# +# Usage: +# ./get-repositories-without-copilot-instructions.sh + +if [ -z "$1" ]; then + echo "Usage: $0 " + exit 1 +fi + +org=$1 + +gh api graphql --paginate -F owner="$org" -H "X-Github-Next-Global-ID: 1" -f query=' + query ($owner: String!, $endCursor: String = null) { + organization(login: $owner) { + repositories( + first: 100 + orderBy: { field: NAME, direction: ASC } + after: $endCursor + ) { + totalCount + pageInfo {hasNextPage endCursor} + nodes { + nameWithOwner + repoWide: object(expression: "HEAD:.github/copilot-instructions.md") { + ... on Blob { + byteSize + } + } + pathSpecific: object(expression: "HEAD:.github/instructions/") { + ... on Tree { + entries { + path + } + } + } + } + } + } + } +' --jq '.data.organization.repositories.nodes[] | select(.repoWide == null and .pathSpecific == null) | .nameWithOwner'