Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add apps to restriction rules in branch protection #2509

Merged
merged 2 commits into from Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions github/github-accessors.go

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

10 changes: 10 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.

16 changes: 10 additions & 6 deletions github/repos.go
Expand Up @@ -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"`
Expand All @@ -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)
Expand All @@ -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"`
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down
53 changes: 49 additions & 4 deletions github/repos_test.go
Expand Up @@ -1074,6 +1074,10 @@ func TestRepositoriesService_GetBranchProtection(t *testing.T) {
"teams":[{
"id":4,
"slug":"t"
}],
"apps":[{
"id":5,
"slug":"a"
}]
},
"dismiss_stale_reviews":true,
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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"},
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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"},
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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"},
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -2143,6 +2182,7 @@ func TestRepositoriesService_UpdatePullRequestReviewEnforcement(t *testing.T) {
DismissalRestrictionsRequest: &DismissalRestrictionsRequest{
Users: &[]string{"u"},
Teams: &[]string{"t"},
Apps: &[]string{"a"},
},
}

Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -2515,6 +2559,7 @@ func TestPullRequestReviewsEnforcementRequest_MarshalJSON_nilDismissalRestirctio
DismissalRestrictionsRequest: &DismissalRestrictionsRequest{
Users: &[]string{},
Teams: &[]string{},
Apps: &[]string{},
},
}

Expand All @@ -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)
}
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Expand Up @@ -9,7 +9,9 @@ require (

require (
github.com/golang/protobuf v1.3.2 // indirect
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 // indirect
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
jporzucek marked this conversation as resolved.
Show resolved Hide resolved
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect
golang.org/x/tools v0.1.12 // indirect
google.golang.org/appengine v1.6.7 // indirect
)

Expand Down
14 changes: 14 additions & 0 deletions go.sum
Expand Up @@ -7,21 +7,35 @@ github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeN
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
jporzucek marked this conversation as resolved.
Show resolved Hide resolved
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ=
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug=
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 h1:qWPm9rbaAMKs8Bq/9LRpbMqxWRVUAQwMI9fVrssnTfw=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b h1:PxfKdU9lEEDYjdIzOtC4qFWgkU2rGHdKlKowJSMN9h0=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be h1:vEDujvNQGv4jgYKudGeI/+DAX4Jffq6hpD55MmoEvKs=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c=
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=