Skip to content

Commit 9069c95

Browse files
committed
adding script to get users in a repository
1 parent 7ed6162 commit 9069c95

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

gh-cli/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,10 @@ github/codeql-action/init@2
428428
actions/dependency-review-action@3
429429
```
430430

431+
### get-all-users-in-repository.sh
432+
433+
Gets all users who have created an issue, pull request, issue comment, or pull request comment in a repository.
434+
431435
### get-app-tokens-for-each-installation.sh
432436

433437
Generates a JWT for a GitHub app and use that JWT to generate installation tokens for each org installation. The installation tokens, returned as `ghs_abc`, can then be used for normal API calls. It requires the App ID and Private Key `pem` file as input.

gh-cli/get-all-users-in-repository.sh

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
if [ -z "$2" ]; then
4+
echo "Usage: $0 <org> <repo>"
5+
echo "Example: ./get-all-users-in-repository joshjohanning-org ghas-demo"
6+
exit 1
7+
fi
8+
9+
org="$1"
10+
repo="$2"
11+
12+
# export GH_HOST=ghes.mycompany.com
13+
14+
issue_comments=$(gh api --paginate /repos/$org/$repo/issues/comments | jq -r '.[].user.login' | sort | uniq)
15+
pr_comments=$(gh api --paginate /repos/$org/$repo/pulls/comments | jq -r '.[].user.login' | sort | uniq)
16+
issues=$(gh api --paginate /repos/$org/$repo/issues | jq -r '.[].user.login' | sort | uniq)
17+
prs=$(gh api --paginate /repos/$org/$repo/pulls | jq -r '.[].user.login' | sort | uniq)
18+
# commits=$(gh api --paginate /repos/$org/$repo/commits | jq -r '.[].committer.login' | sort | uniq) # <-- if want to include committers
19+
20+
# combine all the users into a single list
21+
users=$(echo -e "$issue_comments\n$pr_comments\n$pr_reviews\n$issues\n$prs" | sort | uniq)
22+
# users=$(echo -e "$issue_comments\n$pr_comments\n$pr_reviews\n$issues\n$prs\n$commits" | sort | uniq) # <-- if want to include committers
23+
24+
echo "$users"

0 commit comments

Comments
 (0)