diff --git a/AUTHORS b/AUTHORS index b1faeb0f7f3..8a41ba02676 100644 --- a/AUTHORS +++ b/AUTHORS @@ -70,6 +70,7 @@ Dave Du Cros Dave Henderson David Deng David Jannotta +David Ji Davide Zipeto Dennis Webb Dhi Aurrahman diff --git a/github/github-accessors.go b/github/github-accessors.go index 0e37a9c29cb..b4ca033d300 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -6156,6 +6156,14 @@ func (o *Organization) GetLogin() string { return *o.Login } +// GetMembersAllowedRepositoryCreationType returns the MembersAllowedRepositoryCreationType field if it's non-nil, zero value otherwise. +func (o *Organization) GetMembersAllowedRepositoryCreationType() string { + if o == nil || o.MembersAllowedRepositoryCreationType == nil { + return "" + } + return *o.MembersAllowedRepositoryCreationType +} + // GetMembersCanCreateRepos returns the MembersCanCreateRepos field if it's non-nil, zero value otherwise. func (o *Organization) GetMembersCanCreateRepos() bool { if o == nil || o.MembersCanCreateRepos == nil { diff --git a/github/github-stringify_test.go b/github/github-stringify_test.go index 6934f237c1d..f424531e1f3 100644 --- a/github/github-stringify_test.go +++ b/github/github-stringify_test.go @@ -793,42 +793,43 @@ func TestOrgStats_String(t *testing.T) { func TestOrganization_String(t *testing.T) { v := Organization{ - Login: String(""), - ID: Int64(0), - NodeID: String(""), - AvatarURL: String(""), - HTMLURL: String(""), - Name: String(""), - Company: String(""), - Blog: String(""), - Location: String(""), - Email: String(""), - Description: String(""), - PublicRepos: Int(0), - PublicGists: Int(0), - Followers: Int(0), - Following: Int(0), - TotalPrivateRepos: Int(0), - OwnedPrivateRepos: Int(0), - PrivateGists: Int(0), - DiskUsage: Int(0), - Collaborators: Int(0), - BillingEmail: String(""), - Type: String(""), - Plan: &Plan{}, - TwoFactorRequirementEnabled: Bool(false), - DefaultRepoPermission: String(""), - DefaultRepoSettings: String(""), - MembersCanCreateRepos: Bool(false), - URL: String(""), - EventsURL: String(""), - HooksURL: String(""), - IssuesURL: String(""), - MembersURL: String(""), - PublicMembersURL: String(""), - ReposURL: String(""), - } - want := `github.Organization{Login:"", ID:0, NodeID:"", AvatarURL:"", HTMLURL:"", Name:"", Company:"", Blog:"", Location:"", Email:"", Description:"", PublicRepos:0, PublicGists:0, Followers:0, Following:0, TotalPrivateRepos:0, OwnedPrivateRepos:0, PrivateGists:0, DiskUsage:0, Collaborators:0, BillingEmail:"", Type:"", Plan:github.Plan{}, TwoFactorRequirementEnabled:false, DefaultRepoPermission:"", DefaultRepoSettings:"", MembersCanCreateRepos:false, URL:"", EventsURL:"", HooksURL:"", IssuesURL:"", MembersURL:"", PublicMembersURL:"", ReposURL:""}` + Login: String(""), + ID: Int64(0), + NodeID: String(""), + AvatarURL: String(""), + HTMLURL: String(""), + Name: String(""), + Company: String(""), + Blog: String(""), + Location: String(""), + Email: String(""), + Description: String(""), + PublicRepos: Int(0), + PublicGists: Int(0), + Followers: Int(0), + Following: Int(0), + TotalPrivateRepos: Int(0), + OwnedPrivateRepos: Int(0), + PrivateGists: Int(0), + DiskUsage: Int(0), + Collaborators: Int(0), + BillingEmail: String(""), + Type: String(""), + Plan: &Plan{}, + TwoFactorRequirementEnabled: Bool(false), + DefaultRepoPermission: String(""), + DefaultRepoSettings: String(""), + MembersCanCreateRepos: Bool(false), + MembersAllowedRepositoryCreationType: String(""), + URL: String(""), + EventsURL: String(""), + HooksURL: String(""), + IssuesURL: String(""), + MembersURL: String(""), + PublicMembersURL: String(""), + ReposURL: String(""), + } + want := `github.Organization{Login:"", ID:0, NodeID:"", AvatarURL:"", HTMLURL:"", Name:"", Company:"", Blog:"", Location:"", Email:"", Description:"", PublicRepos:0, PublicGists:0, Followers:0, Following:0, TotalPrivateRepos:0, OwnedPrivateRepos:0, PrivateGists:0, DiskUsage:0, Collaborators:0, BillingEmail:"", Type:"", Plan:github.Plan{}, TwoFactorRequirementEnabled:false, DefaultRepoPermission:"", DefaultRepoSettings:"", MembersCanCreateRepos:false, MembersAllowedRepositoryCreationType:"", URL:"", EventsURL:"", HooksURL:"", IssuesURL:"", MembersURL:"", PublicMembersURL:"", ReposURL:""}` if got := v.String(); got != want { t.Errorf("Organization.String = %v, want %v", got, want) } diff --git a/github/github.go b/github/github.go index 7857c024cf1..7a82677c415 100644 --- a/github/github.go +++ b/github/github.go @@ -150,6 +150,9 @@ const ( // https://developer.github.com/changes/2019-06-12-team-sync/ mediaTypeTeamSyncPreview = "application/vnd.github.team-sync-preview+json" + + // https://developer.github.com/v3/previews/#repository-creation-permissions + mediaTypeMemberAllowedRepoCreationTypePreview = "application/vnd.github.surtur-preview+json" ) // A Client manages communication with the GitHub API. diff --git a/github/orgs.go b/github/orgs.go index c70039ba080..e1aa20db0b1 100644 --- a/github/orgs.go +++ b/github/orgs.go @@ -56,6 +56,10 @@ type Organization struct { // MembersCanCreateRepos default value is true and is only used in Organizations.Edit. MembersCanCreateRepos *bool `json:"members_can_create_repositories,omitempty"` + // MembersAllowedRepositoryCreationType denotes if organization members can create repositories + // and the type of repositories they can create. Possible values are: "all", "private", or "none". + MembersAllowedRepositoryCreationType *string `json:"members_allowed_repository_creation_type,omitempty"` + // API URLs URL *string `json:"url,omitempty"` EventsURL *string `json:"events_url,omitempty"` @@ -160,6 +164,9 @@ func (s *OrganizationsService) Get(ctx context.Context, org string) (*Organizati return nil, nil, err } + // TODO: remove custom Accept header when this API fully launches. + req.Header.Set("Accept", mediaTypeMemberAllowedRepoCreationTypePreview) + organization := new(Organization) resp, err := s.client.Do(ctx, req, organization) if err != nil { diff --git a/github/orgs_test.go b/github/orgs_test.go index 9fe484dbb1e..3b938fc993b 100644 --- a/github/orgs_test.go +++ b/github/orgs_test.go @@ -93,6 +93,7 @@ func TestOrganizationsService_Get(t *testing.T) { mux.HandleFunc("/orgs/o", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") + testHeader(t, r, "Accept", mediaTypeMemberAllowedRepoCreationTypePreview) fmt.Fprint(w, `{"id":1, "login":"l", "url":"u", "avatar_url": "a", "location":"l"}`) })