Skip to content

Commit c0ba3ed

Browse files
authored
use minimal types (#2066)
1 parent 3ffc06b commit c0ba3ed

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
@@ -454,12 +454,12 @@ func GetPullRequestReviews(ctx context.Context, client *github.Client, deps Tool
454454
}
455455
}
456456

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

462-
return utils.NewToolResultText(string(r)), nil
462+
return MarshalledTextResult(minimalReviews), nil
463463
}
464464

465465
// 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
@@ -1990,18 +1990,18 @@ func Test_GetPullRequestReviews(t *testing.T) {
19901990
textContent := getTextResult(t, result)
19911991

19921992
// Unmarshal and verify the result
1993-
var returnedReviews []*github.PullRequestReview
1993+
var returnedReviews []MinimalPullRequestReview
19941994
err = json.Unmarshal([]byte(textContent.Text), &returnedReviews)
19951995
require.NoError(t, err)
19961996
assert.Len(t, returnedReviews, len(tc.expectedReviews))
19971997
for i, review := range returnedReviews {
1998+
assert.Equal(t, tc.expectedReviews[i].GetID(), review.ID)
1999+
assert.Equal(t, tc.expectedReviews[i].GetState(), review.State)
2000+
assert.Equal(t, tc.expectedReviews[i].GetBody(), review.Body)
19982001
require.NotNil(t, tc.expectedReviews[i].User)
19992002
require.NotNil(t, review.User)
2000-
assert.Equal(t, tc.expectedReviews[i].GetID(), review.GetID())
2001-
assert.Equal(t, tc.expectedReviews[i].GetState(), review.GetState())
2002-
assert.Equal(t, tc.expectedReviews[i].GetBody(), review.GetBody())
2003-
assert.Equal(t, tc.expectedReviews[i].GetUser().GetLogin(), review.GetUser().GetLogin())
2004-
assert.Equal(t, tc.expectedReviews[i].GetHTMLURL(), review.GetHTMLURL())
2003+
assert.Equal(t, tc.expectedReviews[i].GetUser().GetLogin(), review.User.Login)
2004+
assert.Equal(t, tc.expectedReviews[i].GetHTMLURL(), review.HTMLURL)
20052005
}
20062006
})
20072007
}

0 commit comments

Comments
 (0)