forked from texas-egads/JumbleJamTemplate
-
Notifications
You must be signed in to change notification settings - Fork 8
43 lines (34 loc) · 1.29 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
name: Grant Permissions
on:
workflow_dispatch:
inputs:
usernames:
description: 'Usernames to grant permissions (comma-separated)'
required: true
jobs:
add-collaborator:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Add collaborators
# if: github.actor == 'texas-egads'
run: |
REPO_OWNER="EGaDSAustin"
REPO_NAME="JJ-0"
GH_TOKEN="${{ secrets.GH_TOKEN }}"
# Split comma-separated list of usernames into an array
IFS=',' read -ra USERNAMES <<< "${{ github.event.inputs.usernames }}"
for USERNAME in "${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 }}