forked from EGaDSAustin/JJ-0
-
Notifications
You must be signed in to change notification settings - Fork 0
66 lines (53 loc) · 2.19 KB
/
add-contributor.yml
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
54
55
56
57
58
59
60
61
62
63
64
65
66
name: Grant Permissions
on:
workflow_dispatch:
# inputs:
# add-usernames:
# description: 'Usernames to grant permissions (comma-separated)'
# required: true
# remove-usernames:
# description: 'Usernames to remove permissions (comma-separated)'
# required: true
jobs:
add-collaborator:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Remove existing collaborators
if: github.actor == 'texas-egads'
run: |
REPO_OWNER="EGaDSAustin"
REPO_NAME="${{ secrets.REPO_NAME }}"
GH_TOKEN="${{ secrets.GH_TOKEN }}"
# Split comma-separated list of usernames to remove into an array
IFS=',' read -ra REMOVE_USERNAMES <<< "${{ secrets.REMOVE_NAMES }}"
for USERNAME in "${REMOVE_USERNAMES[@]}"; do
# Remove the user as a collaborator
curl -X DELETE -H "Authorization: token $GH_TOKEN" \
"https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/collaborators/$USERNAME"
echo "Removed collaborator: $USERNAME"
done
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
- name: Add collaborators
if: github.actor == 'texas-egads'
run: |
REPO_OWNER="EGaDSAustin"
REPO_NAME="${{ secrets.REPO_NAME }}"
GH_TOKEN="${{ secrets.GH_TOKEN }}"
# Split comma-separated list of usernames to add into an array
IFS=',' read -ra ADD_USERNAMES <<< "${{ secrets.ADD_NAMES }}"
for USERNAME in "${ADD_USERNAMES[@]}"; do
# Get the user's ID
USER_ID=$(curl -s -H "Authorization: token $GH_TOKEN" \
"https://api.github.com/users/$USERNAME" | jq -r .id)
# Add the user as a collaborator
curl -X PUT -H "Authorization: token $GH_TOKEN" \
"https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/collaborators/$USERNAME" \
-d "{\"permission\":\"write\"}"
# Optionally, you can add some logging for each user
echo "Added collaborator: $USERNAME"
done
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}