Skip to content

Commit 832d064

Browse files
feat: add scripts to retrieve repositories with and without Copilot custom instructions (#159)
* feat: add scripts to retrieve repositories with and without Copilot custom instructions * docs: update README and scripts to include authentication details for Copilot instructions
1 parent fff1fd1 commit 832d064

3 files changed

Lines changed: 125 additions & 0 deletions

File tree

gh-cli/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,26 @@ Generates a CSV with 4 columns:
13191319

13201320
This script is useful when doing migrations, to determine the kind of actions that might be needed based on the webhooks inventory.
13211321

1322+
### get-repositories-with-copilot-instructions.sh
1323+
1324+
Get repositories that have Copilot custom instruction files, checking for both repository-wide (`.github/copilot-instructions.md`) and path-specific (`.github/instructions/`) instructions
1325+
1326+
Usage:
1327+
1328+
```shell
1329+
./get-repositories-with-copilot-instructions.sh my-org
1330+
```
1331+
1332+
### get-repositories-without-copilot-instructions.sh
1333+
1334+
Get repositories that do not have any Copilot custom instruction files (neither `.github/copilot-instructions.md` nor `.github/instructions/`)
1335+
1336+
Usage:
1337+
1338+
```shell
1339+
./get-repositories-without-copilot-instructions.sh my-org
1340+
```
1341+
13221342
### get-repository-languages-for-organization.sh
13231343

13241344
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).
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
3+
# Get repositories that have Copilot custom instruction files
4+
# Checks for:
5+
# - .github/copilot-instructions.md (repository-wide custom instructions)
6+
# - .github/instructions/ directory (path-specific custom instructions)
7+
#
8+
#
9+
# Authentication:
10+
# Requires a GitHub CLI token with at least read:org and repo scopes
11+
# Example: gh auth refresh -h github.com -s read:org,repo
12+
#
13+
# Usage:
14+
# ./get-repositories-with-copilot-instructions.sh <org>
15+
# If you want to see the results in a nicely formatted table, you can pipe the output to `column`:
16+
# ./get-repositories-with-copilot-instructions.sh <org> | column -ts $'\t'
17+
18+
if [ -z "$1" ]; then
19+
echo "Usage: $0 <org>"
20+
exit 1
21+
fi
22+
23+
org=$1
24+
25+
echo -e "Repository\tRepo-Wide\tPath-Specific Files"
26+
27+
gh api graphql --paginate -F owner="$org" -H "X-Github-Next-Global-ID: 1" -f query='
28+
query ($owner: String!, $endCursor: String = null) {
29+
organization(login: $owner) {
30+
repositories(
31+
first: 100
32+
orderBy: { field: NAME, direction: ASC }
33+
after: $endCursor
34+
) {
35+
totalCount
36+
pageInfo {hasNextPage endCursor}
37+
nodes {
38+
nameWithOwner
39+
repoWide: object(expression: "HEAD:.github/copilot-instructions.md") {
40+
... on Blob {
41+
byteSize
42+
}
43+
}
44+
pathSpecific: object(expression: "HEAD:.github/instructions/") {
45+
... on Tree {
46+
entries {
47+
path
48+
}
49+
}
50+
}
51+
}
52+
}
53+
}
54+
}
55+
' --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'
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/bash
2+
3+
# Get repositories that do not have any Copilot custom instruction files
4+
# Checks for the absence of both:
5+
# - .github/copilot-instructions.md (repository-wide custom instructions)
6+
# - .github/instructions/ directory (path-specific custom instructions)
7+
#
8+
# Authentication:
9+
# Requires a GitHub CLI token with at least read:org and repo scopes
10+
# Example: gh auth refresh -h github.com -s read:org,repo
11+
#
12+
# Usage:
13+
# ./get-repositories-without-copilot-instructions.sh <org>
14+
15+
if [ -z "$1" ]; then
16+
echo "Usage: $0 <org>"
17+
exit 1
18+
fi
19+
20+
org=$1
21+
22+
gh api graphql --paginate -F owner="$org" -H "X-Github-Next-Global-ID: 1" -f query='
23+
query ($owner: String!, $endCursor: String = null) {
24+
organization(login: $owner) {
25+
repositories(
26+
first: 100
27+
orderBy: { field: NAME, direction: ASC }
28+
after: $endCursor
29+
) {
30+
totalCount
31+
pageInfo {hasNextPage endCursor}
32+
nodes {
33+
nameWithOwner
34+
repoWide: object(expression: "HEAD:.github/copilot-instructions.md") {
35+
... on Blob {
36+
byteSize
37+
}
38+
}
39+
pathSpecific: object(expression: "HEAD:.github/instructions/") {
40+
... on Tree {
41+
entries {
42+
path
43+
}
44+
}
45+
}
46+
}
47+
}
48+
}
49+
}
50+
' --jq '.data.organization.repositories.nodes[] | select(.repoWide == null and .pathSpecific == null) | .nameWithOwner'

0 commit comments

Comments
 (0)