Ask Your Question
0

How can I use GitHub REST API to automate the process of adding numerous members to various teams through a Bash script?

asked 2023-03-10 11:00:00 +0000

nofretete gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-10-10 01:00:00 +0000

scrum gravatar image

First, you need to generate a personal access token (PAT) on your GitHub account that has permissions to manage team memberships. Then, you can use the following Bash script to automate the process:

#!/bin/bash

# Set variables
ORG_NAME="your-organization-name"
TEAM_NAME="your-team-name"
PAT="your-personal-access-token"

# Read a file containing a list of usernames (one per line)
while read -r USERNAME; do
    # Add the user to the team
    curl -X PUT -H "Authorization: token $PAT" "https://api.github.com/orgs/$ORG_NAME/teams/$TEAM_NAME/memberships/$USERNAME"
done < usernames.txt

Replace your-organization-name, your-team-name, your-personal-access-token, and usernames.txt with your own values. The usernames.txt file should contain a list of usernames (one per line) that you want to add to the team.

Save the script to a file (e.g. add-team-members.sh) and make it executable using chmod +x add-team-members.sh. Then, run the script with ./add-team-members.sh to add the users to the team.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-03-10 11:00:00 +0000

Seen: 11 times

Last updated: Oct 10 '22