Skip to content

Commit fce4030

Browse files
authored
Add apps to restriction rules in branch protection (#2509)
Fixes: #2506.
1 parent 3dcfcf6 commit fce4030

File tree

4 files changed

+77
-10
lines changed

4 files changed

+77
-10
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-accessors_test.go

Lines changed: 10 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 & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,7 @@ type RequiredStatusCheck struct {
10191019
type PullRequestReviewsEnforcement struct {
10201020
// Allow specific users, teams, or apps to bypass pull request requirements.
10211021
BypassPullRequestAllowances *BypassPullRequestAllowances `json:"bypass_pull_request_allowances,omitempty"`
1022-
// Specifies which users and teams can dismiss pull request reviews.
1022+
// Specifies which users, teams and apps can dismiss pull request reviews.
10231023
DismissalRestrictions *DismissalRestrictions `json:"dismissal_restrictions,omitempty"`
10241024
// Specifies if approved reviews are dismissed automatically, when a new commit is pushed.
10251025
DismissStaleReviews bool `json:"dismiss_stale_reviews"`
@@ -1036,8 +1036,8 @@ type PullRequestReviewsEnforcement struct {
10361036
type PullRequestReviewsEnforcementRequest struct {
10371037
// Allow specific users, teams, or apps to bypass pull request requirements.
10381038
BypassPullRequestAllowancesRequest *BypassPullRequestAllowancesRequest `json:"bypass_pull_request_allowances,omitempty"`
1039-
// Specifies which users and teams should be allowed to dismiss pull request reviews.
1040-
// User and team dismissal restrictions are only available for
1039+
// Specifies which users, teams and apps should be allowed to dismiss pull request reviews.
1040+
// User, team and app dismissal restrictions are only available for
10411041
// organization-owned repositories. Must be nil for personal repositories.
10421042
DismissalRestrictionsRequest *DismissalRestrictionsRequest `json:"dismissal_restrictions,omitempty"`
10431043
// Specifies if approved reviews can be dismissed automatically, when a new commit is pushed. (Required)
@@ -1055,7 +1055,7 @@ type PullRequestReviewsEnforcementRequest struct {
10551055
type PullRequestReviewsEnforcementUpdate struct {
10561056
// Allow specific users, teams, or apps to bypass pull request requirements.
10571057
BypassPullRequestAllowancesRequest *BypassPullRequestAllowancesRequest `json:"bypass_pull_request_allowances,omitempty"`
1058-
// Specifies which users and teams can dismiss pull request reviews. Can be omitted.
1058+
// Specifies which users, teams and apps can dismiss pull request reviews. Can be omitted.
10591059
DismissalRestrictionsRequest *DismissalRestrictionsRequest `json:"dismissal_restrictions,omitempty"`
10601060
// Specifies if approved reviews can be dismissed automatically, when a new commit is pushed. Can be omitted.
10611061
DismissStaleReviews *bool `json:"dismiss_stale_reviews,omitempty"`
@@ -1113,7 +1113,7 @@ type BranchRestrictionsRequest struct {
11131113
// The list of team slugs with push access. (Required; use []string{} instead of nil for empty list.)
11141114
Teams []string `json:"teams"`
11151115
// The list of app slugs with push access.
1116-
Apps []string `json:"apps,omitempty"`
1116+
Apps []string `json:"apps"`
11171117
}
11181118

11191119
// BypassPullRequestAllowances represents the people, teams, or apps who are allowed to bypass required pull requests.
@@ -1145,10 +1145,12 @@ type DismissalRestrictions struct {
11451145
Users []*User `json:"users"`
11461146
// The list of teams which can dismiss pull request reviews.
11471147
Teams []*Team `json:"teams"`
1148+
// The list of apps which can dismiss pull request reviews.
1149+
Apps []*App `json:"apps"`
11481150
}
11491151

11501152
// DismissalRestrictionsRequest represents the request to create/edit the
1151-
// restriction to allows only specific users or teams to dimiss pull request reviews. It is
1153+
// restriction to allows only specific users, teams or apps to dimiss pull request reviews. It is
11521154
// separate from DismissalRestrictions above because the request structure is
11531155
// different from the response structure.
11541156
// Note: Both Users and Teams must be nil, or both must be non-nil.
@@ -1157,6 +1159,8 @@ type DismissalRestrictionsRequest struct {
11571159
Users *[]string `json:"users,omitempty"`
11581160
// The list of team slugs which can dismiss pull request reviews. (Required; use nil to disable dismissal_restrictions or &[]string{} otherwise.)
11591161
Teams *[]string `json:"teams,omitempty"`
1162+
// The list of apps which can dismiss pull request reviews. (Required; use nil to disable dismissal_restrictions or &[]string{} otherwise.)
1163+
Apps *[]string `json:"apps,omitempty"`
11601164
}
11611165

11621166
// SignaturesProtectedBranch represents the protection status of an individual branch.

github/repos_test.go

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,10 @@ func TestRepositoriesService_GetBranchProtection(t *testing.T) {
10741074
"teams":[{
10751075
"id":4,
10761076
"slug":"t"
1077+
}],
1078+
"apps":[{
1079+
"id":5,
1080+
"slug":"a"
10771081
}]
10781082
},
10791083
"dismiss_stale_reviews":true,
@@ -1086,7 +1090,8 @@ func TestRepositoriesService_GetBranchProtection(t *testing.T) {
10861090
},
10871091
"restrictions":{
10881092
"users":[{"id":1,"login":"u"}],
1089-
"teams":[{"id":2,"slug":"t"}]
1093+
"teams":[{"id":2,"slug":"t"}],
1094+
"apps":[{"id":3,"slug":"a"}]
10901095
},
10911096
"required_conversation_resolution": {
10921097
"enabled": true
@@ -1119,6 +1124,9 @@ func TestRepositoriesService_GetBranchProtection(t *testing.T) {
11191124
Teams: []*Team{
11201125
{Slug: String("t"), ID: Int64(4)},
11211126
},
1127+
Apps: []*App{
1128+
{Slug: String("a"), ID: Int64(5)},
1129+
},
11221130
},
11231131
RequireCodeOwnerReviews: true,
11241132
RequiredApprovingReviewCount: 1,
@@ -1134,6 +1142,9 @@ func TestRepositoriesService_GetBranchProtection(t *testing.T) {
11341142
Teams: []*Team{
11351143
{Slug: String("t"), ID: Int64(2)},
11361144
},
1145+
Apps: []*App{
1146+
{Slug: String("a"), ID: Int64(3)},
1147+
},
11371148
},
11381149
RequiredConversationResolution: &RequiredConversationResolution{
11391150
Enabled: true,
@@ -1273,6 +1284,7 @@ func TestRepositoriesService_UpdateBranchProtection_Contexts(t *testing.T) {
12731284
DismissalRestrictionsRequest: &DismissalRestrictionsRequest{
12741285
Users: &[]string{"uu"},
12751286
Teams: &[]string{"tt"},
1287+
Apps: &[]string{"aa"},
12761288
},
12771289
BypassPullRequestAllowancesRequest: &BypassPullRequestAllowancesRequest{
12781290
Users: []string{"uuu"},
@@ -1318,6 +1330,10 @@ func TestRepositoriesService_UpdateBranchProtection_Contexts(t *testing.T) {
13181330
"teams":[{
13191331
"id":4,
13201332
"slug":"tt"
1333+
}],
1334+
"apps":[{
1335+
"id":5,
1336+
"slug":"aa"
13211337
}]
13221338
},
13231339
"dismiss_stale_reviews":true,
@@ -1361,6 +1377,9 @@ func TestRepositoriesService_UpdateBranchProtection_Contexts(t *testing.T) {
13611377
Teams: []*Team{
13621378
{Slug: String("tt"), ID: Int64(4)},
13631379
},
1380+
Apps: []*App{
1381+
{Slug: String("aa"), ID: Int64(5)},
1382+
},
13641383
},
13651384
RequireCodeOwnerReviews: true,
13661385
BypassPullRequestAllowances: &BypassPullRequestAllowances{
@@ -1424,6 +1443,7 @@ func TestRepositoriesService_UpdateBranchProtection_Checks(t *testing.T) {
14241443
DismissalRestrictionsRequest: &DismissalRestrictionsRequest{
14251444
Users: &[]string{"uu"},
14261445
Teams: &[]string{"tt"},
1446+
Apps: &[]string{"aa"},
14271447
},
14281448
BypassPullRequestAllowancesRequest: &BypassPullRequestAllowancesRequest{
14291449
Users: []string{"uuu"},
@@ -1469,6 +1489,10 @@ func TestRepositoriesService_UpdateBranchProtection_Checks(t *testing.T) {
14691489
"teams":[{
14701490
"id":4,
14711491
"slug":"tt"
1492+
}],
1493+
"apps":[{
1494+
"id":5,
1495+
"slug":"aa"
14721496
}]
14731497
},
14741498
"dismiss_stale_reviews":true,
@@ -1512,6 +1536,9 @@ func TestRepositoriesService_UpdateBranchProtection_Checks(t *testing.T) {
15121536
Teams: []*Team{
15131537
{Slug: String("tt"), ID: Int64(4)},
15141538
},
1539+
Apps: []*App{
1540+
{Slug: String("aa"), ID: Int64(5)},
1541+
},
15151542
},
15161543
RequireCodeOwnerReviews: true,
15171544
BypassPullRequestAllowances: &BypassPullRequestAllowances{
@@ -1557,6 +1584,7 @@ func TestRepositoriesService_UpdateBranchProtection_StrictNoChecks(t *testing.T)
15571584
DismissalRestrictionsRequest: &DismissalRestrictionsRequest{
15581585
Users: &[]string{"uu"},
15591586
Teams: &[]string{"tt"},
1587+
Apps: &[]string{"aa"},
15601588
},
15611589
BypassPullRequestAllowancesRequest: &BypassPullRequestAllowancesRequest{
15621590
Users: []string{"uuu"},
@@ -1597,6 +1625,10 @@ func TestRepositoriesService_UpdateBranchProtection_StrictNoChecks(t *testing.T)
15971625
"teams":[{
15981626
"id":4,
15991627
"slug":"tt"
1628+
}],
1629+
"apps":[{
1630+
"id":5,
1631+
"slug":"aa"
16001632
}]
16011633
},
16021634
"dismiss_stale_reviews":true,
@@ -1636,6 +1668,9 @@ func TestRepositoriesService_UpdateBranchProtection_StrictNoChecks(t *testing.T)
16361668
Teams: []*Team{
16371669
{Slug: String("tt"), ID: Int64(4)},
16381670
},
1671+
Apps: []*App{
1672+
{Slug: String("aa"), ID: Int64(5)},
1673+
},
16391674
},
16401675
RequireCodeOwnerReviews: true,
16411676
BypassPullRequestAllowances: &BypassPullRequestAllowances{
@@ -2088,7 +2123,8 @@ func TestRepositoriesService_GetPullRequestReviewEnforcement(t *testing.T) {
20882123
fmt.Fprintf(w, `{
20892124
"dismissal_restrictions":{
20902125
"users":[{"id":1,"login":"u"}],
2091-
"teams":[{"id":2,"slug":"t"}]
2126+
"teams":[{"id":2,"slug":"t"}],
2127+
"apps":[{"id":3,"slug":"a"}]
20922128
},
20932129
"dismiss_stale_reviews":true,
20942130
"require_code_owner_reviews":true,
@@ -2111,6 +2147,9 @@ func TestRepositoriesService_GetPullRequestReviewEnforcement(t *testing.T) {
21112147
Teams: []*Team{
21122148
{Slug: String("t"), ID: Int64(2)},
21132149
},
2150+
Apps: []*App{
2151+
{Slug: String("a"), ID: Int64(3)},
2152+
},
21142153
},
21152154
RequireCodeOwnerReviews: true,
21162155
RequiredApprovingReviewCount: 1,
@@ -2143,6 +2182,7 @@ func TestRepositoriesService_UpdatePullRequestReviewEnforcement(t *testing.T) {
21432182
DismissalRestrictionsRequest: &DismissalRestrictionsRequest{
21442183
Users: &[]string{"u"},
21452184
Teams: &[]string{"t"},
2185+
Apps: &[]string{"a"},
21462186
},
21472187
}
21482188

@@ -2159,7 +2199,8 @@ func TestRepositoriesService_UpdatePullRequestReviewEnforcement(t *testing.T) {
21592199
fmt.Fprintf(w, `{
21602200
"dismissal_restrictions":{
21612201
"users":[{"id":1,"login":"u"}],
2162-
"teams":[{"id":2,"slug":"t"}]
2202+
"teams":[{"id":2,"slug":"t"}],
2203+
"apps":[{"id":3,"slug":"a"}]
21632204
},
21642205
"dismiss_stale_reviews":true,
21652206
"require_code_owner_reviews":true,
@@ -2182,6 +2223,9 @@ func TestRepositoriesService_UpdatePullRequestReviewEnforcement(t *testing.T) {
21822223
Teams: []*Team{
21832224
{Slug: String("t"), ID: Int64(2)},
21842225
},
2226+
Apps: []*App{
2227+
{Slug: String("a"), ID: Int64(3)},
2228+
},
21852229
},
21862230
RequireCodeOwnerReviews: true,
21872231
RequiredApprovingReviewCount: 3,
@@ -2515,6 +2559,7 @@ func TestPullRequestReviewsEnforcementRequest_MarshalJSON_nilDismissalRestirctio
25152559
DismissalRestrictionsRequest: &DismissalRestrictionsRequest{
25162560
Users: &[]string{},
25172561
Teams: &[]string{},
2562+
Apps: &[]string{},
25182563
},
25192564
}
25202565

@@ -2523,7 +2568,7 @@ func TestPullRequestReviewsEnforcementRequest_MarshalJSON_nilDismissalRestirctio
25232568
t.Errorf("PullRequestReviewsEnforcementRequest.MarshalJSON returned error: %v", err)
25242569
}
25252570

2526-
want = `{"dismissal_restrictions":{"users":[],"teams":[]},"dismiss_stale_reviews":false,"require_code_owner_reviews":false,"required_approving_review_count":0}`
2571+
want = `{"dismissal_restrictions":{"users":[],"teams":[],"apps":[]},"dismiss_stale_reviews":false,"require_code_owner_reviews":false,"required_approving_review_count":0}`
25272572
if want != string(got) {
25282573
t.Errorf("PullRequestReviewsEnforcementRequest.MarshalJSON returned %+v, want %+v", string(got), want)
25292574
}

0 commit comments

Comments
 (0)