Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pkg/github/issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,12 +433,12 @@ func GetIssueComments(ctx context.Context, client *github.Client, deps ToolDepen
comments = filteredComments
}

r, err := json.Marshal(comments)
if err != nil {
return nil, fmt.Errorf("failed to marshal response: %w", err)
minimalComments := make([]MinimalIssueComment, 0, len(comments))
for _, comment := range comments {
minimalComments = append(minimalComments, convertToMinimalIssueComment(comment))
}

return utils.NewToolResultText(string(r)), nil
return MarshalledTextResult(minimalComments), nil
}

func GetSubIssues(ctx context.Context, client *github.Client, deps ToolDependencies, owner string, repo string, issueNumber int, pagination PaginationParams) (*mcp.CallToolResult, error) {
Expand Down
8 changes: 4 additions & 4 deletions pkg/github/issues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2020,16 +2020,16 @@ func Test_GetIssueComments(t *testing.T) {
textContent := getTextResult(t, result)

// Unmarshal and verify the result
var returnedComments []*github.IssueComment
var returnedComments []MinimalIssueComment
err = json.Unmarshal([]byte(textContent.Text), &returnedComments)
require.NoError(t, err)
assert.Equal(t, len(tc.expectedComments), len(returnedComments))
for i := range tc.expectedComments {
require.NotNil(t, tc.expectedComments[i].User)
require.NotNil(t, returnedComments[i].User)
assert.Equal(t, tc.expectedComments[i].GetID(), returnedComments[i].GetID())
assert.Equal(t, tc.expectedComments[i].GetBody(), returnedComments[i].GetBody())
assert.Equal(t, tc.expectedComments[i].GetUser().GetLogin(), returnedComments[i].GetUser().GetLogin())
assert.Equal(t, tc.expectedComments[i].GetID(), returnedComments[i].ID)
assert.Equal(t, tc.expectedComments[i].GetBody(), returnedComments[i].Body)
assert.Equal(t, tc.expectedComments[i].GetUser().GetLogin(), returnedComments[i].User.Login)
}
})
}
Expand Down
45 changes: 45 additions & 0 deletions pkg/github/minimal_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,18 @@ type MinimalIssue struct {
IssueType string `json:"issue_type,omitempty"`
}

// MinimalIssueComment is the trimmed output type for issue comment objects to reduce verbosity.
type MinimalIssueComment struct {
ID int64 `json:"id"`
Body string `json:"body,omitempty"`
HTMLURL string `json:"html_url"`
User *MinimalUser `json:"user,omitempty"`
AuthorAssociation string `json:"author_association,omitempty"`
Reactions *MinimalReactions `json:"reactions,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
UpdatedAt string `json:"updated_at,omitempty"`
}

// MinimalPullRequest is the trimmed output type for pull request objects to reduce verbosity.
type MinimalPullRequest struct {
Number int `json:"number"`
Expand Down Expand Up @@ -283,6 +295,39 @@ func convertToMinimalIssue(issue *github.Issue) MinimalIssue {
return m
}

func convertToMinimalIssueComment(comment *github.IssueComment) MinimalIssueComment {
m := MinimalIssueComment{
ID: comment.GetID(),
Body: comment.GetBody(),
HTMLURL: comment.GetHTMLURL(),
User: convertToMinimalUser(comment.GetUser()),
AuthorAssociation: comment.GetAuthorAssociation(),
}

if comment.CreatedAt != nil {
m.CreatedAt = comment.CreatedAt.Format(time.RFC3339)
}
if comment.UpdatedAt != nil {
m.UpdatedAt = comment.UpdatedAt.Format(time.RFC3339)
}

if r := comment.Reactions; r != nil {
m.Reactions = &MinimalReactions{
TotalCount: r.GetTotalCount(),
PlusOne: r.GetPlusOne(),
MinusOne: r.GetMinusOne(),
Laugh: r.GetLaugh(),
Confused: r.GetConfused(),
Heart: r.GetHeart(),
Hooray: r.GetHooray(),
Rocket: r.GetRocket(),
Eyes: r.GetEyes(),
}
}

return m
}

func convertToMinimalPullRequest(pr *github.PullRequest) MinimalPullRequest {
m := MinimalPullRequest{
Number: pr.GetNumber(),
Expand Down