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
Reduce context usage for list_issues#2098
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
Merged
+77
−85
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -201,33 +201,6 @@ func getIssueQueryType(hasLabels bool, hasSince bool) any { | ||
| } | ||
| } | ||
| func fragmentToIssue(fragment IssueFragment) *github.Issue { | ||
| // Convert GraphQL labels to GitHub API labels format | ||
| var foundLabels []*github.Label | ||
| for _, labelNode := range fragment.Labels.Nodes { | ||
| foundLabels = append(foundLabels, &github.Label{ | ||
| Name: github.Ptr(string(labelNode.Name)), | ||
| NodeID: github.Ptr(string(labelNode.ID)), | ||
| Description: github.Ptr(string(labelNode.Description)), | ||
| }) | ||
| } | ||
| return &github.Issue{ | ||
| Number: github.Ptr(int(fragment.Number)), | ||
| Title: github.Ptr(sanitize.Sanitize(string(fragment.Title))), | ||
| CreatedAt: &github.Timestamp{Time: fragment.CreatedAt.Time}, | ||
| UpdatedAt: &github.Timestamp{Time: fragment.UpdatedAt.Time}, | ||
| User: &github.User{ | ||
| Login: github.Ptr(string(fragment.Author.Login)), | ||
| }, | ||
| State: github.Ptr(string(fragment.State)), | ||
| ID: github.Ptr(fragment.DatabaseID), | ||
| Body: github.Ptr(sanitize.Sanitize(string(fragment.Body))), | ||
| Labels: foundLabels, | ||
| Comments: github.Ptr(int(fragment.Comments.TotalCount)), | ||
| } | ||
| } | ||
| // IssueRead creates a tool to get details of a specific issue in a GitHub repository. | ||
| func IssueRead(t translations.TranslationHelperFunc) inventory.ServerTool { | ||
| schema := &jsonschema.Schema{ | ||
| @@ -1584,41 +1557,12 @@ func ListIssues(t translations.TranslationHelperFunc) inventory.ServerTool { | ||
| ), nil, nil | ||
| } | ||
| // Extract and convert all issue nodes using the common interface | ||
| var issues []*github.Issue | ||
| var pageInfo struct { | ||
| HasNextPage githubv4.Boolean | ||
| HasPreviousPage githubv4.Boolean | ||
| StartCursor githubv4.String | ||
| EndCursor githubv4.String | ||
| } | ||
| var totalCount int | ||
| var resp MinimalIssuesResponse | ||
| if queryResult, ok := issueQuery.(IssueQueryResult); ok { | ||
| fragment := queryResult.GetIssueFragment() | ||
| for _, issue := range fragment.Nodes { | ||
| issues = append(issues, fragmentToIssue(issue)) | ||
| } | ||
| pageInfo = fragment.PageInfo | ||
| totalCount = fragment.TotalCount | ||
| } | ||
| // Create response with issues | ||
| response := map[string]any{ | ||
| "issues": issues, | ||
| "pageInfo": map[string]any{ | ||
| "hasNextPage": pageInfo.HasNextPage, | ||
| "hasPreviousPage": pageInfo.HasPreviousPage, | ||
| "startCursor": string(pageInfo.StartCursor), | ||
| "endCursor": string(pageInfo.EndCursor), | ||
| }, | ||
| "totalCount": totalCount, | ||
| resp = convertToMinimalIssuesResponse(queryResult.GetIssueFragment()) | ||
| } | ||
| out, err := json.Marshal(response) | ||
| if err != nil { | ||
| return nil, nil, fmt.Errorf("failed to marshal issues: %w", err) | ||
| } | ||
| return utils.NewToolResultText(string(out)), nil, nil | ||
| return MarshalledTextResult(resp), nil, nil | ||
kerobbi marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| }) | ||
| } | ||
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 |
|---|---|---|
| @@ -1187,7 +1187,6 @@ func Test_ListIssues(t *testing.T) { | ||
| expectError bool | ||
| errContains string | ||
| expectedCount int | ||
| verifyOrder func(t *testing.T, issues []*github.Issue) | ||
| }{ | ||
| { | ||
| name: "list all issues", | ||
| @@ -1296,31 +1295,32 @@ func Test_ListIssues(t *testing.T) { | ||
| require.NoError(t, err) | ||
| // Parse the structured response with pagination info | ||
| var response struct { | ||
| Issues []*github.Issue `json:"issues"` | ||
| PageInfo struct { | ||
| HasNextPage bool `json:"hasNextPage"` | ||
| HasPreviousPage bool `json:"hasPreviousPage"` | ||
| StartCursor string `json:"startCursor"` | ||
| EndCursor string `json:"endCursor"` | ||
| } `json:"pageInfo"` | ||
| TotalCount int `json:"totalCount"` | ||
| } | ||
| var response MinimalIssuesResponse | ||
| err = json.Unmarshal([]byte(text), &response) | ||
| require.NoError(t, err) | ||
| assert.Len(t, response.Issues, tc.expectedCount, "Expected %d issues, got %d", tc.expectedCount, len(response.Issues)) | ||
| // Verify order if verifyOrder function is provided | ||
| if tc.verifyOrder != nil { | ||
| tc.verifyOrder(t, response.Issues) | ||
| } | ||
| // Verify pagination metadata | ||
| assert.Equal(t, tc.expectedCount, response.TotalCount) | ||
| assert.False(t, response.PageInfo.HasNextPage) | ||
| assert.False(t, response.PageInfo.HasPreviousPage) | ||
| // Verify that returned issues have expected structure | ||
| for _, issue := range response.Issues { | ||
| assert.NotNil(t, issue.Number, "Issue should have number") | ||
| assert.NotNil(t, issue.Title, "Issue should have title") | ||
| assert.NotNil(t, issue.State, "Issue should have state") | ||
| assert.NotZero(t, issue.Number, "Issue should have number") | ||
| assert.NotEmpty(t, issue.Title, "Issue should have title") | ||
| assert.NotEmpty(t, issue.State, "Issue should have state") | ||
| assert.NotEmpty(t, issue.CreatedAt, "Issue should have created_at") | ||
| assert.NotEmpty(t, issue.UpdatedAt, "Issue should have updated_at") | ||
| assert.NotNil(t, issue.User, "Issue should have user") | ||
| assert.NotEmpty(t, issue.User.Login, "Issue user should have login") | ||
| assert.Empty(t, issue.HTMLURL, "html_url should be empty (not populated by GraphQL fragment)") | ||
| // Labels should be flattened to name strings | ||
| for _, label := range issue.Labels { | ||
| assert.NotEmpty(t, label, "Label should be a non-empty string") | ||
| } | ||
| } | ||
kerobbi marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| }) | ||
| } | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.