Skip to content

Grant Permissions

Grant Permissions #24

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 }}