Skip to content

Commit 4987cf7

Browse files
authored
Fix field_option_name to pass option name to REST API, not DB ID - return minimal fields
1 parent 7561ca4 commit 4987cf7

3 files changed

Lines changed: 21 additions & 13 deletions

File tree

pkg/github/__toolsnaps__/issue_write.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,19 @@
3030
"type": "number"
3131
},
3232
"issue_fields": {
33-
"description": "Issue field values to set. Each item requires field_name and either value or field_option_name. field_option_name is for single-select fields and is resolved to the corresponding option ID automatically.",
33+
"description": "Issue field values to set. Each item requires 'field_name' and either 'value' or 'field_option_name'. Use 'field_option_name' for single-select fields to validate the option exists.",
3434
"items": {
3535
"properties": {
3636
"field_name": {
3737
"description": "Issue field name",
3838
"type": "string"
3939
},
4040
"field_option_name": {
41-
"description": "Single-select option name to resolve and set for the field",
41+
"description": "Single-select option name (validates option exists before setting)",
4242
"type": "string"
4343
},
4444
"value": {
45-
"description": "Value for text/number/date/single-select fields. For single-select, you can use field_option_name instead."
45+
"description": "Value for text/number/date/single-select fields"
4646
}
4747
},
4848
"required": [

pkg/github/issues.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -329,11 +329,8 @@ func resolveIssueRequestFieldValues(ctx context.Context, gqlClient *githubv4.Cli
329329
optionFound := false
330330
for _, option := range node.IssueFieldSingleSelect.Options {
331331
if strings.EqualFold(strings.TrimSpace(string(option.Name)), strings.TrimSpace(fieldInput.FieldOptionName)) {
332-
optionID := parseFullDatabaseID(string(option.FullDatabaseID))
333-
if optionID == 0 {
334-
return nil, fmt.Errorf("issue field option %q on field %q is missing fullDatabaseId", fieldInput.FieldOptionName, fieldInput.FieldName)
335-
}
336-
resolvedValue = optionID
332+
// REST API expects the option name, not the ID
333+
resolvedValue = string(option.Name)
337334
optionFound = true
338335
break
339336
}
@@ -762,6 +759,17 @@ func GetIssue(ctx context.Context, client *github.Client, deps ToolDependencies,
762759

763760
minimalIssue := convertToMinimalIssue(issue)
764761

762+
// Enrich with field_values via GraphQL for consistency with list_issues/search_issues
763+
if issue != nil && issue.NodeID != nil && *issue.NodeID != "" {
764+
gqlClient, err := deps.GetGQLClient(ctx)
765+
if err == nil {
766+
if fieldValuesByID, err := fetchIssueFieldValuesByNodeID(ctx, gqlClient, []*github.Issue{issue}); err == nil {
767+
minimalIssue.FieldValues = fieldValuesByID[*issue.NodeID]
768+
minimalIssue.IssueFieldValues = nil // Clear verbose REST format
769+
}
770+
}
771+
}
772+
765773
return MarshalledTextResult(minimalIssue), nil
766774
}
767775

@@ -1711,7 +1719,7 @@ Options are:
17111719
},
17121720
"issue_fields": {
17131721
Type: "array",
1714-
Description: "Issue field values to set. Each item requires field_name and either value or field_option_name. field_option_name is for single-select fields and is resolved to the corresponding option ID automatically.",
1722+
Description: "Issue field values to set. Each item requires 'field_name' and either 'value' or 'field_option_name'. Use 'field_option_name' for single-select fields to validate the option exists.",
17151723
Items: &jsonschema.Schema{
17161724
Type: "object",
17171725
Properties: map[string]*jsonschema.Schema{
@@ -1720,11 +1728,11 @@ Options are:
17201728
Description: "Issue field name",
17211729
},
17221730
"value": {
1723-
Description: "Value for text/number/date/single-select fields. For single-select, you can use field_option_name instead.",
1731+
Description: "Value for text/number/date/single-select fields",
17241732
},
17251733
"field_option_name": {
17261734
Type: "string",
1727-
Description: "Single-select option name to resolve and set for the field",
1735+
Description: "Single-select option name (validates option exists before setting)",
17281736
},
17291737
},
17301738
Required: []string{"field_name"},

pkg/github/issues_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,7 @@ func Test_CreateIssue(t *testing.T) {
12991299
"labels": []any{},
13001300
"assignees": []any{},
13011301
"issue_field_values": []any{
1302-
map[string]any{"field_id": float64(101), "value": float64(9001)},
1302+
map[string]any{"field_id": float64(101), "value": "P1"},
13031303
map[string]any{"field_id": float64(102), "value": "Acme"},
13041304
},
13051305
}).andThen(
@@ -2768,7 +2768,7 @@ func Test_UpdateIssue(t *testing.T) {
27682768
mockedRESTClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
27692769
PatchReposIssuesByOwnerByRepoByIssueNumber: expectRequestBody(t, map[string]any{
27702770
"issue_field_values": []any{
2771-
map[string]any{"field_id": float64(101), "value": float64(9001)},
2771+
map[string]any{"field_id": float64(101), "value": "P1"},
27722772
map[string]any{"field_id": float64(102), "value": "Acme"},
27732773
},
27742774
"title": "Updated Title",

0 commit comments

Comments
 (0)