-
Notifications
You must be signed in to change notification settings - Fork 275
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
Prevent pushing with empty Label/Tag names #2780
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.
lgtm!
for _, tag := range flags.Tags { | ||
if tag == "" { | ||
return appcmd.NewInvalidArgumentErrorf( | ||
"%s|--%s requires a non-empty string.", |
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.
drive by, but should the short flag have a -
in front?
"%s|--%s requires a non-empty string.", | |
"-%s|--%s requires a non-empty string.", |
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.
Ah I x
'd that by accident. Let me push that up.
)..., | ||
), | ||
) | ||
labels := make([]string, 0, len(flags.Labels)+len(flags.Tags)) |
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 not continue to use previous style, labels := append(flag.Labels, flags.Tags...)
?
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.
append
can mutate the underlying array of its first argument (flag.Label
). It shouldn't matter in this case because we're not overwriting indexes, but in general I avoid using append
to copy a slice I don't own. Happy to change this back if you think it's a non-issue.
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.
Well every day's a school day I guess, I don't know how I've gone this long without running into some bug based on this. Sounds good. A slight nit, I might clean it up to append(slicesext.Copy(flags.Labels), flags.Tags...)
but doesn't matter much.
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 cleaned it up using slicesext.Copy
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.
@akshayjshah on my case about how could I be so naive
for _, tag := range flags.Tags { | ||
if tag == "" { | ||
return appcmd.NewInvalidArgumentErrorf( | ||
"-%s|--%s requires a non-empty string.", |
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.
All other usages of appcmd.NewInvalidArgumentErrorf
(save one) in the codebase do not display short names, and do not use punctuation - update to --%s requires a non-empty string
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.
Done!
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.
Did you want me to remove the trailing period on the errors returned by validateCreateFlags
?
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.
Yea for sure, that was a miss on my part
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.
Done!
return nil | ||
} | ||
|
||
func validateLabelFlags(flags *flags) error { |
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.
Put below validateCreateFlags
since this is the call order and it is more natural
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.
Done!
func validateLabelFlags(flags *flags) error { | ||
for _, label := range flags.Labels { | ||
if label == "" { | ||
return appcmd.NewInvalidArgumentErrorf( |
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.
No need for newlines
} | ||
for _, tag := range flags.Tags { | ||
if tag == "" { | ||
return appcmd.NewInvalidArgumentErrorf( |
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.
No need for newlines
flags.Draft
andflags.Branch
may be empty string, and they were being added to the labels name. Instead, I conditionally add them.I also chose to detect empty strings in
flags.Labels
andflags.Tags
, via--label ''
or--tag ''
.