Skip to content

Commit

Permalink
Add BypassPullRequestAllowances field (#2432)
Browse files Browse the repository at this point in the history
Fixes: #2431
  • Loading branch information
Starttoaster committed Aug 13, 2022
1 parent aff6c4b commit 6212c67
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 2 deletions.
24 changes: 24 additions & 0 deletions github/github-accessors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions github/github-accessors_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions github/repos.go
Expand Up @@ -919,6 +919,8 @@ type RequiredStatusCheck struct {

// PullRequestReviewsEnforcement represents the pull request reviews enforcement of a protected branch.
type PullRequestReviewsEnforcement struct {
// Allow specific users, teams, or apps to bypass pull request requirements.
BypassPullRequestAllowances *BypassPullRequestAllowances `json:"bypass_pull_request_allowances,omitempty"`
// Specifies which users and teams can dismiss pull request reviews.
DismissalRestrictions *DismissalRestrictions `json:"dismissal_restrictions,omitempty"`
// Specifies if approved reviews are dismissed automatically, when a new commit is pushed.
Expand All @@ -934,6 +936,8 @@ type PullRequestReviewsEnforcement struct {
// enforcement of a protected branch. It is separate from PullRequestReviewsEnforcement above
// because the request structure is different from the response structure.
type PullRequestReviewsEnforcementRequest struct {
// Allow specific users, teams, or apps to bypass pull request requirements.
BypassPullRequestAllowancesRequest *BypassPullRequestAllowancesRequest `json:"bypass_pull_request_allowances,omitempty"`
// Specifies which users and teams should be allowed to dismiss pull request reviews.
// User and team dismissal restrictions are only available for
// organization-owned repositories. Must be nil for personal repositories.
Expand All @@ -951,6 +955,8 @@ type PullRequestReviewsEnforcementRequest struct {
// enforcement of a protected branch. It is separate from PullRequestReviewsEnforcementRequest above
// because the patch request does not require all fields to be initialized.
type PullRequestReviewsEnforcementUpdate struct {
// Allow specific users, teams, or apps to bypass pull request requirements.
BypassPullRequestAllowancesRequest *BypassPullRequestAllowancesRequest `json:"bypass_pull_request_allowances,omitempty"`
// Specifies which users and teams can dismiss pull request reviews. Can be omitted.
DismissalRestrictionsRequest *DismissalRestrictionsRequest `json:"dismissal_restrictions,omitempty"`
// Specifies if approved reviews can be dismissed automatically, when a new commit is pushed. Can be omitted.
Expand Down Expand Up @@ -1012,6 +1018,29 @@ type BranchRestrictionsRequest struct {
Apps []string `json:"apps,omitempty"`
}

// BypassPullRequestAllowances represents the people, teams, or apps who are allowed to bypass required pull requests.
type BypassPullRequestAllowances struct {
// The list of users allowed to bypass pull request requirements.
Users []*User `json:"users"`
// The list of teams allowed to bypass pull request requirements.
Teams []*Team `json:"teams"`
// The list of apps allowed to bypass pull request requirements.
Apps []*App `json:"apps"`
}

// BypassPullRequestAllowancesRequest represents the people, teams, or apps who are
// allowed to bypass required pull requests.
// It is separate from BypassPullRequestAllowances above because the request structure is
// different from the response structure.
type BypassPullRequestAllowancesRequest struct {
// The list of user logins allowed to bypass pull request requirements.
Users []string `json:"users"`
// The list of team slugs allowed to bypass pull request requirements.
Teams []string `json:"teams"`
// The list of app slugs allowed to bypass pull request requirements.
Apps []string `json:"apps"`
}

// DismissalRestrictions specifies which users and teams can dismiss pull request reviews.
type DismissalRestrictions struct {
// The list of users who can dimiss pull request reviews.
Expand Down
46 changes: 44 additions & 2 deletions github/repos_test.go
Expand Up @@ -1274,6 +1274,11 @@ func TestRepositoriesService_UpdateBranchProtection_Contexts(t *testing.T) {
Users: &[]string{"uu"},
Teams: &[]string{"tt"},
},
BypassPullRequestAllowancesRequest: &BypassPullRequestAllowancesRequest{
Users: []string{"uuu"},
Teams: []string{"ttt"},
Apps: []string{"aaa"},
},
},
Restrictions: &BranchRestrictionsRequest{
Users: []string{"u"},
Expand Down Expand Up @@ -1316,7 +1321,12 @@ func TestRepositoriesService_UpdateBranchProtection_Contexts(t *testing.T) {
}]
},
"dismiss_stale_reviews":true,
"require_code_owner_reviews":true
"require_code_owner_reviews":true,
"bypass_pull_request_allowances": {
"users":[{"id":10,"login":"uuu"}],
"teams":[{"id":20,"slug":"ttt"}],
"apps":[{"id":30,"slug":"aaa"}]
}
},
"restrictions":{
"users":[{"id":1,"login":"u"}],
Expand Down Expand Up @@ -1353,6 +1363,17 @@ func TestRepositoriesService_UpdateBranchProtection_Contexts(t *testing.T) {
},
},
RequireCodeOwnerReviews: true,
BypassPullRequestAllowances: &BypassPullRequestAllowances{
Users: []*User{
{Login: String("uuu"), ID: Int64(10)},
},
Teams: []*Team{
{Slug: String("ttt"), ID: Int64(20)},
},
Apps: []*App{
{Slug: String("aaa"), ID: Int64(30)},
},
},
},
Restrictions: &BranchRestrictions{
Users: []*User{
Expand Down Expand Up @@ -1404,6 +1425,11 @@ func TestRepositoriesService_UpdateBranchProtection_Checks(t *testing.T) {
Users: &[]string{"uu"},
Teams: &[]string{"tt"},
},
BypassPullRequestAllowancesRequest: &BypassPullRequestAllowancesRequest{
Users: []string{"uuu"},
Teams: []string{"ttt"},
Apps: []string{"aaa"},
},
},
Restrictions: &BranchRestrictionsRequest{
Users: []string{"u"},
Expand Down Expand Up @@ -1446,7 +1472,12 @@ func TestRepositoriesService_UpdateBranchProtection_Checks(t *testing.T) {
}]
},
"dismiss_stale_reviews":true,
"require_code_owner_reviews":true
"require_code_owner_reviews":true,
"bypass_pull_request_allowances": {
"users":[{"id":10,"login":"uuu"}],
"teams":[{"id":20,"slug":"ttt"}],
"apps":[{"id":30,"slug":"aaa"}]
}
},
"restrictions":{
"users":[{"id":1,"login":"u"}],
Expand Down Expand Up @@ -1483,6 +1514,17 @@ func TestRepositoriesService_UpdateBranchProtection_Checks(t *testing.T) {
},
},
RequireCodeOwnerReviews: true,
BypassPullRequestAllowances: &BypassPullRequestAllowances{
Users: []*User{
{Login: String("uuu"), ID: Int64(10)},
},
Teams: []*Team{
{Slug: String("ttt"), ID: Int64(20)},
},
Apps: []*App{
{Slug: String("aaa"), ID: Int64(30)},
},
},
},
Restrictions: &BranchRestrictions{
Users: []*User{
Expand Down

0 comments on commit 6212c67

Please sign in to comment.