-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgithub-api.sh
executable file
·53 lines (44 loc) · 964 Bytes
/
github-api.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
: ${TOKEN?"please set you github token into KEY env variable"}
github(){
local path=$1
shift
[[ "TRACE" ]] && set -x
curl https://api.github.com/$path -H "Authorization: token $TOKEN" "$@"
set +x
}
github_put(){
curl https://api.github.com/$1 -H "Authorization: token $TOKEN" -X PUT -d ""
}
github_post(){
curl https://api.github.com/$1 -H "Authorization: token $TOKEN" -X POST -d @-
}
choose_repo(){
select repo in $(github "orgs/sequenceiq/repos?per_page=100" | jq .[].full_name -r); do
break
done
echo $repo
}
repo=$(choose_repo)
get_teamid(){
org=$1
team=$2
x=$(github orgs/$org/teams | jq '.[]| [.id, .name]' -c | grep $team)
y=${x%%,*}
teamid=${y:1}
echo $teamid
}
teamid=$(get_teamid sequenceiq dev)
set -x
github_put teams/$teamid/repos/$repo
:<<COMMENT
github_post orgs/sequenceiq/teams <<EOF
{
"name": "dev",
"permission": "push",
"repo_names": [
"github/dotfiles"
]
}
EOF
COMMENT