Repository: google/go-github
Pull request #1213 (2019-07-01 05:09:26)

Add repository creation permissions field
Resolves https://github.com/davidji99/go-github/issues/3

This PR is to introduce the `application/vnd.github.surtur-preview+json` Accept header when getting information about an organization.

Reference: https://developer.github.com/v3/orgs/#get-an-organization

codecov[bot]: # [Codecov](https://codecov.io/gh/google/go-github/pull/1213?src=pr&el=h1) Report
> Merging [#1213](https://codecov.io/gh/google/go-github/pull/1213?src=pr&el=desc) into [master](https://codecov.io/gh/google/go-github/commit/0ffc27d42b7ad05ff6890030162d9a3d495224e8?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/google/go-github/pull/1213/graphs/tree.svg?width=650&token=EgYjGjZlI0&height=150&src=pr)](https://codecov.io/gh/google/go-github/pull/1213?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master    #1213      +/-   ##
==========================================
+ Coverage   73.39%   73.39%   +<.01%     
==========================================
  Files          84       84              
  Lines        5949     5950       +1     
==========================================
+ Hits         4366     4367       +1     
  Misses        825      825              
  Partials      758      758
```


| [Impacted Files](https://codecov.io/gh/google/go-github/pull/1213?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [github/github.go](https://codecov.io/gh/google/go-github/pull/1213/diff?src=pr&el=tree#diff-Z2l0aHViL2dpdGh1Yi5nbw==) | `89.31% <ø> (ø)` | :arrow_up: |
| [github/orgs.go](https://codecov.io/gh/google/go-github/pull/1213/diff?src=pr&el=tree#diff-Z2l0aHViL29yZ3MuZ28=) | `71.87% <100%> (+0.44%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/google/go-github/pull/1213?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/google/go-github/pull/1213?src=pr&el=footer). Last update [0ffc27d...59005a5](https://codecov.io/gh/google/go-github/pull/1213?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

gmlewis: Thank you, @gauntface!
Merging.

Patch:
diff --git a/AUTHORS b/AUTHORS
index b1faeb0f..8a41ba02 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -70,6 +70,7 @@ Dave Du Cros <davidducros@gmail.com>
 Dave Henderson <dhenderson@gmail.com>
 David Deng <daviddengcn@gmail.com>
 David Jannotta <djannotta@gmail.com>
+David Ji <github.com/davidji99>
 Davide Zipeto <dawez1@gmail.com>
 Dennis Webb <dennis@bluesentryit.com>
 Dhi Aurrahman <diorahman@rockybars.com>
diff --git a/github/github-accessors.go b/github/github-accessors.go
index 0e37a9c2..b4ca033d 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.go b/github/github.go
index 7857c024..7a82677c 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 c70039ba..e1aa20db 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 {


Test patch:
diff --git a/github/github-stringify_test.go b/github/github-stringify_test.go
index 6934f237..f424531e 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/orgs_test.go b/github/orgs_test.go
index 9fe484db..3b938fc9 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"}`)
 	})