user2019182
user2019182

Reputation: 315

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?

Upvotes: 8

Views: 12961

Answers (2)

Damo
Damo

Reputation: 6453

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

Upvotes: 8

Bertrand Martel
Bertrand Martel

Reputation: 45503

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")

Upvotes: 7

Related Questions