Due to the omitempty tag on NewTeam.ParentTeamID it is not possible (in my understanding) to update a child team to be a top-level team. Because updating a team is a PATCH operation, when parent_team_id is omitted, GitHub does not update the team's parent.
Happy to submit a PR.
For others listening in, I believe we are talking about this:
GitHub Developer v3 API docs: https://developer.github.com/v3/teams/#edit-team
and this:
https://github.com/gmlewis/go-github/blob/master/github/teams.go#L196-L216
So I'm not sure I understand the issue that you are raising. omitempty actually gives us more flexibility... if you don't provide an *int64, then the parameter won't be passed. But if you do indeed set the parameter, it will be passed... so I don't see what the problem is. Maybe if you give a more detailed example, I could possibly help.
But, having said that, I'm about to be out-of-town for 8 days with no internet... just FYI, I won't be responding for a while. Hopefully someone else can help you out.
@willnorris & @gauntface - just FYI I'm out-of-town for about a week, in case any urgent issues arise. Thanks.
Maybe if you give a more detailed example, I could possibly help.
Sure, what I'm seeing is that because ParentTeamID uses an omitempty tag, the JSON field parent_team_id is not included in the PATCH operation if ParentTeamID is nil. As such, there is no way to tell GitHub to update a team to longer have a parent (i.e. to become a top-level team). To tell GitHub to update a team to be top-level you minimally need:
{
"name": "foo",
"parent_team_id": null
}
But due to omitempty you get:
{
"name": "foo"
}
Which produces a no-op.
Sorry for the delay, @ashlineldridge, and thank you for the detailed explanation and example!
Yes, I understand now. Since this particular method still needs that parameter to be optional, it sounds like the correct solution to this problem is to create a new method that specifically updates the team to be one with no parent.
Now the challenge becomes "What do we name the new method"?
I'm leaning toward EditTeamRemoveParent, but am option to suggestions.
This new method would be identical to EditTeam except that its ParentTeamID field would be set to nil and omitempty would be removed.
If @gauntface has any other ideas on how to approach this, I would love to hear them.
@gmlewis Is the change needs to be done. I can send the patch fixing the issue.
Thank you, @yashLadha - it is yours.
Most helpful comment
@gmlewis Is the change needs to be done. I can send the patch fixing the issue.