Skip to content

Teams.IsTeamRepoByID support for custom roles #2378

Closed

Description

@joshua-hancox

Now that GitHub has created the custom roles feature, I think the implementation of Teams.IsTeamRepoByID (and BySlug) may need to be changed, or a new function added.

https://github.com/google/go-github/blob/master/github/teams.go#L411L427

Currently, we return a repository object, which contains information about which permissions the specified team has on the repository.

e.g.

    "permissions": {
        "admin": true,
        "maintain": true,
        "push": true,
        "triage": true,
        "pull": true
    }

However, the API that we interact with here also returns the name of the role that is assigned to that team on that repository.

e.g

    "role_name": "admin"

Previously this was not an issue, as it was possible to work out what the role name would be based on the permissions object. (since all role names are included there.) Now that custom roles are available, a role based on the admin role may be created, but with a custom name.

e.g.

    "permissions": {
        "admin": true,
        "maintain": true,
        "push": true,
        "triage": true,
        "pull": true
    }
    "role_name": "super-admin"

Based on what is returned from this function currently, we cannot get the name of the role, and the permissions object looks identical to the one returned when the built-in admin role is assigned.

Should we extend the Repository type to include the role_name? It seems a bit strange to me that the permissions object is included there since that describes an assignment between a team and a repo rather than just an attribute of the repo. But if we wanted to follow that pattern would the change to include role_name make sense?

Activity

  1. gmlewis commented on Jun 6, 2022

    @gmlewis
    Collaborator

    Based on the API documentation you linked above, I don't see any other option but to include the role_name into the Repository struct, with a comment that it is returned only for certain API endpoints.

    Although this does indeed seem strange, what alternatives can you think of?

  2. joshua-hancox commented on Jun 6, 2022

    @joshua-hancox
    ContributorAuthor

    I wondered if this function should really return a Repository struct at all? Since we're checking what permissions a specific team has on a specific repository, should we create/use a new struct like TeamRepositoryPermissions.

    e.g.

    type TeamRepositoryPermissions struct {
    	Permissions         map[string]bool `json:"permissions,omitempty"`
    	RoleName            *string `json:"role_name,omitempty"`
    }

    But understand that would be a breaking change so maybe not ideal.

  3. gmlewis commented on Jun 6, 2022

    @gmlewis
    Collaborator

    Looking at the example response here: https://docs.github.com/en/rest/teams/teams#check-team-permissions-for-a-repository
    I don't see how we cannot return a Repository struct.

    For some reason, the GitHub v3 API team decided that all that information needed to be returned, so I don't think we want to discard the vast majority of it.

  4. joshua-hancox commented on Jun 7, 2022

    @joshua-hancox
    ContributorAuthor

    OK sure, understood. That being the case I guess we have no choice but to include role_name in the exiting repository struct?

    I'd also like to include the below function in github-accessors.go:

    // GetRoleName returns the role_name field if it's non-nil, zero value otherwise.
    func (r *Repository) GetRoleName() string {
    	if r == nil || r.RoleName == nil {
    		return ""
    	}
    	return *r.RoleName
    }

    If you agree, I'll raise a PR sometime today.

  5. gmlewis commented on Jun 7, 2022

    @gmlewis
    Collaborator

    Yes, go ahead with a PR but do not manually edit the accessors file as it is autogenerated. Please read CONTRIBUTING.md for details.

  6. joshua-hancox commented on Jun 7, 2022

    @joshua-hancox
    ContributorAuthor

    Ahh, I see. Thanks 😃 .

    PR is here whenever you get a second.

    #2379

  7. joshua-hancox commented on Jun 7, 2022

    @joshua-hancox
    ContributorAuthor

    Thankyou @gmlewis! Any idea when your next release will be?

  8. gmlewis commented on Jun 7, 2022

    @gmlewis
    Collaborator
  9. joshua-hancox commented on Jun 7, 2022

    @joshua-hancox
    ContributorAuthor

    Amazing! Thankyou

  10. added a commit that references this issue on May 9, 2024
    0b5813f
  11. added a commit that references this issue on Jun 28, 2026
    a254d88
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions