Skip to content

Conversation

@nghialv
Copy link
Member

@nghialv nghialv commented Jan 13, 2021

What this PR does / why we need it:

Which issue(s) this PR fixes:

Fixes #1393

Does this PR introduce a user-facing change?:

NONE

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 34.09%. This pull request does not change code coverage.

@khanhtc1202
Copy link
Member

/lgtm

message RegisterEventRequest {
string name = 1 [(validate.rules).string.min_len = 1];
string data = 2 [(validate.rules).string.min_len = 1];
map<string,string> labels = 3 [(validate.rules).map.keys.string.min_len = 1, (validate.rules).map.values.string.min_len = 1];
Copy link
Member

Choose a reason for hiding this comment

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

This validates just there is no empty value for a key? I just want to know this fails if no labels set. Sorry I'm lazy I didn't read the documentation for the validate.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. No labels case is fine. This checks against the empty string of the key, value.

Copy link
Member Author

Choose a reason for hiding this comment

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

In case you want to know the generated code

/ Validate checks the field values on RegisterEventRequest with the rules
// defined in the proto definition for this message. If any rules are
// violated, an error is returned.
func (m *RegisterEventRequest) Validate() error {
        if m == nil {
                return nil
        }

        if utf8.RuneCountInString(m.GetName()) < 1 {
                return RegisterEventRequestValidationError{
                        field:  "Name",
                        reason: "value length must be at least 1 runes",
                }
        }

        if utf8.RuneCountInString(m.GetData()) < 1 {
                return RegisterEventRequestValidationError{
                        field:  "Data",
                        reason: "value length must be at least 1 runes",
                }
        }

        for key, val := range m.GetLabels() {
                _ = val

                if utf8.RuneCountInString(key) < 1 {
                        return RegisterEventRequestValidationError{
                                field:  fmt.Sprintf("Labels[%v]", key),
                                reason: "value length must be at least 1 runes",
                        }
                }

                if utf8.RuneCountInString(val) < 1 {
                        return RegisterEventRequestValidationError{
                                field:  fmt.Sprintf("Labels[%v]", key),
                                reason: "value length must be at least 1 runes",
                        }
                }

        }

        return nil
}

Copy link
Member

Choose a reason for hiding this comment

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

That more makes sense! This generated code tell me how it works completely.

cmd.Flags().StringVar(&r.name, "name", r.name, "The name of event.")
cmd.Flags().StringVar(&r.data, "data", r.data, "The string value of event data.")
// TODO: Allow specifying event labels.
cmd.Flags().StringToStringVar(&r.labels, "labels", r.labels, "The list of labels for event. Format: key=value,key2=value2 .")
Copy link
Member

Choose a reason for hiding this comment

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

nit: In that case, I feel like the period at the end of a sentence is unneeded.

Copy link
Member

Choose a reason for hiding this comment

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

😄

Copy link
Member Author

Choose a reason for hiding this comment

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

ww. Sure.

@pipecd-bot pipecd-bot removed the lgtm label Jan 13, 2021
@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 34.09%. This pull request does not change code coverage.

@nakabonne
Copy link
Member

Thank you!
/approve

@pipecd-bot
Copy link
Collaborator

APPROVE

This pull request is APPROVED by nakabonne.

Approvers can cancel the approval by writing /approve cancel in a comment. Any additional commits also will change this pull request to be not-approved.

@pipecd-bot pipecd-bot merged commit f89df1a into master Jan 13, 2021
@pipecd-bot pipecd-bot deleted the pipectl-labels branch January 13, 2021 07:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow specifying event labels.

5 participants