Skip to content

Commit fa3ebf1

Browse files
committed
use minimal types
1 parent 713848b commit fa3ebf1

File tree

3 files changed

+40
-10
lines changed

3 files changed

+40
-10
lines changed

pkg/github/minimal_types.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,38 @@ type MinimalProjectStatusUpdate struct {
272272
Creator *MinimalUser `json:"creator,omitempty"`
273273
}
274274

275+
// MinimalPullRequestReview is the trimmed output type for pull request review objects to reduce verbosity.
276+
type MinimalPullRequestReview struct {
277+
ID int64 `json:"id"`
278+
State string `json:"state"`
279+
Body string `json:"body,omitempty"`
280+
HTMLURL string `json:"html_url"`
281+
User *MinimalUser `json:"user,omitempty"`
282+
CommitID string `json:"commit_id,omitempty"`
283+
SubmittedAt string `json:"submitted_at,omitempty"`
284+
AuthorAssociation string `json:"author_association,omitempty"`
285+
}
286+
275287
// Helper functions
276288

289+
func convertToMinimalPullRequestReview(review *github.PullRequestReview) MinimalPullRequestReview {
290+
m := MinimalPullRequestReview{
291+
ID: review.GetID(),
292+
State: review.GetState(),
293+
Body: review.GetBody(),
294+
HTMLURL: review.GetHTMLURL(),
295+
User: convertToMinimalUser(review.GetUser()),
296+
CommitID: review.GetCommitID(),
297+
AuthorAssociation: review.GetAuthorAssociation(),
298+
}
299+
300+
if review.SubmittedAt != nil {
301+
m.SubmittedAt = review.SubmittedAt.Format(time.RFC3339)
302+
}
303+
304+
return m
305+
}
306+
277307
func convertToMinimalIssue(issue *github.Issue) MinimalIssue {
278308
m := MinimalIssue{
279309
Number: issue.GetNumber(),

pkg/github/pullrequests.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,12 +471,12 @@ func GetPullRequestReviews(ctx context.Context, client *github.Client, deps Tool
471471
}
472472
}
473473

474-
r, err := json.Marshal(reviews)
475-
if err != nil {
476-
return nil, fmt.Errorf("failed to marshal response: %w", err)
474+
minimalReviews := make([]MinimalPullRequestReview, 0, len(reviews))
475+
for _, review := range reviews {
476+
minimalReviews = append(minimalReviews, convertToMinimalPullRequestReview(review))
477477
}
478478

479-
return utils.NewToolResultText(string(r)), nil
479+
return MarshalledTextResult(minimalReviews), nil
480480
}
481481

482482
// PullRequestWriteUIResourceURI is the URI for the create_pull_request tool's MCP App UI resource.

pkg/github/pullrequests_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2005,18 +2005,18 @@ func Test_GetPullRequestReviews(t *testing.T) {
20052005
textContent := getTextResult(t, result)
20062006

20072007
// Unmarshal and verify the result
2008-
var returnedReviews []*github.PullRequestReview
2008+
var returnedReviews []MinimalPullRequestReview
20092009
err = json.Unmarshal([]byte(textContent.Text), &returnedReviews)
20102010
require.NoError(t, err)
20112011
assert.Len(t, returnedReviews, len(tc.expectedReviews))
20122012
for i, review := range returnedReviews {
2013+
assert.Equal(t, tc.expectedReviews[i].GetID(), review.ID)
2014+
assert.Equal(t, tc.expectedReviews[i].GetState(), review.State)
2015+
assert.Equal(t, tc.expectedReviews[i].GetBody(), review.Body)
20132016
require.NotNil(t, tc.expectedReviews[i].User)
20142017
require.NotNil(t, review.User)
2015-
assert.Equal(t, tc.expectedReviews[i].GetID(), review.GetID())
2016-
assert.Equal(t, tc.expectedReviews[i].GetState(), review.GetState())
2017-
assert.Equal(t, tc.expectedReviews[i].GetBody(), review.GetBody())
2018-
assert.Equal(t, tc.expectedReviews[i].GetUser().GetLogin(), review.GetUser().GetLogin())
2019-
assert.Equal(t, tc.expectedReviews[i].GetHTMLURL(), review.GetHTMLURL())
2018+
assert.Equal(t, tc.expectedReviews[i].GetUser().GetLogin(), review.User.Login)
2019+
assert.Equal(t, tc.expectedReviews[i].GetHTMLURL(), review.HTMLURL)
20202020
}
20212021
})
20222022
}

0 commit comments

Comments
 (0)