Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 4.8k
use the REST PATCH endpoint if updating rationale or suggestion#2592
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1277,75 +1277,50 @@ func TestGranularSetIssueFields(t *testing.T) { | ||
| }) | ||
| t.Run("successful set with text value and rationale", func(t *testing.T) { | ||
| matchers := []githubv4mock.Matcher{ | ||
| githubv4mock.NewQueryMatcher( | ||
| struct { | ||
| Repository struct { | ||
| Issue struct { | ||
| ID githubv4.ID | ||
| } `graphql:"issue(number: $issueNumber)"` | ||
| } `graphql:"repository(owner: $owner, name: $repo)"` | ||
| }{}, | ||
| map[string]any{ | ||
| "owner": githubv4.String("owner"), | ||
| "repo": githubv4.String("repo"), | ||
| "issueNumber": githubv4.Int(5), | ||
| }, | ||
| githubv4mock.DataResponse(map[string]any{ | ||
| "repository": map[string]any{ | ||
| "issue": map[string]any{"id": "ISSUE_123"}, | ||
| }, | ||
| }), | ||
| ), | ||
| githubv4mock.NewMutationMatcher( | ||
| struct { | ||
| SetIssueFieldValue struct { | ||
| Issue struct { | ||
| ID githubv4.ID | ||
| Number githubv4.Int | ||
| URL githubv4.String | ||
| } | ||
| IssueFieldValues []struct { | ||
| TextValue struct { | ||
| Value string | ||
| } `graphql:"... on IssueFieldTextValue"` | ||
| SingleSelectValue struct { | ||
| Name string | ||
| } `graphql:"... on IssueFieldSingleSelectValue"` | ||
| DateValue struct { | ||
| Value string | ||
| } `graphql:"... on IssueFieldDateValue"` | ||
| NumberValue struct { | ||
| Value float64 | ||
| } `graphql:"... on IssueFieldNumberValue"` | ||
| } | ||
| } `graphql:"setIssueFieldValue(input: $input)"` | ||
| }{}, | ||
| SetIssueFieldValueInput{ | ||
| IssueID: githubv4.ID("ISSUE_123"), | ||
| IssueFields: []IssueFieldCreateOrUpdateInput{ | ||
| { | ||
| FieldID: githubv4.ID("FIELD_1"), | ||
| TextValue: githubv4.NewString(githubv4.String("hello")), | ||
| Rationale: githubv4.NewString(githubv4.String("Reflects the reported severity")), | ||
| // fetchIssueFields query mock for resolving the field's database ID. | ||
| fieldsQuery := githubv4mock.NewQueryMatcher( | ||
| issueFieldsRepoQuery{}, | ||
| map[string]any{ | ||
| "owner": githubv4.String("owner"), | ||
| "name": githubv4.String("repo"), | ||
| }, | ||
| githubv4mock.DataResponse(map[string]any{ | ||
| "repository": map[string]any{ | ||
| "issueFields": map[string]any{ | ||
| "nodes": []any{ | ||
| map[string]any{ | ||
| "__typename": "IssueFieldText", | ||
| "id": "FIELD_1", | ||
| "fullDatabaseId": "42", | ||
| "name": "DRI", | ||
| "dataType": "TEXT", | ||
| "visibility": "ALL", | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| nil, | ||
| githubv4mock.DataResponse(map[string]any{ | ||
| "setIssueFieldValue": map[string]any{ | ||
| "issue": map[string]any{ | ||
| "id": "ISSUE_123", | ||
| "number": 5, | ||
| "url": "https://github.com/owner/repo/issues/5", | ||
| }, | ||
| }), | ||
| ) | ||
| gqlClient := githubv4.NewClient(githubv4mock.NewMockedHTTPClient(fieldsQuery)) | ||
| // REST PATCH mock asserting the issue_field_values wire format. | ||
| restClient := mustNewGHClient(t, MockHTTPClientWithHandlers(map[string]http.HandlerFunc{ | ||
| PatchReposIssuesByOwnerByRepoByIssueNumber: expectRequestBody(t, map[string]any{ | ||
| "issue_field_values": []any{ | ||
| map[string]any{ | ||
| "field_id": float64(42), | ||
| "value": "hello", | ||
| "rationale": "Reflects the reported severity", | ||
| }, | ||
| }), | ||
| ), | ||
| } | ||
| gqlClient := githubv4.NewClient(githubv4mock.NewMockedHTTPClient(matchers...)) | ||
| deps := BaseDeps{GQLClient: gqlClient} | ||
| }, | ||
| }).andThen(mockResponse(t, http.StatusOK, &gogithub.Issue{ | ||
| ID: gogithub.Ptr(int64(123)), | ||
| Number: gogithub.Ptr(5), | ||
| HTMLURL: gogithub.Ptr("https://github.com/owner/repo/issues/5"), | ||
| })), | ||
| })) | ||
boazreicher marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| deps := BaseDeps{Client: restClient, GQLClient: gqlClient} | ||
| serverTool := GranularSetIssueFields(translations.NullTranslationHelper) | ||
| handler := serverTool.Handler(deps) | ||
| @@ -1364,6 +1339,9 @@ func TestGranularSetIssueFields(t *testing.T) { | ||
| result, err := handler(ContextWithDeps(context.Background(), deps), &request) | ||
| require.NoError(t, err) | ||
| assert.False(t, result.IsError) | ||
| textContent := getTextResult(t, result) | ||
| assert.Contains(t, textContent.Text, `"id":"123"`) | ||
| assert.Contains(t, textContent.Text, "https://github.com/owner/repo/issues/5") | ||
| }) | ||
| t.Run("rationale too long returns error", func(t *testing.T) { | ||
| @@ -1390,77 +1368,49 @@ func TestGranularSetIssueFields(t *testing.T) { | ||
| }) | ||
| t.Run("successful set with suggest flag", func(t *testing.T) { | ||
| suggestTrue := githubv4.Boolean(true) | ||
| matchers := []githubv4mock.Matcher{ | ||
| githubv4mock.NewQueryMatcher( | ||
| struct { | ||
| Repository struct { | ||
| Issue struct { | ||
| ID githubv4.ID | ||
| } `graphql:"issue(number: $issueNumber)"` | ||
| } `graphql:"repository(owner: $owner, name: $repo)"` | ||
| }{}, | ||
| map[string]any{ | ||
| "owner": githubv4.String("owner"), | ||
| "repo": githubv4.String("repo"), | ||
| "issueNumber": githubv4.Int(5), | ||
| }, | ||
| githubv4mock.DataResponse(map[string]any{ | ||
| "repository": map[string]any{ | ||
| "issue": map[string]any{"id": "ISSUE_123"}, | ||
| }, | ||
| }), | ||
| ), | ||
| githubv4mock.NewMutationMatcher( | ||
| struct { | ||
| SetIssueFieldValue struct { | ||
| Issue struct { | ||
| ID githubv4.ID | ||
| Number githubv4.Int | ||
| URL githubv4.String | ||
| } | ||
| IssueFieldValues []struct { | ||
| TextValue struct { | ||
| Value string | ||
| } `graphql:"... on IssueFieldTextValue"` | ||
| SingleSelectValue struct { | ||
| Name string | ||
| } `graphql:"... on IssueFieldSingleSelectValue"` | ||
| DateValue struct { | ||
| Value string | ||
| } `graphql:"... on IssueFieldDateValue"` | ||
| NumberValue struct { | ||
| Value float64 | ||
| } `graphql:"... on IssueFieldNumberValue"` | ||
| } | ||
| } `graphql:"setIssueFieldValue(input: $input)"` | ||
| }{}, | ||
| SetIssueFieldValueInput{ | ||
| IssueID: githubv4.ID("ISSUE_123"), | ||
| IssueFields: []IssueFieldCreateOrUpdateInput{ | ||
| { | ||
| FieldID: githubv4.ID("FIELD_1"), | ||
| TextValue: githubv4.NewString(githubv4.String("hello")), | ||
| Rationale: githubv4.NewString(githubv4.String("Reflects the reported severity")), | ||
| Suggest: &suggestTrue, | ||
| fieldsQuery := githubv4mock.NewQueryMatcher( | ||
| issueFieldsRepoQuery{}, | ||
| map[string]any{ | ||
| "owner": githubv4.String("owner"), | ||
| "name": githubv4.String("repo"), | ||
| }, | ||
| githubv4mock.DataResponse(map[string]any{ | ||
| "repository": map[string]any{ | ||
| "issueFields": map[string]any{ | ||
| "nodes": []any{ | ||
| map[string]any{ | ||
| "__typename": "IssueFieldText", | ||
| "id": "FIELD_1", | ||
| "fullDatabaseId": "42", | ||
| "name": "DRI", | ||
| "dataType": "TEXT", | ||
| "visibility": "ALL", | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| nil, | ||
| githubv4mock.DataResponse(map[string]any{ | ||
| "setIssueFieldValue": map[string]any{ | ||
| "issue": map[string]any{ | ||
| "id": "ISSUE_123", | ||
| "number": 5, | ||
| "url": "https://github.com/owner/repo/issues/5", | ||
| }, | ||
| }), | ||
| ) | ||
| gqlClient := githubv4.NewClient(githubv4mock.NewMockedHTTPClient(fieldsQuery)) | ||
| restClient := mustNewGHClient(t, MockHTTPClientWithHandlers(map[string]http.HandlerFunc{ | ||
| PatchReposIssuesByOwnerByRepoByIssueNumber: expectRequestBody(t, map[string]any{ | ||
| "issue_field_values": []any{ | ||
| map[string]any{ | ||
| "field_id": float64(42), | ||
| "value": "hello", | ||
| "rationale": "Reflects the reported severity", | ||
| "suggest": true, | ||
| }, | ||
| }), | ||
| ), | ||
| } | ||
| gqlClient := githubv4.NewClient(githubv4mock.NewMockedHTTPClient(matchers...)) | ||
| deps := BaseDeps{GQLClient: gqlClient} | ||
| }, | ||
| }).andThen(mockResponse(t, http.StatusOK, &gogithub.Issue{ | ||
| ID: gogithub.Ptr(int64(123)), | ||
| Number: gogithub.Ptr(5), | ||
| HTMLURL: gogithub.Ptr("https://github.com/owner/repo/issues/5"), | ||
| })), | ||
| })) | ||
boazreicher marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| deps := BaseDeps{Client: restClient, GQLClient: gqlClient} | ||
| serverTool := GranularSetIssueFields(translations.NullTranslationHelper) | ||
| handler := serverTool.Handler(deps) | ||
| @@ -1480,5 +1430,137 @@ func TestGranularSetIssueFields(t *testing.T) { | ||
| result, err := handler(ContextWithDeps(context.Background(), deps), &request) | ||
| require.NoError(t, err) | ||
| assert.False(t, result.IsError) | ||
| textContent := getTextResult(t, result) | ||
| assert.Contains(t, textContent.Text, `"id":"123"`) | ||
| assert.Contains(t, textContent.Text, "https://github.com/owner/repo/issues/5") | ||
| }) | ||
| t.Run("successful set with single_select_option_id and rationale", func(t *testing.T) { | ||
| fieldsQuery := githubv4mock.NewQueryMatcher( | ||
| issueFieldsRepoQuery{}, | ||
| map[string]any{ | ||
| "owner": githubv4.String("owner"), | ||
| "name": githubv4.String("repo"), | ||
| }, | ||
| githubv4mock.DataResponse(map[string]any{ | ||
| "repository": map[string]any{ | ||
| "issueFields": map[string]any{ | ||
| "nodes": []any{ | ||
| map[string]any{ | ||
| "__typename": "IssueFieldSingleSelect", | ||
| "id": "FIELD_1", | ||
| "fullDatabaseId": "42", | ||
| "name": "Priority", | ||
| "dataType": "SINGLE_SELECT", | ||
| "visibility": "ALL", | ||
| "options": []any{ | ||
| map[string]any{"id": "OPT_HIGH", "name": "High", "description": ""}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }), | ||
| ) | ||
| gqlClient := githubv4.NewClient(githubv4mock.NewMockedHTTPClient(fieldsQuery)) | ||
| restClient := mustNewGHClient(t, MockHTTPClientWithHandlers(map[string]http.HandlerFunc{ | ||
| PatchReposIssuesByOwnerByRepoByIssueNumber: expectRequestBody(t, map[string]any{ | ||
| "issue_field_values": []any{ | ||
| map[string]any{ | ||
| "field_id": float64(42), | ||
| "value": "High", | ||
| "rationale": "Severe customer impact", | ||
| }, | ||
| }, | ||
| }).andThen(mockResponse(t, http.StatusOK, &gogithub.Issue{ | ||
| ID: gogithub.Ptr(int64(123)), | ||
| Number: gogithub.Ptr(5), | ||
| HTMLURL: gogithub.Ptr("https://github.com/owner/repo/issues/5"), | ||
| })), | ||
| })) | ||
| deps := BaseDeps{Client: restClient, GQLClient: gqlClient} | ||
| serverTool := GranularSetIssueFields(translations.NullTranslationHelper) | ||
| handler := serverTool.Handler(deps) | ||
| request := createMCPRequest(map[string]any{ | ||
| "owner": "owner", | ||
| "repo": "repo", | ||
| "issue_number": float64(5), | ||
| "fields": []any{ | ||
| map[string]any{ | ||
| "field_id": "FIELD_1", | ||
| "single_select_option_id": "OPT_HIGH", | ||
| "rationale": "Severe customer impact", | ||
| }, | ||
| }, | ||
| }) | ||
| result, err := handler(ContextWithDeps(context.Background(), deps), &request) | ||
| require.NoError(t, err) | ||
| assert.False(t, result.IsError) | ||
| }) | ||
| t.Run("successful set with number value and rationale", func(t *testing.T) { | ||
| fieldsQuery := githubv4mock.NewQueryMatcher( | ||
| issueFieldsRepoQuery{}, | ||
| map[string]any{ | ||
| "owner": githubv4.String("owner"), | ||
| "name": githubv4.String("repo"), | ||
| }, | ||
| githubv4mock.DataResponse(map[string]any{ | ||
| "repository": map[string]any{ | ||
| "issueFields": map[string]any{ | ||
| "nodes": []any{ | ||
| map[string]any{ | ||
| "__typename": "IssueFieldNumber", | ||
| "id": "FIELD_1", | ||
| "fullDatabaseId": "42", | ||
| "name": "Score", | ||
| "dataType": "NUMBER", | ||
| "visibility": "ALL", | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }), | ||
| ) | ||
| gqlClient := githubv4.NewClient(githubv4mock.NewMockedHTTPClient(fieldsQuery)) | ||
| restClient := mustNewGHClient(t, MockHTTPClientWithHandlers(map[string]http.HandlerFunc{ | ||
| PatchReposIssuesByOwnerByRepoByIssueNumber: expectRequestBody(t, map[string]any{ | ||
| "issue_field_values": []any{ | ||
| map[string]any{ | ||
| "field_id": float64(42), | ||
| "value": float64(7), | ||
| "rationale": "Initial estimate", | ||
| }, | ||
| }, | ||
| }).andThen(mockResponse(t, http.StatusOK, &gogithub.Issue{ | ||
| ID: gogithub.Ptr(int64(123)), | ||
| Number: gogithub.Ptr(5), | ||
| HTMLURL: gogithub.Ptr("https://github.com/owner/repo/issues/5"), | ||
| })), | ||
| })) | ||
| deps := BaseDeps{Client: restClient, GQLClient: gqlClient} | ||
| serverTool := GranularSetIssueFields(translations.NullTranslationHelper) | ||
| handler := serverTool.Handler(deps) | ||
| request := createMCPRequest(map[string]any{ | ||
| "owner": "owner", | ||
| "repo": "repo", | ||
| "issue_number": float64(5), | ||
| "fields": []any{ | ||
| map[string]any{ | ||
| "field_id": "FIELD_1", | ||
| "number_value": float64(7), | ||
| "rationale": "Initial estimate", | ||
| }, | ||
| }, | ||
| }) | ||
| result, err := handler(ContextWithDeps(context.Background(), deps), &request) | ||
| require.NoError(t, err) | ||
| assert.False(t, result.IsError) | ||
| }) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.