Skip to content

Commit ad11d03

Browse files
committed
fix!: remove hardcoding of repo
1 parent 0fbc05f commit ad11d03

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

Diff for: gh-cli/README.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,17 @@ Adds a user to a ProjectV2 with a given role
125125
Example usage:
126126

127127
```shell
128-
./add-user-to-project.sh joshjohanning-org 1234 joshjohanning ADMIN"
128+
./add-user-to-project.sh <organization> <repository> <project-number> <user> <role>
129+
./add-user-to-project.sh joshjohanning-org my-repo 1234 joshjohanning ADMIN"
129130
```
130131

132+
Example roles:
133+
134+
- ADMIN
135+
- WRITER
136+
- READER
137+
- NONE
138+
131139
### add-user-to-repository.sh
132140

133141
Adds a user to a repository with a given permission

Diff for: gh-cli/add-user-to-project.sh

+14-9
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
# needs: gh auth login -s project
66

77
function print_usage {
8-
echo "Usage: $0 <org> <project-number> <user> <role>"
9-
echo "Example: ./add-user-to-project.sh joshjohanning-org 1234 joshjohanning ADMIN"
8+
echo "Usage: $0 <organization> <repository> <project-number> <user> <role>"
9+
echo "Example: ./add-user-to-project.sh joshjohanning-org my-repo 1234 joshjohanning ADMIN"
1010
echo "Valid roles: ADMIN, WRITER, READER, NONE"
1111
exit 1
1212
}
@@ -15,10 +15,11 @@ if [ -z "$4" ]; then
1515
print_usage
1616
fi
1717

18-
org="$1"
19-
project_number="$2"
20-
user="$3"
21-
role=$(echo "$4" | tr '[:lower:]' '[:upper:]')
18+
organization="$1"
19+
repository="$2"
20+
project_number="$3"
21+
user="$4"
22+
role=$(echo "$5" | tr '[:lower:]' '[:upper:]')
2223

2324
case "$role" in
2425
"ADMIN" | "WRITER" | "READER" | "NONE")
@@ -29,10 +30,10 @@ case "$role" in
2930
esac
3031

3132
# get project id
32-
project_id=$(gh api graphql --paginate -f organization="$org" -f repository="$repo" -f query='
33-
query ($organization: String!) {
33+
project_id=$(gh api graphql --paginate -f organization="$organization" -f repository="$repository" -f query='
34+
query ($organization: String!, $repository: String!) {
3435
organization (login: $organization) {
35-
repository (name: "cisco-cxepi") {
36+
repository (name: $repository) {
3637
name
3738
projectsV2 (first: 100) {
3839
nodes {
@@ -47,6 +48,8 @@ project_id=$(gh api graphql --paginate -f organization="$org" -f repository="$re
4748
}
4849
' --jq ".data.organization.repository.projectsV2.nodes[] | select(.number == $project_number) | .id")
4950

51+
echo "project_id: $project_id"
52+
5053
# get user id
5154
user_id=$(gh api graphql -H X-Github-Next-Global-ID:1 -f user="$user" -f query='
5255
query ($user: String!)
@@ -58,6 +61,8 @@ query ($user: String!)
5861
}
5962
' --jq '.data.user.id')
6063

64+
echo "user_id: $user_id"
65+
6166
# get epoch time
6267
epoch=$(date +%s)
6368
# create request.json

0 commit comments

Comments
 (0)