Skip to content

Commit 066aeba

Browse files
Merge branch 'main' into fix-mcp-apps-update-before-submit
2 parents c2d8087 + 713848b commit 066aeba

File tree

3 files changed

+35
-10
lines changed

3 files changed

+35
-10
lines changed

pkg/github/minimal_types.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,18 @@ type MinimalCommitFile struct {
7979
Changes int `json:"changes,omitempty"`
8080
}
8181

82+
// MinimalPRFile represents a file changed in a pull request.
83+
// Compared to MinimalCommitFile, it includes the patch diff and previous filename for renames.
84+
type MinimalPRFile struct {
85+
Filename string `json:"filename"`
86+
Status string `json:"status,omitempty"`
87+
Additions int `json:"additions,omitempty"`
88+
Deletions int `json:"deletions,omitempty"`
89+
Changes int `json:"changes,omitempty"`
90+
Patch string `json:"patch,omitempty"`
91+
PreviousFilename string `json:"previous_filename,omitempty"`
92+
}
93+
8294
// MinimalCommit is the trimmed output type for commit objects.
8395
type MinimalCommit struct {
8496
SHA string `json:"sha"`
@@ -600,6 +612,22 @@ func convertToMinimalCommit(commit *github.RepositoryCommit, includeDiffs bool)
600612
return minimalCommit
601613
}
602614

615+
func convertToMinimalPRFiles(files []*github.CommitFile) []MinimalPRFile {
616+
result := make([]MinimalPRFile, 0, len(files))
617+
for _, f := range files {
618+
result = append(result, MinimalPRFile{
619+
Filename: f.GetFilename(),
620+
Status: f.GetStatus(),
621+
Additions: f.GetAdditions(),
622+
Deletions: f.GetDeletions(),
623+
Changes: f.GetChanges(),
624+
Patch: f.GetPatch(),
625+
PreviousFilename: f.GetPreviousFilename(),
626+
})
627+
}
628+
return result
629+
}
630+
603631
// convertToMinimalBranch converts a GitHub API Branch to MinimalBranch
604632
func convertToMinimalBranch(branch *github.Branch) MinimalBranch {
605633
return MinimalBranch{

pkg/github/pullrequests.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,12 +290,9 @@ func GetPullRequestFiles(ctx context.Context, client *github.Client, owner, repo
290290
return ghErrors.NewGitHubAPIStatusErrorResponse(ctx, "failed to get pull request files", resp, body), nil
291291
}
292292

293-
r, err := json.Marshal(files)
294-
if err != nil {
295-
return nil, fmt.Errorf("failed to marshal response: %w", err)
296-
}
293+
minimalFiles := convertToMinimalPRFiles(files)
297294

298-
return utils.NewToolResultText(string(r)), nil
295+
return MarshalledTextResult(minimalFiles), nil
299296
}
300297

301298
// GraphQL types for review threads query

pkg/github/pullrequests_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,15 +1229,15 @@ func Test_GetPullRequestFiles(t *testing.T) {
12291229
textContent := getTextResult(t, result)
12301230

12311231
// Unmarshal and verify the result
1232-
var returnedFiles []*github.CommitFile
1232+
var returnedFiles []MinimalPRFile
12331233
err = json.Unmarshal([]byte(textContent.Text), &returnedFiles)
12341234
require.NoError(t, err)
12351235
assert.Len(t, returnedFiles, len(tc.expectedFiles))
12361236
for i, file := range returnedFiles {
1237-
assert.Equal(t, *tc.expectedFiles[i].Filename, *file.Filename)
1238-
assert.Equal(t, *tc.expectedFiles[i].Status, *file.Status)
1239-
assert.Equal(t, *tc.expectedFiles[i].Additions, *file.Additions)
1240-
assert.Equal(t, *tc.expectedFiles[i].Deletions, *file.Deletions)
1237+
assert.Equal(t, tc.expectedFiles[i].GetFilename(), file.Filename)
1238+
assert.Equal(t, tc.expectedFiles[i].GetStatus(), file.Status)
1239+
assert.Equal(t, tc.expectedFiles[i].GetAdditions(), file.Additions)
1240+
assert.Equal(t, tc.expectedFiles[i].GetDeletions(), file.Deletions)
12411241
}
12421242
})
12431243
}

0 commit comments

Comments
 (0)