Skip to content

Commit d2e5fee

Browse files
alindemangmlewis
authored andcommitted
Adds required pull request reviews
`required_pull_request_reviews` is a newly introduced object: * https://developer.github.com/v3/repos/branches/#get-branch-protection * https://developer.github.com/v3/repos/branches/#update-branch-protection Closes google#512. Change-Id: Ia4d3ff3e39163fe58a691a8abf0a067bf3c714e5
1 parent 2997b5c commit d2e5fee

File tree

2 files changed

+41
-24
lines changed

2 files changed

+41
-24
lines changed

github/repos.go

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -508,34 +508,42 @@ type Branch struct {
508508

509509
// Protection represents a repository branch's protection.
510510
type Protection struct {
511-
RequiredStatusChecks *RequiredStatusChecks `json:"required_status_checks"`
512-
Restrictions *BranchRestrictions `json:"restrictions"`
511+
RequiredStatusChecks *RequiredStatusChecks `json:"required_status_checks"`
512+
RequiredPullRequestReviews *RequiredPullRequestReviews `json:"required_pull_request_reviews"`
513+
Restrictions *BranchRestrictions `json:"restrictions"`
513514
}
514515

515516
// ProtectionRequest represents a request to create/edit a branch's protection.
516517
type ProtectionRequest struct {
517-
RequiredStatusChecks *RequiredStatusChecks `json:"required_status_checks"`
518-
Restrictions *BranchRestrictionsRequest `json:"restrictions"`
518+
RequiredStatusChecks *RequiredStatusChecks `json:"required_status_checks"`
519+
RequiredPullRequestReviews *RequiredPullRequestReviews `json:"required_pull_request_reviews"`
520+
Restrictions *BranchRestrictionsRequest `json:"restrictions"`
519521
}
520522

521523
// RequiredStatusChecks represents the protection status of a individual branch.
522524
type RequiredStatusChecks struct {
523525
// Enforce required status checks for repository administrators.
524-
IncludeAdmins *bool `json:"include_admins,omitempty"`
526+
IncludeAdmins bool `json:"include_admins"`
525527
// Require branches to be up to date before merging.
526-
Strict *bool `json:"strict,omitempty"`
528+
Strict bool `json:"strict"`
527529
// The list of status checks to require in order to merge into this
528530
// branch.
529-
Contexts *[]string `json:"contexts,omitempty"`
531+
Contexts []string `json:"contexts"`
532+
}
533+
534+
// RequiredPullRequestReviews represents the protection configuration for pull requests.
535+
type RequiredPullRequestReviews struct {
536+
// Enforce pull request reviews for repository administrators.
537+
IncludeAdmins bool `json:"include_admins"`
530538
}
531539

532540
// BranchRestrictions represents the restriction that only certain users or
533541
// teams may push to a branch.
534542
type BranchRestrictions struct {
535543
// The list of user logins with push access.
536-
Users []*User `json:"users,omitempty"`
544+
Users []*User `json:"users"`
537545
// The list of team slugs with push access.
538-
Teams []*Team `json:"teams,omitempty"`
546+
Teams []*Team `json:"teams"`
539547
}
540548

541549
// BranchRestrictionsRequest represents the request to create/edit the
@@ -544,9 +552,9 @@ type BranchRestrictions struct {
544552
// different from the response structure.
545553
type BranchRestrictionsRequest struct {
546554
// The list of user logins with push access.
547-
Users *[]string `json:"users,omitempty"`
555+
Users []string `json:"users"`
548556
// The list of team slugs with push access.
549-
Teams *[]string `json:"teams,omitempty"`
557+
Teams []string `json:"teams"`
550558
}
551559

552560
// ListBranches lists branches for the specified repository.

github/repos_test.go

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ func TestRepositoriesService_GetBranchProtection(t *testing.T) {
481481

482482
testMethod(t, r, "GET")
483483
testHeader(t, r, "Accept", mediaTypeProtectedBranchesPreview)
484-
fmt.Fprintf(w, `{"required_status_checks":{"include_admins":true,"strict":true,"contexts":["continuous-integration"]},"restrictions":{"users":[{"id":1,"login":"u"}],"teams":[{"id":2,"slug":"t"}]}}`)
484+
fmt.Fprintf(w, `{"required_status_checks":{"include_admins":true,"strict":true,"contexts":["continuous-integration"]},"required_pull_request_reviews":{"include_admins":true},"restrictions":{"users":[{"id":1,"login":"u"}],"teams":[{"id":2,"slug":"t"}]}}`)
485485
})
486486

487487
protection, _, err := client.Repositories.GetBranchProtection("o", "r", "b")
@@ -491,9 +491,12 @@ func TestRepositoriesService_GetBranchProtection(t *testing.T) {
491491

492492
want := &Protection{
493493
RequiredStatusChecks: &RequiredStatusChecks{
494-
IncludeAdmins: Bool(true),
495-
Strict: Bool(true),
496-
Contexts: &[]string{"continuous-integration"},
494+
IncludeAdmins: true,
495+
Strict: true,
496+
Contexts: []string{"continuous-integration"},
497+
},
498+
RequiredPullRequestReviews: &RequiredPullRequestReviews{
499+
IncludeAdmins: true,
497500
},
498501
Restrictions: &BranchRestrictions{
499502
Users: []*User{
@@ -515,13 +518,16 @@ func TestRepositoriesService_UpdateBranchProtection(t *testing.T) {
515518

516519
input := &ProtectionRequest{
517520
RequiredStatusChecks: &RequiredStatusChecks{
518-
IncludeAdmins: Bool(true),
519-
Strict: Bool(true),
520-
Contexts: &[]string{"continuous-integration"},
521+
IncludeAdmins: true,
522+
Strict: true,
523+
Contexts: []string{"continuous-integration"},
524+
},
525+
RequiredPullRequestReviews: &RequiredPullRequestReviews{
526+
IncludeAdmins: true,
521527
},
522528
Restrictions: &BranchRestrictionsRequest{
523-
Users: &[]string{"u"},
524-
Teams: &[]string{"t"},
529+
Users: []string{"u"},
530+
Teams: []string{"t"},
525531
},
526532
}
527533

@@ -534,7 +540,7 @@ func TestRepositoriesService_UpdateBranchProtection(t *testing.T) {
534540
t.Errorf("Request body = %+v, want %+v", v, input)
535541
}
536542
testHeader(t, r, "Accept", mediaTypeProtectedBranchesPreview)
537-
fmt.Fprintf(w, `{"required_status_checks":{"include_admins":true,"strict":true,"contexts":["continuous-integration"]},"restrictions":{"users":[{"id":1,"login":"u"}],"teams":[{"id":2,"slug":"t"}]}}`)
543+
fmt.Fprintf(w, `{"required_status_checks":{"include_admins":true,"strict":true,"contexts":["continuous-integration"]},"required_pull_request_reviews":{"include_admins":true},"restrictions":{"users":[{"id":1,"login":"u"}],"teams":[{"id":2,"slug":"t"}]}}`)
538544
})
539545

540546
protection, _, err := client.Repositories.UpdateBranchProtection("o", "r", "b", input)
@@ -544,9 +550,12 @@ func TestRepositoriesService_UpdateBranchProtection(t *testing.T) {
544550

545551
want := &Protection{
546552
RequiredStatusChecks: &RequiredStatusChecks{
547-
IncludeAdmins: Bool(true),
548-
Strict: Bool(true),
549-
Contexts: &[]string{"continuous-integration"},
553+
IncludeAdmins: true,
554+
Strict: true,
555+
Contexts: []string{"continuous-integration"},
556+
},
557+
RequiredPullRequestReviews: &RequiredPullRequestReviews{
558+
IncludeAdmins: true,
550559
},
551560
Restrictions: &BranchRestrictions{
552561
Users: []*User{

0 commit comments

Comments
 (0)