diff --git a/github/github-accessors.go b/github/github-accessors.go index 42b1abc802..f91f9a93ba 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -4558,6 +4558,14 @@ func (d *DiscussionEvent) GetSender() *User { return d.Sender } +// GetApps returns the Apps field if it's non-nil, zero value otherwise. +func (d *DismissalRestrictionsRequest) GetApps() []string { + if d == nil || d.Apps == nil { + return nil + } + return *d.Apps +} + // GetTeams returns the Teams field if it's non-nil, zero value otherwise. func (d *DismissalRestrictionsRequest) GetTeams() []string { if d == nil || d.Teams == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index c65c98d2d2..3fee246979 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -5326,6 +5326,16 @@ func TestDiscussionEvent_GetSender(tt *testing.T) { d.GetSender() } +func TestDismissalRestrictionsRequest_GetApps(tt *testing.T) { + var zeroValue []string + d := &DismissalRestrictionsRequest{Apps: &zeroValue} + d.GetApps() + d = &DismissalRestrictionsRequest{} + d.GetApps() + d = nil + d.GetApps() +} + func TestDismissalRestrictionsRequest_GetTeams(tt *testing.T) { var zeroValue []string d := &DismissalRestrictionsRequest{Teams: &zeroValue} diff --git a/github/repos.go b/github/repos.go index 8f5bbea9d4..e12cff0837 100644 --- a/github/repos.go +++ b/github/repos.go @@ -1019,7 +1019,7 @@ type RequiredStatusCheck struct { 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. + // Specifies which users, teams and apps can dismiss pull request reviews. DismissalRestrictions *DismissalRestrictions `json:"dismissal_restrictions,omitempty"` // Specifies if approved reviews are dismissed automatically, when a new commit is pushed. DismissStaleReviews bool `json:"dismiss_stale_reviews"` @@ -1036,8 +1036,8 @@ type PullRequestReviewsEnforcement struct { 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 + // Specifies which users, teams and apps should be allowed to dismiss pull request reviews. + // User, team and app dismissal restrictions are only available for // organization-owned repositories. Must be nil for personal repositories. DismissalRestrictionsRequest *DismissalRestrictionsRequest `json:"dismissal_restrictions,omitempty"` // Specifies if approved reviews can be dismissed automatically, when a new commit is pushed. (Required) @@ -1055,7 +1055,7 @@ type PullRequestReviewsEnforcementRequest struct { 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. + // Specifies which users, teams and apps 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. DismissStaleReviews *bool `json:"dismiss_stale_reviews,omitempty"` @@ -1113,7 +1113,7 @@ type BranchRestrictionsRequest struct { // The list of team slugs with push access. (Required; use []string{} instead of nil for empty list.) Teams []string `json:"teams"` // The list of app slugs with push access. - Apps []string `json:"apps,omitempty"` + Apps []string `json:"apps"` } // BypassPullRequestAllowances represents the people, teams, or apps who are allowed to bypass required pull requests. @@ -1145,10 +1145,12 @@ type DismissalRestrictions struct { Users []*User `json:"users"` // The list of teams which can dismiss pull request reviews. Teams []*Team `json:"teams"` + // The list of apps which can dismiss pull request reviews. + Apps []*App `json:"apps"` } // DismissalRestrictionsRequest represents the request to create/edit the -// restriction to allows only specific users or teams to dimiss pull request reviews. It is +// restriction to allows only specific users, teams or apps to dimiss pull request reviews. It is // separate from DismissalRestrictions above because the request structure is // different from the response structure. // Note: Both Users and Teams must be nil, or both must be non-nil. @@ -1157,6 +1159,8 @@ type DismissalRestrictionsRequest struct { Users *[]string `json:"users,omitempty"` // The list of team slugs which can dismiss pull request reviews. (Required; use nil to disable dismissal_restrictions or &[]string{} otherwise.) Teams *[]string `json:"teams,omitempty"` + // The list of apps which can dismiss pull request reviews. (Required; use nil to disable dismissal_restrictions or &[]string{} otherwise.) + Apps *[]string `json:"apps,omitempty"` } // SignaturesProtectedBranch represents the protection status of an individual branch. diff --git a/github/repos_test.go b/github/repos_test.go index f7ee58b231..ec32b5d578 100644 --- a/github/repos_test.go +++ b/github/repos_test.go @@ -1074,6 +1074,10 @@ func TestRepositoriesService_GetBranchProtection(t *testing.T) { "teams":[{ "id":4, "slug":"t" + }], + "apps":[{ + "id":5, + "slug":"a" }] }, "dismiss_stale_reviews":true, @@ -1086,7 +1090,8 @@ func TestRepositoriesService_GetBranchProtection(t *testing.T) { }, "restrictions":{ "users":[{"id":1,"login":"u"}], - "teams":[{"id":2,"slug":"t"}] + "teams":[{"id":2,"slug":"t"}], + "apps":[{"id":3,"slug":"a"}] }, "required_conversation_resolution": { "enabled": true @@ -1119,6 +1124,9 @@ func TestRepositoriesService_GetBranchProtection(t *testing.T) { Teams: []*Team{ {Slug: String("t"), ID: Int64(4)}, }, + Apps: []*App{ + {Slug: String("a"), ID: Int64(5)}, + }, }, RequireCodeOwnerReviews: true, RequiredApprovingReviewCount: 1, @@ -1134,6 +1142,9 @@ func TestRepositoriesService_GetBranchProtection(t *testing.T) { Teams: []*Team{ {Slug: String("t"), ID: Int64(2)}, }, + Apps: []*App{ + {Slug: String("a"), ID: Int64(3)}, + }, }, RequiredConversationResolution: &RequiredConversationResolution{ Enabled: true, @@ -1273,6 +1284,7 @@ func TestRepositoriesService_UpdateBranchProtection_Contexts(t *testing.T) { DismissalRestrictionsRequest: &DismissalRestrictionsRequest{ Users: &[]string{"uu"}, Teams: &[]string{"tt"}, + Apps: &[]string{"aa"}, }, BypassPullRequestAllowancesRequest: &BypassPullRequestAllowancesRequest{ Users: []string{"uuu"}, @@ -1318,6 +1330,10 @@ func TestRepositoriesService_UpdateBranchProtection_Contexts(t *testing.T) { "teams":[{ "id":4, "slug":"tt" + }], + "apps":[{ + "id":5, + "slug":"aa" }] }, "dismiss_stale_reviews":true, @@ -1361,6 +1377,9 @@ func TestRepositoriesService_UpdateBranchProtection_Contexts(t *testing.T) { Teams: []*Team{ {Slug: String("tt"), ID: Int64(4)}, }, + Apps: []*App{ + {Slug: String("aa"), ID: Int64(5)}, + }, }, RequireCodeOwnerReviews: true, BypassPullRequestAllowances: &BypassPullRequestAllowances{ @@ -1424,6 +1443,7 @@ func TestRepositoriesService_UpdateBranchProtection_Checks(t *testing.T) { DismissalRestrictionsRequest: &DismissalRestrictionsRequest{ Users: &[]string{"uu"}, Teams: &[]string{"tt"}, + Apps: &[]string{"aa"}, }, BypassPullRequestAllowancesRequest: &BypassPullRequestAllowancesRequest{ Users: []string{"uuu"}, @@ -1469,6 +1489,10 @@ func TestRepositoriesService_UpdateBranchProtection_Checks(t *testing.T) { "teams":[{ "id":4, "slug":"tt" + }], + "apps":[{ + "id":5, + "slug":"aa" }] }, "dismiss_stale_reviews":true, @@ -1512,6 +1536,9 @@ func TestRepositoriesService_UpdateBranchProtection_Checks(t *testing.T) { Teams: []*Team{ {Slug: String("tt"), ID: Int64(4)}, }, + Apps: []*App{ + {Slug: String("aa"), ID: Int64(5)}, + }, }, RequireCodeOwnerReviews: true, BypassPullRequestAllowances: &BypassPullRequestAllowances{ @@ -1557,6 +1584,7 @@ func TestRepositoriesService_UpdateBranchProtection_StrictNoChecks(t *testing.T) DismissalRestrictionsRequest: &DismissalRestrictionsRequest{ Users: &[]string{"uu"}, Teams: &[]string{"tt"}, + Apps: &[]string{"aa"}, }, BypassPullRequestAllowancesRequest: &BypassPullRequestAllowancesRequest{ Users: []string{"uuu"}, @@ -1597,6 +1625,10 @@ func TestRepositoriesService_UpdateBranchProtection_StrictNoChecks(t *testing.T) "teams":[{ "id":4, "slug":"tt" + }], + "apps":[{ + "id":5, + "slug":"aa" }] }, "dismiss_stale_reviews":true, @@ -1636,6 +1668,9 @@ func TestRepositoriesService_UpdateBranchProtection_StrictNoChecks(t *testing.T) Teams: []*Team{ {Slug: String("tt"), ID: Int64(4)}, }, + Apps: []*App{ + {Slug: String("aa"), ID: Int64(5)}, + }, }, RequireCodeOwnerReviews: true, BypassPullRequestAllowances: &BypassPullRequestAllowances{ @@ -2088,7 +2123,8 @@ func TestRepositoriesService_GetPullRequestReviewEnforcement(t *testing.T) { fmt.Fprintf(w, `{ "dismissal_restrictions":{ "users":[{"id":1,"login":"u"}], - "teams":[{"id":2,"slug":"t"}] + "teams":[{"id":2,"slug":"t"}], + "apps":[{"id":3,"slug":"a"}] }, "dismiss_stale_reviews":true, "require_code_owner_reviews":true, @@ -2111,6 +2147,9 @@ func TestRepositoriesService_GetPullRequestReviewEnforcement(t *testing.T) { Teams: []*Team{ {Slug: String("t"), ID: Int64(2)}, }, + Apps: []*App{ + {Slug: String("a"), ID: Int64(3)}, + }, }, RequireCodeOwnerReviews: true, RequiredApprovingReviewCount: 1, @@ -2143,6 +2182,7 @@ func TestRepositoriesService_UpdatePullRequestReviewEnforcement(t *testing.T) { DismissalRestrictionsRequest: &DismissalRestrictionsRequest{ Users: &[]string{"u"}, Teams: &[]string{"t"}, + Apps: &[]string{"a"}, }, } @@ -2159,7 +2199,8 @@ func TestRepositoriesService_UpdatePullRequestReviewEnforcement(t *testing.T) { fmt.Fprintf(w, `{ "dismissal_restrictions":{ "users":[{"id":1,"login":"u"}], - "teams":[{"id":2,"slug":"t"}] + "teams":[{"id":2,"slug":"t"}], + "apps":[{"id":3,"slug":"a"}] }, "dismiss_stale_reviews":true, "require_code_owner_reviews":true, @@ -2182,6 +2223,9 @@ func TestRepositoriesService_UpdatePullRequestReviewEnforcement(t *testing.T) { Teams: []*Team{ {Slug: String("t"), ID: Int64(2)}, }, + Apps: []*App{ + {Slug: String("a"), ID: Int64(3)}, + }, }, RequireCodeOwnerReviews: true, RequiredApprovingReviewCount: 3, @@ -2515,6 +2559,7 @@ func TestPullRequestReviewsEnforcementRequest_MarshalJSON_nilDismissalRestirctio DismissalRestrictionsRequest: &DismissalRestrictionsRequest{ Users: &[]string{}, Teams: &[]string{}, + Apps: &[]string{}, }, } @@ -2523,7 +2568,7 @@ func TestPullRequestReviewsEnforcementRequest_MarshalJSON_nilDismissalRestirctio t.Errorf("PullRequestReviewsEnforcementRequest.MarshalJSON returned error: %v", err) } - want = `{"dismissal_restrictions":{"users":[],"teams":[]},"dismiss_stale_reviews":false,"require_code_owner_reviews":false,"required_approving_review_count":0}` + want = `{"dismissal_restrictions":{"users":[],"teams":[],"apps":[]},"dismiss_stale_reviews":false,"require_code_owner_reviews":false,"required_approving_review_count":0}` if want != string(got) { t.Errorf("PullRequestReviewsEnforcementRequest.MarshalJSON returned %+v, want %+v", string(got), want) }