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

Allow an empty array of BypassActors in Ruleset struct in CreateRuleset endpoint #3174

Open
wants to merge 20 commits into
base: master
Choose a base branch
from

Conversation

Matthew-Reidy
Copy link
Contributor

@Matthew-Reidy Matthew-Reidy commented May 22, 2024

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

Copy link

codecov bot commented May 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.95%. Comparing base (2b8c7fa) to head (1f7c1ef).
Report is 66 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3174      +/-   ##
==========================================
- Coverage   97.72%   92.95%   -4.77%     
==========================================
  Files         153      171      +18     
  Lines       13390    11566    -1824     
==========================================
- Hits        13085    10751    -2334     
- Misses        215      724     +509     
- Partials       90       91       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@gmlewis gmlewis left a 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.

@Matthew-Reidy
Copy link
Contributor Author

Matthew-Reidy commented May 23, 2024

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.

@gmlewis
Copy link
Collaborator

gmlewis commented May 23, 2024

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

@Matthew-Reidy
Copy link
Contributor Author

Matthew-Reidy commented May 30, 2024

made some changes. Let me know if its what you expected.

Copy link
Collaborator

@gmlewis gmlewis left a 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.

github/repos_rules.go Outdated Show resolved Hide resolved
github/repos_rules.go Outdated Show resolved Hide resolved
Matthew-Reidy and others added 2 commits May 30, 2024 12:59
@Matthew-Reidy
Copy link
Contributor Author

Ok. I commited your suggested changes. I didn't know rulesetNoOmitBypassActors made it non exported. Learned something new about the language. Thanks!

Copy link
Collaborator

@gmlewis gmlewis left a 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.

github/repos_rules.go Outdated Show resolved Hide resolved
github/repos_rules.go Outdated Show resolved Hide resolved
@gmlewis
Copy link
Collaborator

gmlewis commented May 30, 2024

Please re-run step 4 in CONTRIBUTING.md to re-generate the auto-generated files... then the tests should all pass.
You can also test locally before you push by running go test ./...

Copy link
Collaborator

@gmlewis gmlewis left a 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.

@gmlewis gmlewis added the NeedsReview PR is awaiting a review before merging. label May 30, 2024
@@ -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 {
Copy link
Contributor

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}
   }

Copy link
Collaborator

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":[].

@@ -507,6 +525,48 @@ func (s *RepositoriesService) UpdateRuleset(ctx context.Context, owner, repo str
return ruleset, resp, nil
}

// UpdateRulesetNoBypassActor updates a ruleset for the specified repository.
//
// This function is necessary as the UpdateRuleset function does not marschall ByPassActor if passed as nil or an empty array.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: marschall -> marshal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsReview PR is awaiting a review before merging.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't remove repository ruleset's every Bypass Actors because of serialization issue
3 participants