Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: verify & set parent team after creation #1449

Merged
merged 7 commits into from
Jan 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions github/resource_github_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,31 @@ func resourceGithubTeamCreate(d *schema.ResourceData, meta interface{}) error {
return err
}

/*
When using a GitHub App for authentication, `members:write` permissions on the App are needed.

However, when using a GitHub App, CreateTeam will not correctly nest the team under the parent,
if the parent team was created by someone else than the GitHub App. In that case, the response
object will contain a `nil` parent object.

This can be resolved by using an additional call to EditTeamByID. This will be able to set the
parent team correctly when using a GitHub App with `members:write` permissions.

Note that this is best-effort: when running this with a PAT that does not have admin permissions
on the parent team, the operation might still fail to set the parent team.
*/
if newTeam.ParentTeamID != nil && githubTeam.Parent == nil {
_, _, err := client.Teams.EditTeamByID(ctx,
*githubTeam.Organization.ID,
*githubTeam.ID,
newTeam,
false)

if err != nil {
return err
}
}

create_default_maintainer := d.Get("create_default_maintainer").(bool)
if !create_default_maintainer {
log.Printf("[DEBUG] Removing default maintainer from team: %s (%s)", name, ownerName)
Expand Down