-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Add per-label is_suggestion and rationale to issue_write #2656
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
Open
iulia-b
wants to merge
5
commits into
main
Choose a base branch
from
iunia/rationale-issue-write-labels
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
da7b15d
Add per-label is_suggestion and rationale to issue_write
iulia-b b1cd28c
Add confidence and reusable value-intent helper for issue_write labels
iulia-b f84a67c
Migrate update_issue_labels to shared parseValueIntent helper
iulia-b 755b351
make the parser fully agnostic of type
iulia-b 2b1ba6f
Potential fix for pull request finding
iulia-b File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1858,7 +1858,19 @@ Options are: | |
| Type: "array", | ||
| Description: "Labels to apply to this issue", | ||
| Items: &jsonschema.Schema{ | ||
|
Comment on lines
1858
to
1860
|
||
| Type: "string", | ||
| OneOf: []*jsonschema.Schema{ | ||
| {Type: "string", Description: "Label name"}, | ||
| { | ||
| Type: "object", | ||
| Properties: withIntentProperties(map[string]*jsonschema.Schema{ | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @boazreicher @alondahari , I extracted the parser and also the intent related props in their own type, and using it to extend labels (and soon, types and field values) ; also using this in the |
||
| "name": { | ||
| Type: "string", | ||
| Description: "Label name", | ||
| }, | ||
| }), | ||
| Required: []string{"name"}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| "milestone": { | ||
|
|
@@ -1975,13 +1987,11 @@ Options are: | |
| assigneesValue, assigneesProvided := args["assignees"] | ||
| assigneesProvided = assigneesProvided && assigneesValue != nil | ||
|
|
||
| // Get labels | ||
| labels, err := OptionalStringArrayParam(args, "labels") | ||
| // Get labels (plain names or per-label intent objects) | ||
| labels, labelsPayload, labelsHaveIntent, labelsProvided, err := parseParamWithIntent(args, "labels", "name") | ||
| if err != nil { | ||
| return utils.NewToolResultError(err.Error()), nil, nil | ||
| } | ||
| labelsValue, labelsProvided := args["labels"] | ||
| labelsProvided = labelsProvided && labelsValue != nil | ||
|
|
||
| // Get optional milestone | ||
| milestone, err := OptionalIntParam(args, "milestone") | ||
|
|
@@ -2053,10 +2063,14 @@ Options are: | |
| if err != nil { | ||
| return utils.NewToolResultError(err.Error()), nil, nil | ||
| } | ||
| result, err := UpdateIssue(ctx, client, gqlClient, owner, repo, issueNumber, title, body, assignees, labels, milestoneNum, issueType, issueFieldValues, fieldIDsToDelete, state, stateReason, duplicateOf, UpdateIssueOptions{ | ||
| updateOpts := UpdateIssueOptions{ | ||
| AssigneesProvided: assigneesProvided, | ||
| LabelsProvided: labelsProvided, | ||
| }) | ||
| } | ||
| if labelsHaveIntent { | ||
| updateOpts.LabelsWithIntent = labelsPayload | ||
| } | ||
| result, err := UpdateIssue(ctx, client, gqlClient, owner, repo, issueNumber, title, body, assignees, labels, milestoneNum, issueType, issueFieldValues, fieldIDsToDelete, state, stateReason, duplicateOf, updateOpts) | ||
| return result, nil, err | ||
| default: | ||
| return utils.NewToolResultError("invalid method, must be either 'create' or 'update'"), nil, nil | ||
|
|
@@ -2132,7 +2146,19 @@ Options are: | |
| Type: "array", | ||
| Description: "Labels to apply to this issue", | ||
| Items: &jsonschema.Schema{ | ||
|
Comment on lines
2146
to
2148
|
||
| Type: "string", | ||
| OneOf: []*jsonschema.Schema{ | ||
| {Type: "string", Description: "Label name"}, | ||
| { | ||
| Type: "object", | ||
| Properties: withIntentProperties(map[string]*jsonschema.Schema{ | ||
| "name": { | ||
| Type: "string", | ||
| Description: "Label name", | ||
| }, | ||
| }), | ||
| Required: []string{"name"}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| "milestone": { | ||
|
|
@@ -2214,13 +2240,11 @@ Options are: | |
| assigneesValue, assigneesProvided := args["assignees"] | ||
| assigneesProvided = assigneesProvided && assigneesValue != nil | ||
|
|
||
| // Get labels | ||
| labels, err := OptionalStringArrayParam(args, "labels") | ||
| // Get labels (plain names or per-label intent objects) | ||
| labels, labelsPayload, labelsHaveIntent, labelsProvided, err := parseParamWithIntent(args, "labels", "name") | ||
| if err != nil { | ||
| return utils.NewToolResultError(err.Error()), nil, nil | ||
| } | ||
| labelsValue, labelsProvided := args["labels"] | ||
| labelsProvided = labelsProvided && labelsValue != nil | ||
|
|
||
| // Get optional milestone | ||
| milestone, err := OptionalIntParam(args, "milestone") | ||
|
|
@@ -2277,10 +2301,14 @@ Options are: | |
| if err != nil { | ||
| return utils.NewToolResultError(err.Error()), nil, nil | ||
| } | ||
| result, err := UpdateIssue(ctx, client, gqlClient, owner, repo, issueNumber, title, body, assignees, labels, milestoneNum, issueType, nil, nil, state, stateReason, duplicateOf, UpdateIssueOptions{ | ||
| updateOpts := UpdateIssueOptions{ | ||
| AssigneesProvided: assigneesProvided, | ||
| LabelsProvided: labelsProvided, | ||
| }) | ||
| } | ||
| if labelsHaveIntent { | ||
| updateOpts.LabelsWithIntent = labelsPayload | ||
| } | ||
| result, err := UpdateIssue(ctx, client, gqlClient, owner, repo, issueNumber, title, body, assignees, labels, milestoneNum, issueType, nil, nil, state, stateReason, duplicateOf, updateOpts) | ||
| return result, nil, err | ||
| default: | ||
| return utils.NewToolResultError("invalid method, must be either 'create' or 'update'"), nil, nil | ||
|
|
@@ -2350,6 +2378,30 @@ type UpdateIssueOptions struct { | |
| AssigneesProvided bool | ||
| // LabelsProvided sends the labels field even when the slice is empty. | ||
| LabelsProvided bool | ||
| // LabelsWithIntent, when non-empty, sends labels in object form (a mix of | ||
| // plain label names and valueWithIntent objects) via a custom request so | ||
| // per-label rationale and suggestion intent are preserved. When set, it | ||
| // takes precedence over the labels slice. | ||
| LabelsWithIntent []any | ||
| } | ||
|
|
||
| // issueRequestWithLabels marshals an IssueRequest into a generic map and sets | ||
| // the labels field to the provided object-form payload (a mix of plain label | ||
| // names and valueWithIntent objects). This lets an issue update carry per-label | ||
| // rationale and suggestion intent that github.IssueRequest cannot represent. | ||
| func issueRequestWithLabels(issueRequest *github.IssueRequest, labels []any) (map[string]any, error) { | ||
| data, err := json.Marshal(issueRequest) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| payload := map[string]any{} | ||
| dec := json.NewDecoder(strings.NewReader(string(data))) | ||
| dec.UseNumber() | ||
| if err := dec.Decode(&payload); err != nil { | ||
| return nil, err | ||
| } | ||
| payload["labels"] = labels | ||
| return payload, nil | ||
| } | ||
|
Copilot marked this conversation as resolved.
|
||
|
|
||
| func UpdateIssue(ctx context.Context, client *github.Client, gqlClient *githubv4.Client, owner string, repo string, issueNumber int, title string, body string, assignees []string, labels []string, milestoneNum int, issueType string, issueFieldValues []*github.IssueRequestFieldValue, fieldIDsToDelete []int64, state string, stateReason string, duplicateOf int, opts ...UpdateIssueOptions) (*mcp.CallToolResult, error) { | ||
|
|
@@ -2360,6 +2412,9 @@ func UpdateIssue(ctx context.Context, client *github.Client, gqlClient *githubv4 | |
| for _, opt := range opts { | ||
| updateOptions.AssigneesProvided = updateOptions.AssigneesProvided || opt.AssigneesProvided | ||
| updateOptions.LabelsProvided = updateOptions.LabelsProvided || opt.LabelsProvided | ||
| if len(opt.LabelsWithIntent) > 0 { | ||
| updateOptions.LabelsWithIntent = opt.LabelsWithIntent | ||
| } | ||
| } | ||
|
|
||
| // Create the issue request with only provided fields | ||
|
|
@@ -2374,7 +2429,9 @@ func UpdateIssue(ctx context.Context, client *github.Client, gqlClient *githubv4 | |
| issueRequest.Body = github.Ptr(body) | ||
| } | ||
|
|
||
| if updateOptions.LabelsProvided { | ||
| // When labels carry per-label intent, they are sent via a custom request | ||
| // below instead of through issueRequest.Labels. | ||
| if updateOptions.LabelsProvided && len(updateOptions.LabelsWithIntent) == 0 { | ||
| issueRequest.Labels = &labels | ||
| } | ||
|
|
||
|
|
@@ -2415,7 +2472,27 @@ func UpdateIssue(ctx context.Context, client *github.Client, gqlClient *githubv4 | |
| issueRequest.IssueFieldValues = merged | ||
| } | ||
|
|
||
| updatedIssue, resp, err := client.Issues.Edit(ctx, owner, repo, issueNumber, issueRequest) | ||
| var updatedIssue *github.Issue | ||
| var resp *github.Response | ||
| var err error | ||
| if len(updateOptions.LabelsWithIntent) > 0 { | ||
| // Send labels in object form so per-label rationale and suggestion intent | ||
| // are preserved. Marshal the standard request (labels omitted), then inject | ||
| // the object-form labels into the payload. | ||
| payload, mErr := issueRequestWithLabels(issueRequest, updateOptions.LabelsWithIntent) | ||
| if mErr != nil { | ||
| return utils.NewToolResultErrorFromErr("failed to build issue update request", mErr), nil | ||
| } | ||
| apiURL := fmt.Sprintf("repos/%s/%s/issues/%d", owner, repo, issueNumber) | ||
| httpReq, rErr := client.NewRequest(ctx, "PATCH", apiURL, payload) | ||
| if rErr != nil { | ||
| return utils.NewToolResultErrorFromErr("failed to create request", rErr), nil | ||
| } | ||
| updatedIssue = &github.Issue{} | ||
| resp, err = client.Do(httpReq, updatedIssue) | ||
| } else { | ||
| updatedIssue, resp, err = client.Issues.Edit(ctx, owner, repo, issueNumber, issueRequest) | ||
| } | ||
| if err != nil { | ||
| return ghErrors.NewGitHubAPIErrorResponse(ctx, | ||
| "failed to update issue", | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@boazreicher I added confidence with values low, medium and high, and without any optional param or anything special, just sending it to the server