-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Allow an empty array of BypassActors in Ruleset struct in CreateRuleset endpoint #3174
Conversation
Co-authored-by: Daniel Liao <[email protected]>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #3174 +/- ##
==========================================
- Coverage 97.72% 92.92% -4.80%
==========================================
Files 153 171 +18
Lines 13390 11582 -1808
==========================================
- Hits 13085 10763 -2322
- Misses 215 726 +511
- Partials 90 93 +3 ☔ View full report in Codecov by Sentry. |
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.
It think it might be a more pleasant user experience to not introduce a new struct,
but just a new endpoint that still uses the Ruleset
struct as input, but internally uses a non-exported struct like the one you created.
To do this, you would need to copy over the fields to this non-exported struct and then send that instead of the original Ruleset.
Also, let's please not start using BPActr
as a short abbreviation for BypassActor
, as we try to make this repo as searchable as possible, and nobody is going to guess bpactr
as a search string.
Also, all new godoc-style comments should be complete sentences with ending periods. Thanks.
Do you mean something like having an anonymous struct identical to Ruleset in the new functions scope that would just copy over the values of Ruleset to? I understand your idea but i'm confused about the implementation. |
Yes, that is what I mean. We have other examples of this in our repo. Here is one of many: https://github.com/google/go-github/blob/master/github/repos.go#L546-L573 I found this by typing: $ grep 'type [a-z]' github/*.go |
made some changes. Let me know if its what you expected. |
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.
Yes, this is what I was talking about - the only difference is that the new struct should not be exported because the end-user never has know or worry about it.
Co-authored-by: Glenn Lewis <[email protected]>
Co-authored-by: Glenn Lewis <[email protected]>
Ok. I commited your suggested changes. I didn't know rulesetNoOmitBypassActors made it non exported. Learned something new about the language. Thanks! |
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.
Whups, sorry... my bad... I gave bad suggestions. Doh.
Co-authored-by: Glenn Lewis <[email protected]>
Co-authored-by: Glenn Lewis <[email protected]>
Please re-run step 4 in CONTRIBUTING.md to re-generate the auto-generated files... then the tests should all pass. |
…oBypassActor, regenerated files
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.
Thank you, @Matthew-Reidy !
LGTM.
Awaiting second LGTM+Approval from any other contributor to this repo before merging.
@@ -395,6 +395,24 @@ type Ruleset struct { | |||
Rules []*RepositoryRule `json:"rules,omitempty"` | |||
} | |||
|
|||
// rulesetNoOmitBypassActors represents a GitHub ruleset object. The struct does not omit bypassActors if the field is nil or an empty array is passed. | |||
type rulesetNoOmitBypassActors struct { |
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.
I think that you can embed the entire Ruleset
object and shadow just the bypass_actors
type rulesetNoOmitBypassActors struct {
Ruleset
BypassActors []*BypassActor `json:"bypass_actors"`
}
example: https://goplay.tools/snippet/7lHZci7LW0y
@gmlewis WDYT?
Then you can use it like so:
func (s *RepositoriesService) UpdateRulesetNoBypassActor(...rs *Ruleset...
rsNoBypassActor := &rulesetNoOmitBypassActors{}
if rs != nil {
rsNoBypassActor := &rulesetNoOmitBypassActors{Ruleset: *rs}
}
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.
Sounds great, @tomfeigin - as long as we have a unit test that demonstrates this behavior (meaning a BypassActors=nil
still gets passed through in JSON as "bypass_actors":[]
).
This would be useful for me as I'm tracking a bug in the GitHub terraform provider that I think links to #3137. @Matthew-Reidy are you planning on picking this up again? |
I can fix the spelling mistake/nit but as for the other proposed change, whats the justification? The solution in place now on this PR seems to do the same things and has testing evidence behind it. Thanks. |
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.
My comments are only relevant for styling, let's merge it
Thank you, @tomfeigin and @Matthew-Reidy ! Merging. |
This is a quirk upstream, where they introduced a new function `UpdateRulesetNoBypassActor` to work around the issue of `UpdateRuleset` not deleting BypassActors when there's an empty array. google/go-github#3174 Not sure why they decided to introduce a new function instead of just patching the original. Compatibility issues? Is there ever a use case where we need to keep BypassActors around when the non-empty list becomes an empty list?
Fixes: #3137
added an extra Ruleset struct and CreateRuleset endpoint in repo_rules.go to allow the BypassActors field to be passed as nil or an empty array