-
Notifications
You must be signed in to change notification settings - Fork 763
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
Adding BypassPullRequestActorIDs to branch protection #1030
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,13 @@ type DismissalActorTypes struct { | |
} | ||
} | ||
|
||
type BypassPullRequestActorTypes struct { | ||
Actor struct { | ||
Team Actor `graphql:"... on Team"` | ||
User Actor `graphql:"... on User"` | ||
} | ||
} | ||
|
||
type PushActorTypes struct { | ||
Actor struct { | ||
App Actor `graphql:"... on App"` | ||
|
@@ -39,6 +46,9 @@ type BranchProtectionRule struct { | |
ReviewDismissalAllowances struct { | ||
Nodes []DismissalActorTypes | ||
} `graphql:"reviewDismissalAllowances(first: 100)"` | ||
BypassPullRequestAllowances struct { | ||
Nodes []BypassPullRequestActorTypes | ||
} `graphql:"bypassPullRequestAllowances(first: 100)"` | ||
AllowsDeletions githubv4.Boolean | ||
AllowsForcePushes githubv4.Boolean | ||
DismissesStaleReviews githubv4.Boolean | ||
|
@@ -62,6 +72,7 @@ type BranchProtectionResourceData struct { | |
AllowsDeletions bool | ||
AllowsForcePushes bool | ||
BranchProtectionRuleID string | ||
BypassPullRequestActorIDs []string | ||
DismissesStaleReviews bool | ||
IsAdminEnforced bool | ||
Pattern string | ||
|
@@ -157,6 +168,16 @@ func branchProtectionResourceData(d *schema.ResourceData, meta interface{}) (Bra | |
data.RestrictsReviewDismissals = true | ||
} | ||
} | ||
if v, ok := m[PROTECTION_PULL_REQUESTS_BYPASSERS]; ok { | ||
bypassPullRequestActorIDs := make([]string, 0) | ||
vL := v.(*schema.Set).List() | ||
for _, v := range vL { | ||
bypassPullRequestActorIDs = append(bypassPullRequestActorIDs, v.(string)) | ||
} | ||
if len(bypassPullRequestActorIDs) > 0 { | ||
data.BypassPullRequestActorIDs = bypassPullRequestActorIDs | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
@@ -210,6 +231,20 @@ func setDismissalActorIDs(actors []DismissalActorTypes) []string { | |
return pushActors | ||
} | ||
|
||
func setBypassPullRequestActorIDs(actors []BypassPullRequestActorTypes) []string { | ||
bypassActors := make([]string, 0, len(actors)) | ||
for _, a := range actors { | ||
if a.Actor.Team != (Actor{}) { | ||
bypassActors = append(bypassActors, a.Actor.Team.ID.(string)) | ||
} | ||
if a.Actor.User != (Actor{}) { | ||
bypassActors = append(bypassActors, a.Actor.User.ID.(string)) | ||
} | ||
Comment on lines
+237
to
+242
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mind explaining this logic to me a little more? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logic is the same like in the case of |
||
} | ||
|
||
return bypassActors | ||
} | ||
|
||
func setPushActorIDs(actors []PushActorTypes) []string { | ||
pushActors := make([]string, 0, len(actors)) | ||
for _, a := range actors { | ||
|
@@ -234,13 +269,16 @@ func setApprovingReviews(protection BranchProtectionRule) interface{} { | |
|
||
dismissalAllowances := protection.ReviewDismissalAllowances.Nodes | ||
dismissalActors := setDismissalActorIDs(dismissalAllowances) | ||
bypassPullRequestAllowances := protection.BypassPullRequestAllowances.Nodes | ||
bypassPullRequestActors := setBypassPullRequestActorIDs(bypassPullRequestAllowances) | ||
approvalReviews := []interface{}{ | ||
map[string]interface{}{ | ||
PROTECTION_REQUIRED_APPROVING_REVIEW_COUNT: protection.RequiredApprovingReviewCount, | ||
PROTECTION_REQUIRES_CODE_OWNER_REVIEWS: protection.RequiresCodeOwnerReviews, | ||
PROTECTION_DISMISSES_STALE_REVIEWS: protection.DismissesStaleReviews, | ||
PROTECTION_RESTRICTS_REVIEW_DISMISSALS: protection.RestrictsReviewDismissals, | ||
PROTECTION_RESTRICTS_REVIEW_DISMISSERS: dismissalActors, | ||
PROTECTION_PULL_REQUESTS_BYPASSERS: bypassPullRequestActors, | ||
}, | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is "Empty" in the name here? It looks like the function is a translation between a string slice and a githubv4.ID slice, and I'm not quite understanding how Empty fits in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I remember it correctly, I had to add this here so we can set the list of
pull_request_bypassers
to empty list:Without this we cannot remove all bypassers if any were set before.
I didn't want to make changes to the
githubv4IDSlice
for the case some other logic would break so I added this new function. If you feel the function should be called differently, plese suggest a new name and I will amend it.