Skip to content

Commit 371b000

Browse files
Implement support for repository visibility parameter (#1471)
Fixes #1470.
1 parent 7726a3e commit 371b000

File tree

5 files changed

+35
-11
lines changed

5 files changed

+35
-11
lines changed

github/github-accessors.go

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/github-stringify_test.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/github.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ const (
138138

139139
// https://developer.github.com/changes/2019-11-05-deprecated-passwords-and-authorizations-api/
140140
mediaTypeOAuthAppPreview = "application/vnd.github.doctor-strange-preview+json"
141+
142+
// https://developer.github.com/changes/2019-12-03-internal-visibility-changes/
143+
mediaTypeRepositoryVisibilityPreview = "application/vnd.github.nebula-preview+json"
141144
)
142145

143146
// A Client manages communication with the GitHub API.

github/repos.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ type Repository struct {
121121
// TextMatches is only populated from search results that request text matches
122122
// See: search.go and https://developer.github.com/v3/search/#text-match-metadata
123123
TextMatches []*TextMatch `json:"text_matches,omitempty"`
124+
125+
// Visibility is only used for Create and Edit endpoints. The visibility field
126+
// overrides the field parameter when both are used.
127+
// Can be one of public, private or internal.
128+
Visibility *string `json:"visibility,omitempty"`
124129
}
125130

126131
func (r Repository) String() string {
@@ -295,11 +300,12 @@ type createRepoRequest struct {
295300
Description *string `json:"description,omitempty"`
296301
Homepage *string `json:"homepage,omitempty"`
297302

298-
Private *bool `json:"private,omitempty"`
299-
HasIssues *bool `json:"has_issues,omitempty"`
300-
HasProjects *bool `json:"has_projects,omitempty"`
301-
HasWiki *bool `json:"has_wiki,omitempty"`
302-
IsTemplate *bool `json:"is_template,omitempty"`
303+
Private *bool `json:"private,omitempty"`
304+
Visibility *string `json:"visibility,omitempty"`
305+
HasIssues *bool `json:"has_issues,omitempty"`
306+
HasProjects *bool `json:"has_projects,omitempty"`
307+
HasWiki *bool `json:"has_wiki,omitempty"`
308+
IsTemplate *bool `json:"is_template,omitempty"`
303309

304310
// Creating an organization repository. Required for non-owners.
305311
TeamID *int64 `json:"team_id,omitempty"`
@@ -334,6 +340,7 @@ func (s *RepositoriesService) Create(ctx context.Context, org string, repo *Repo
334340
Description: repo.Description,
335341
Homepage: repo.Homepage,
336342
Private: repo.Private,
343+
Visibility: repo.Visibility,
337344
HasIssues: repo.HasIssues,
338345
HasProjects: repo.HasProjects,
339346
HasWiki: repo.HasWiki,
@@ -353,7 +360,8 @@ func (s *RepositoriesService) Create(ctx context.Context, org string, repo *Repo
353360
return nil, nil, err
354361
}
355362

356-
req.Header.Set("Accept", mediaTypeRepositoryTemplatePreview)
363+
acceptHeaders := []string{mediaTypeRepositoryTemplatePreview, mediaTypeRepositoryVisibilityPreview}
364+
req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))
357365
r := new(Repository)
358366
resp, err := s.client.Do(ctx, req, r)
359367
if err != nil {
@@ -469,7 +477,8 @@ func (s *RepositoriesService) Edit(ctx context.Context, owner, repo string, repo
469477
return nil, nil, err
470478
}
471479

472-
req.Header.Set("Accept", mediaTypeRepositoryTemplatePreview)
480+
acceptHeaders := []string{mediaTypeRepositoryTemplatePreview, mediaTypeRepositoryVisibilityPreview}
481+
req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))
473482
r := new(Repository)
474483
resp, err := s.client.Do(ctx, req, r)
475484
if err != nil {

github/repos_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,13 @@ func TestRepositoriesService_Create_user(t *testing.T) {
251251
Archived: Bool(true), // not passed along.
252252
}
253253

254+
wantAcceptHeaders := []string{mediaTypeRepositoryTemplatePreview, mediaTypeRepositoryVisibilityPreview}
254255
mux.HandleFunc("/user/repos", func(w http.ResponseWriter, r *http.Request) {
255256
v := new(createRepoRequest)
256257
json.NewDecoder(r.Body).Decode(v)
257258

258259
testMethod(t, r, "POST")
259-
testHeader(t, r, "Accept", mediaTypeRepositoryTemplatePreview)
260+
testHeader(t, r, "Accept", strings.Join(wantAcceptHeaders, ", "))
260261
want := &createRepoRequest{Name: String("n")}
261262
if !reflect.DeepEqual(v, want) {
262263
t.Errorf("Request body = %+v, want %+v", v, want)
@@ -313,12 +314,13 @@ func TestRepositoriesService_Create_org(t *testing.T) {
313314
Archived: Bool(true), // not passed along.
314315
}
315316

317+
wantAcceptHeaders := []string{mediaTypeRepositoryTemplatePreview, mediaTypeRepositoryVisibilityPreview}
316318
mux.HandleFunc("/orgs/o/repos", func(w http.ResponseWriter, r *http.Request) {
317319
v := new(createRepoRequest)
318320
json.NewDecoder(r.Body).Decode(v)
319321

320322
testMethod(t, r, "POST")
321-
testHeader(t, r, "Accept", mediaTypeRepositoryTemplatePreview)
323+
testHeader(t, r, "Accept", strings.Join(wantAcceptHeaders, ", "))
322324
want := &createRepoRequest{Name: String("n")}
323325
if !reflect.DeepEqual(v, want) {
324326
t.Errorf("Request body = %+v, want %+v", v, want)
@@ -551,12 +553,13 @@ func TestRepositoriesService_Edit(t *testing.T) {
551553
i := true
552554
input := &Repository{HasIssues: &i}
553555

556+
wantAcceptHeaders := []string{mediaTypeRepositoryTemplatePreview, mediaTypeRepositoryVisibilityPreview}
554557
mux.HandleFunc("/repos/o/r", func(w http.ResponseWriter, r *http.Request) {
555558
v := new(Repository)
556559
json.NewDecoder(r.Body).Decode(v)
557560

558561
testMethod(t, r, "PATCH")
559-
testHeader(t, r, "Accept", mediaTypeRepositoryTemplatePreview)
562+
testHeader(t, r, "Accept", strings.Join(wantAcceptHeaders, ", "))
560563
if !reflect.DeepEqual(v, input) {
561564
t.Errorf("Request body = %+v, want %+v", v, input)
562565
}

0 commit comments

Comments
 (0)