Skip to content

Commit

Permalink
Merge pull request drone#82 from imeredith/org_create_repo_perms
Browse files Browse the repository at this point in the history
feat: include member repo creation perms in org
  • Loading branch information
jenkins-x-bot authored Mar 13, 2020
2 parents de626dd + ae8086d commit 0c28a56
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
23 changes: 20 additions & 3 deletions scm/driver/github/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ type organizationService struct {
}

type organization struct {
Login string `json:"login"`
Avatar string `json:"avatar_url"`
Login string `json:"login"`
Avatar string `json:"avatar_url"`
MembersCreatePublic bool `json:"members_can_create_public_repositories"`
MembersCreatePrivate bool `json:"members_can_create_private_repositories"`
MembersCreateInternal bool `json:"members_can_create_internal_repositories"`
}

type team struct {
Expand Down Expand Up @@ -57,7 +60,16 @@ func (s *organizationService) IsMember(ctx context.Context, org string, user str
func (s *organizationService) Find(ctx context.Context, name string) (*scm.Organization, *scm.Response, error) {
path := fmt.Sprintf("orgs/%s", name)
out := new(organization)
res, err := s.client.do(ctx, "GET", path, nil, out)
req := &scm.Request{
Method: http.MethodGet,
Path: path,
Header: map[string][]string{
// This accept header adds member create repo permissions
"Accept": {"application/vnd.github.surtur-preview+json"},
},
}
res, err := s.client.doRequest(ctx, req, nil, out)

return convertOrganization(out), res, err
}

Expand Down Expand Up @@ -106,6 +118,11 @@ func convertOrganization(from *organization) *scm.Organization {
return &scm.Organization{
Name: from.Login,
Avatar: from.Avatar,
Permissions: scm.Permissions{
MembersCreateInternal: from.MembersCreateInternal,
MembersCreatePublic: from.MembersCreatePublic,
MembersCreatePrivate: from.MembersCreatePrivate,
},
}
}

Expand Down
10 changes: 8 additions & 2 deletions scm/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@ import (
type (
// Organization represents an organization account.
Organization struct {
Name string
Avatar string
Name string
Avatar string
Permissions Permissions
}

Permissions struct {
MembersCreatePrivate bool
MembersCreatePublic bool
MembersCreateInternal bool
}
// Team is a organizational team
Team struct {
ID int
Expand Down

0 comments on commit 0c28a56

Please sign in to comment.