-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
fix: validate period flag #67
Conversation
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.
PR Compliance Checks
Thank you for your Pull Request! We have run several checks on this pull request in order to make sure it's suitable for merging into this project. The results are listed in the following section.
Issue Reference
In order to be considered for merging, the pull request description must refer to a specific issue number. This is described in our Contributing Guide.
This check is looking for a phrase similar to: "Fixes #XYZ" or "Resolves #XYZ" where XYZ is the issue number that this PR is meant to address.
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.
Looks great @k1nho! One non-blocking suggestion.
pkg/api/validation.go
Outdated
if period == 7 || period == 30 || period == 90 { | ||
return true | ||
} | ||
return false |
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.
refactor (non-blocking): No need for an explicit return of true or false unless this a preferred pattern in Go (I'm not a Gopher 😅)
if period == 7 || period == 30 || period == 90 { | |
return true | |
} | |
return false | |
return period == 7 || period == 30 || period == 90 |
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.
Not a pattern, might be a side effect from too much if err != nil
😂
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.
return period == 7 || period == 30 || period == 90
is valid Go and it really comes down to personal preference: there will be people who say this is a prime use case for a switch
in Go in order to reduce the boolean mind games someone reading your code might need to do to figure out what's going on. Like:
switch range {
case 7:
return true
case 30:
return true
case 90:
return true
default:
// invalid range
return false
}
but others would say that's too verbose and ends up being crufty 🤷🏼
Anywho, I'm good with what's written here and makes sense to me!
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.
there will be people who say this is a prime use case for a switch in Go in order to reduce the boolean mind games
true, there is also this way with the switch.
switch range {
case 7,30,90:
return true
default:
// invalid range
return false
}
There is always the even-odd check meme way of doing it as well xD
ba87ce9
to
4202355
Compare
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.
Looks great! just one small suggestion!! Thanks for this - and thanks for your patience: I've been heads down on abunch of stuff the last few weeks!
pkg/api/validation.go
Outdated
@@ -0,0 +1,5 @@ | |||
package api | |||
|
|||
func ValidateRange(period int32) bool { |
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.
Since this is a boolean function, can we rename this IsValidRange
?
That typically reads better:
if !api.IsValidRange(opts.Period)
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.
thanks for the feedback!
4202355
to
4d8ab7f
Compare
Description
This PR adds a range validation to the
insights contributors
command. It will check for the value of the period flag. In case the period provided is invalid, it returns a descriptive error to signal that the API only accepts (7,30,90) as period values.Before
Now
What type of PR is this? (check all applicable)
Related Tickets & Documents
#66 --period flag broken
Mobile & Desktop Screenshots/Recordings
Added tests?
Added to documentation?
[optional] Are there any post-deployment tasks we need to perform?
[optional] What gif best describes this PR or how it makes you feel?