-
Notifications
You must be signed in to change notification settings - Fork 4k
Enforce exactly one value key per field in set_issue_fields #2339
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -731,41 +731,44 @@ func GranularSetIssueFields(t translations.TranslationHelperFunc) inventory.Serv | |
| FieldID: githubv4.ID(fieldID), | ||
| } | ||
|
|
||
| // Check for exactly one value type (or delete) | ||
| hasValue := false | ||
| // Count how many value keys are present; exactly one is required. | ||
| valueCount := 0 | ||
|
|
||
| if v, err := OptionalParam[string](fieldMap, "text_value"); err == nil && v != "" { | ||
| input.TextValue = githubv4.NewString(githubv4.String(v)) | ||
| hasValue = true | ||
| valueCount++ | ||
| } | ||
| if v, err := OptionalParam[float64](fieldMap, "number_value"); err == nil { | ||
| if _, exists := fieldMap["number_value"]; exists { | ||
| gqlFloat := githubv4.Float(v) | ||
| input.NumberValue = &gqlFloat | ||
| hasValue = true | ||
| valueCount++ | ||
| } | ||
| } | ||
| if v, err := OptionalParam[string](fieldMap, "date_value"); err == nil && v != "" { | ||
| input.DateValue = githubv4.NewString(githubv4.String(v)) | ||
| hasValue = true | ||
| valueCount++ | ||
| } | ||
| if v, err := OptionalParam[string](fieldMap, "single_select_option_id"); err == nil && v != "" { | ||
| optionID := githubv4.ID(v) | ||
| input.SingleSelectOptionID = &optionID | ||
| hasValue = true | ||
| valueCount++ | ||
| } | ||
| if _, exists := fieldMap["delete"]; exists { | ||
| del, err := OptionalParam[bool](fieldMap, "delete") | ||
| if err == nil && del { | ||
| deleteVal := githubv4.Boolean(true) | ||
| input.Delete = &deleteVal | ||
| hasValue = true | ||
| valueCount++ | ||
| } | ||
|
Comment on lines
+734
to
763
|
||
| } | ||
|
|
||
| if !hasValue { | ||
| if valueCount == 0 { | ||
| return utils.NewToolResultError("each field must have a value (text_value, number_value, date_value, single_select_option_id) or delete: true"), nil, nil | ||
| } | ||
| if valueCount > 1 { | ||
| return utils.NewToolResultError("each field must have exactly one value (text_value, number_value, date_value, single_select_option_id) or delete: true, but multiple were provided"), nil, nil | ||
| } | ||
|
|
||
| issueFields = append(issueFields, input) | ||
| } | ||
|
|
||
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.
The new tests cover multiple valid value keys, but they don’t cover cases where a second value key is present but invalid/empty (which currently won’t increment
valueCountand therefore won’t trigger the “exactly one value” error). Adding a test liketext_value:"hello"+number_value:"42"(string) and/ortext_value:""+number_value:42would catch this and protect the stricter validation behavior described in the PR.