Access to the repos #111036
Answered
by
luismarioagreda
rnadupal
asked this question in
Enterprise
Access to the repos
#111036
-
A Noob question. Looking for recommendations on how to add new users to GHE to an existing team group automatically? |
Beta Was this translation helpful? Give feedback.
Answered by
luismarioagreda
Mar 7, 2024
Replies: 1 comment
-
Its pretty straightforward with some Python and Github Actions. A general approach would be something like:
Python script would look something like: import requests
# Your GitHub Enterprise host
GITHUB_API = ''
TOKEN = ''
ORG_NAME = ''
TEAM_SLUG = ''
USERNAME = ''
headers = {
'Authorization': f'token {TOKEN}',
'Accept': 'application/vnd.github.v3+json',
}
def add_user_to_team(username):
url = f'{GITHUB_API}/orgs/{ORG_NAME}/teams/{TEAM_SLUG}/memberships/{username}'
response = requests.put(url, headers=headers)
if response.status_code == 200:
print(f'Successfully added {username} to the team.')
else:
print(f'Failed to add {username} to the team. Status code: {response.status_code}')
add_user_to_team(USERNAME) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
rnadupal
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Its pretty straightforward with some Python and Github Actions. A general approach would be something like:
Python script would look something like: