Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add GitHub Team in Org to a REPO

I'm trying to do a Curl request to add a team to a repo like this:

curl --user $USERNAME:$TOKEN -X PUT -d "" "https://api.github.com/teams/<team name>/repos/<org>/$REPONAME"

My variables are the correct one, but I keep getting a message not found error. Anyone have an advice on how to proceed?

like image 986
user2019182 Avatar asked Dec 23 '22 18:12

user2019182


2 Answers

The correct endpoint from here is :

PUT /teams/:id/repos/:org/:repo

You have to specify the team ID not the team name

The following will get the team ID for the Developers team and perform the PUT request to add repo to the specified team :

username=your_user
password=your_password

org=your_org
repo=your_repo

team=Developers

teamid=$(curl -s --user $username:$password "https://api.github.com/orgs/$org/teams" | \
    jq --arg team "$team" '.[] | select(.name==$team) | .id')

curl -v --user $username:$password -d "" -X PUT "https://api.github.com/teams/$teamid/repos/$org/$repo"

Note for this example JSON parsing is done with jq

Also consider to use Personal access token with scope admin:org instead of your username/password (then use -H "Authorization: Token $TOKEN")

like image 154
Bertrand Martel Avatar answered Dec 28 '22 07:12

Bertrand Martel


The accepted answer is slightly out of date now.

Try here: https://docs.github.com/en/rest/reference/teams#add-or-update-team-repository-permissions

put /orgs/{org}/teams/{team_slug}/repos/{owner}/{repo}

curl \
  -X PUT \
  -H "Accept: application/vnd.github.v3+json" \
  -H "Authorization: token ......." \
  https://api.github.com/orgs/ORG/teams/TEAM_SLUG/repos/ORG/REPO \
  -d '{"permission":"permission"}'
like image 38
Damo Avatar answered Dec 28 '22 07:12

Damo