forked from jbdevstudio/github-teams
-
Notifications
You must be signed in to change notification settings - Fork 0
/
addmembers.sh
40 lines (24 loc) · 1.11 KB
/
addmembers.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
for name in "$@"
do
echo ------ Trying to setup permissions for $name
file=$(basename $name)
team="${file%.*}"
teamid=`curl -# -u $GITHUB_USER:$GITHUB_PWD https://api.github.com/orgs/jbdevstudio/teams | grep "name...*$team" -A1 | grep id | sed -e 's/.*\"id...\(.*\),/\1/g'`
echo Found $team having $teamid as id
cat $team.team | xargs -n 1 -I {} bash -c "echo Adding {} to $team && curl -u $GITHUB_USER:$GITHUB_PWD -X PUT -d '' https://api.github.com/teams/$teamid/members/{}"
if [[ $team == jbdevstudio-* ]] ;
then
echo Adding repo $team to team $team
curl -# -u $GITHUB_USER:$GITHUB_PWD -X PUT -d "" https://api.github.com/teams/$teamid/repos/jbdevstudio/$team
fi
curl -# -u $GITHUB_USER:$GITHUB_PWD https://api.github.com/teams/$teamid/members | grep \"login\"\: | sed -e 's/.*login":.*"\(.*\)",/\1/g' | sort > $team.existingmembers
# ensure hand written team is actually sorted.
sort $team.team -o $team.team
echo Comparing...
diff=`diff $team.existingmembers $team.team`
if [ "$diff" != "" ]
then
echo WARNING: Team $team does not have the exact members expected! Please check.
echo "$diff"
fi
done