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

Prevent pushing with empty Label/Tag names #2780

Merged
merged 7 commits into from
Feb 21, 2024

Conversation

saquibmian
Copy link
Contributor

flags.Draft and flags.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 and flags.Tags, via --label '' or --tag ''.

Copy link
Member

@unmultimedio unmultimedio left a 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.",
Copy link
Member

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?

Suggested change
"%s|--%s requires a non-empty string.",
"-%s|--%s requires a non-empty string.",

Copy link
Contributor Author

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))
Copy link
Member

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...)?

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

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.",
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

Copy link
Contributor Author

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?

Copy link
Member

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

Copy link
Contributor Author

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 {
Copy link
Member

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

Copy link
Contributor Author

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(
Copy link
Member

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(
Copy link
Member

Choose a reason for hiding this comment

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

No need for newlines

@bufdev bufdev merged commit c1fa381 into bufmod Feb 21, 2024
4 of 8 checks passed
@bufdev bufdev deleted the smian/fix-push-with-empty-label branch February 21, 2024 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants