-
Notifications
You must be signed in to change notification settings - Fork 0
/
perm1.sh
28 lines (22 loc) · 944 Bytes
/
perm1.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
#!/bin/bash
OWNER='lithesheeli'
# Get GitLab members
GITLAB_MEMBERS=$(curl --header "PRIVATE-TOKEN: $GITLAB_TOKEN" "$GITLAB_URL/projects/$PROJECT_ID/members")
# Loop through members and add to GitHub
echo "${GITLAB_MEMBERS}" | jq -r '.[] | @base64' | while read row; do
_jq() {
echo ${row} | base64 --decode | jq -r ${1}
}
USERNAME=$(_jq '.username')
PERMISSION="push" # Map GitLab role to GitHub permission as needed
# Add member to GitHub
RESPONSE=$(curl -X PUT -H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
"$GITHUB_URL/repos/$OWNER/$REPO_NAME/collaborators/$USERNAME" \
-d "{\"permission\":\"$PERMISSION\"}")
if [ $? -eq 0 ]; then
echo "Successfully added $USERNAME to GitHub with $PERMISSION permission"
else
echo "Failed to add $USERNAME: $RESPONSE"
fi
done