Skip to content

Commit 03955a4

Browse files
amirilovicdmitshur
authored andcommitted
Add admin enforcement to protected branches API. (google#610)
This change adds support for an addition to the Protected Branches API preview, the ability to turn on and off admin settings in one place. This is documented at https://developer.github.com/changes/2017-03-22-protected-branches-admin-improvements/. The IncludeAdmins fields are deprecated, but they're still required to be sent in the request for now. A future update to API preview will remove the IncludeAdmins fields completely. Helps google#606.
1 parent 415ab30 commit 03955a4

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
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/repos.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,19 +511,22 @@ type Branch struct {
511511
type Protection struct {
512512
RequiredStatusChecks *RequiredStatusChecks `json:"required_status_checks"`
513513
RequiredPullRequestReviews *RequiredPullRequestReviews `json:"required_pull_request_reviews"`
514+
EnforceAdmins *AdminEnforcement `json:"enforce_admins"`
514515
Restrictions *BranchRestrictions `json:"restrictions"`
515516
}
516517

517518
// ProtectionRequest represents a request to create/edit a branch's protection.
518519
type ProtectionRequest struct {
519520
RequiredStatusChecks *RequiredStatusChecks `json:"required_status_checks"`
520521
RequiredPullRequestReviews *RequiredPullRequestReviews `json:"required_pull_request_reviews"`
522+
EnforceAdmins bool `json:"enforce_admins"`
521523
Restrictions *BranchRestrictionsRequest `json:"restrictions"`
522524
}
523525

524526
// RequiredStatusChecks represents the protection status of a individual branch.
525527
type RequiredStatusChecks struct {
526528
// Enforce required status checks for repository administrators. (Required.)
529+
// Deprecated: Use EnforceAdmins instead.
527530
IncludeAdmins bool `json:"include_admins"`
528531
// Require branches to be up to date before merging. (Required.)
529532
Strict bool `json:"strict"`
@@ -535,9 +538,16 @@ type RequiredStatusChecks struct {
535538
// RequiredPullRequestReviews represents the protection configuration for pull requests.
536539
type RequiredPullRequestReviews struct {
537540
// Enforce pull request reviews for repository administrators. (Required.)
541+
// Deprecated: Use EnforceAdmins instead.
538542
IncludeAdmins bool `json:"include_admins"`
539543
}
540544

545+
// AdminEnforcement represents the configuration to enforce required status checks for repository administrators.
546+
type AdminEnforcement struct {
547+
URL *string `json:"url,omitempty"`
548+
Enabled bool `json:"enabled"`
549+
}
550+
541551
// BranchRestrictions represents the restriction that only certain users or
542552
// teams may push to a branch.
543553
type BranchRestrictions struct {

github/repos_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ func TestRepositoriesService_GetBranchProtection(t *testing.T) {
482482

483483
testMethod(t, r, "GET")
484484
testHeader(t, r, "Accept", mediaTypeProtectedBranchesPreview)
485-
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"}]}}`)
485+
fmt.Fprintf(w, `{"required_status_checks":{"include_admins":true,"strict":true,"contexts":["continuous-integration"]},"required_pull_request_reviews":{"include_admins":true},"enforce_admins":{"url":"/repos/o/r/branches/b/protection/enforce_admins","enabled":true},"restrictions":{"users":[{"id":1,"login":"u"}],"teams":[{"id":2,"slug":"t"}]}}`)
486486
})
487487

488488
protection, _, err := client.Repositories.GetBranchProtection(context.Background(), "o", "r", "b")
@@ -499,6 +499,10 @@ func TestRepositoriesService_GetBranchProtection(t *testing.T) {
499499
RequiredPullRequestReviews: &RequiredPullRequestReviews{
500500
IncludeAdmins: true,
501501
},
502+
EnforceAdmins: &AdminEnforcement{
503+
URL: String("/repos/o/r/branches/b/protection/enforce_admins"),
504+
Enabled: true,
505+
},
502506
Restrictions: &BranchRestrictions{
503507
Users: []*User{
504508
{Login: String("u"), ID: Int(1)},

0 commit comments

Comments
 (0)