Skip to content

Commit b1bb756

Browse files
committed
adding get organization language count script
1 parent b04da8d commit b1bb756

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

gh-cli/README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ Gets the commits of since a certain date - date should be in [ISO 8601](https://
151151

152152
## get-dependencies-in-repository.sh
153153

154-
Gets dependencies used in the repository, including the ecosystem and version number. Example output:
154+
Gets dependencies used in the repository, including the ecosystem and version number.
155+
156+
Example output:
155157

156158
```csv
157159
@@ -219,6 +221,20 @@ Gets the current IP allow list for an organization.
219221

220222
See the [docs](https://docs.github.com/en/graphql/reference/objects#ipallowlistentry) for further information.
221223

224+
## get-organization-language-count.sh
225+
226+
Get a total count of the primary language of repositories in an organization.
227+
228+
Example output:
229+
230+
```
231+
21 Shell
232+
11 JavaScript
233+
11 Dockerfile
234+
10 C#
235+
4 Java
236+
```
237+
222238
## get-organization-members.sh
223239

224240
Gets a list of members and their role in an organization
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
3+
# Usage: ./get-organization-language-count.sh <org>
4+
5+
if [ -z "$1" ]; then
6+
echo "Usage: $0 <org>"
7+
exit 1
8+
fi
9+
10+
org=$1
11+
12+
results=$(gh api graphql --paginate -F owner="$org" -f query='
13+
query ($owner: String!, $endCursor: String) {
14+
organization(login: $owner) {
15+
repositories(first: 100, after: $endCursor) {
16+
totalCount
17+
nodes {
18+
nameWithOwner
19+
languages(first: 1) {
20+
nodes {
21+
name
22+
}
23+
}
24+
}
25+
pageInfo {
26+
endCursor
27+
hasNextPage
28+
}
29+
}
30+
}
31+
}')
32+
33+
echo $results >> results.json
34+
# sum the nodes.name
35+
echo $results | jq -r '.data.organization.repositories.nodes[].languages.nodes[].name' | sort | uniq -c | sort -nr

0 commit comments

Comments
 (0)