Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit938e354

Browse files
committed
testing review threads
1 parentec6afa7 commit938e354

File tree

5 files changed

+141
-112
lines changed

5 files changed

+141
-112
lines changed

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ Possible options:
930930
2. get_diff - Get the diff of a pull request.
931931
3. get_status - Get status of a head commit in a pull request. This reflects status of builds and checks.
932932
4. get_files - Get the list of files changed in a pull request. Use with pagination parameters to control the number of results returned.
933-
5. get_review_comments - Getthereviewcomments on a pull request.They are comments made on a portion oftheunified diffduringapull requestreview. Usewithpagination parameters to control the number of results returned.
933+
5. get_review_comments - Get reviewthreads on a pull request.Each thread contains logically grouped review comments made onthesame code locationduring pull requestreviews. Returns threadswithmetadata (isResolved, isOutdated, isCollapsed) and their associated comments. Use cursor-based pagination (perPage, after) to control results.
934934
6. get_reviews - Get the reviews on a pull request. When asked for review comments, use get_review_comments method.
935935
7. get_comments - Get comments on a pull request. Use this if user doesn't specifically want review comments. Use with pagination parameters to control the number of results returned.
936936
(string, required)

‎pkg/github/__toolsnaps__/pull_request_read.snap‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"inputSchema": {
88
"properties": {
99
"method": {
10-
"description":"Action to specify what pull request data needs to be retrieved from GitHub.\nPossible options:\n 1. get - Get details of a specific pull request.\n 2. get_diff - Get the diff of a pull request.\n 3. get_status - Get status of a head commit in a pull request. This reflects status of builds and checks.\n 4. get_files - Get the list of files changed in a pull request. Use with pagination parameters to control the number of results returned.\n 5. get_review_comments - Get the review comments on a pull request. They are comments made on a portion of the unified diff during a pull request review. Use with pagination parameters to control the number of results returned.\n 6. get_reviews - Get the reviews on a pull request. When asked for review comments, use get_review_comments method.\n 7. get_comments - Get comments on a pull request. Use this if user doesn't specifically want review comments. Use with pagination parameters to control the number of results returned.\n",
10+
"description": "Action to specify what pull request data needs to be retrieved from GitHub. \nPossible options: \n 1. get - Get details of a specific pull request.\n 2. get_diff - Get the diff of a pull request.\n 3. get_status - Get status of a head commit in a pull request. This reflects status of builds and checks.\n 4. get_files - Get the list of files changed in a pull request. Use with pagination parameters to control the number of results returned.\n 5. get_review_comments - Get review threads on a pull request. Each thread contains logically grouped review comments made on the same code location during pull request reviews. Returns threads with metadata (isResolved, isOutdated, isCollapsed) and their associated comments. Use cursor-based pagination (perPage, after) to control results.\n 6. get_reviews - Get the reviews on a pull request. When asked for review comments, use get_review_comments method.\n 7. get_comments - Get comments on a pull request. Use this if user doesn't specifically want review comments. Use with pagination parameters to control the number of results returned.\n",
1111
"enum": [
1212
"get",
1313
"get_diff",

‎pkg/github/pullrequests.go‎

Lines changed: 96 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
)
2020

2121
// GetPullRequest creates a tool to get details of a specific pull request.
22-
funcPullRequestRead(getClientGetClientFn,t translations.TranslationHelperFunc,flagsFeatureFlags) (mcp.Tool, server.ToolHandlerFunc) {
22+
funcPullRequestRead(getClientGetClientFn,getGQLClientGetGQLClientFn,t translations.TranslationHelperFunc,flagsFeatureFlags) (mcp.Tool, server.ToolHandlerFunc) {
2323
returnmcp.NewTool("pull_request_read",
2424
mcp.WithDescription(t("TOOL_PULL_REQUEST_READ_DESCRIPTION","Get information on a specific pull request in GitHub repository.")),
2525
mcp.WithToolAnnotation(mcp.ToolAnnotation{
@@ -34,7 +34,7 @@ Possible options:
3434
2. get_diff - Get the diff of a pull request.
3535
3. get_status - Get status of a head commit in a pull request. This reflects status of builds and checks.
3636
4. get_files - Get the list of files changed in a pull request. Use with pagination parameters to control the number of results returned.
37-
5. get_review_comments - Getthereviewcomments on a pull request.They are comments made on a portion oftheunified diffduringapull requestreview. Usewithpagination parameters to control the number of results returned.
37+
5. get_review_comments - Get reviewthreads on a pull request.Each thread contains logically grouped review comments made onthesame code locationduring pull requestreviews. Returns threadswithmetadata (isResolved, isOutdated, isCollapsed) and their associated comments. Use cursor-based pagination (perPage, after) to control results.
3838
6. get_reviews - Get the reviews on a pull request. When asked for review comments, use get_review_comments method.
3939
7. get_comments - Get comments on a pull request. Use this if user doesn't specifically want review comments. Use with pagination parameters to control the number of results returned.
4040
`),
@@ -94,7 +94,11 @@ Possible options:
9494
case"get_files":
9595
returnGetPullRequestFiles(ctx,client,owner,repo,pullNumber,pagination)
9696
case"get_review_comments":
97-
returnGetPullRequestReviewComments(ctx,client,owner,repo,pullNumber,pagination)
97+
gqlClient,err:=getGQLClient(ctx)
98+
iferr!=nil {
99+
returnmcp.NewToolResultError(fmt.Sprintf("failed to get GitHub GQL client: %v",err)),nil
100+
}
101+
returnGetPullRequestReviewComments(ctx,gqlClient,owner,repo,pullNumber,pagination)
98102
case"get_reviews":
99103
returnGetPullRequestReviews(ctx,client,owner,repo,pullNumber)
100104
case"get_comments":
@@ -249,33 +253,104 @@ func GetPullRequestFiles(ctx context.Context, client *github.Client, owner, repo
249253
returnmcp.NewToolResultText(string(r)),nil
250254
}
251255

252-
funcGetPullRequestReviewComments(ctx context.Context,client*github.Client,owner,repostring,pullNumberint,paginationPaginationParams) (*mcp.CallToolResult,error) {
253-
opts:=&github.PullRequestListCommentsOptions{
254-
ListOptions: github.ListOptions{
255-
PerPage:pagination.PerPage,
256-
Page:pagination.Page,
257-
},
256+
// GraphQL types for review threads query
257+
typereviewThreadsQuerystruct {
258+
Repositorystruct {
259+
PullRequeststruct {
260+
ReviewThreadsstruct {
261+
Nodes []reviewThreadNode
262+
PageInfopageInfoFragment
263+
TotalCount githubv4.Int
264+
}`graphql:"reviewThreads(first: $first, after: $after)"`
265+
}`graphql:"pullRequest(number: $prNum)"`
266+
}`graphql:"repository(owner: $owner, name: $repo)"`
267+
}
268+
269+
typereviewThreadNodestruct {
270+
ID githubv4.ID
271+
IsResolved githubv4.Boolean
272+
IsOutdated githubv4.Boolean
273+
IsCollapsed githubv4.Boolean
274+
Commentsstruct {
275+
Nodes []reviewCommentNode
276+
TotalCount githubv4.Int
277+
}`graphql:"comments(first: $commentsPerThread)"`
278+
}
279+
280+
typereviewCommentNodestruct {
281+
ID githubv4.ID
282+
Body githubv4.String
283+
Path githubv4.String
284+
Line*githubv4.Int
285+
Authorstruct {
286+
Login githubv4.String
258287
}
288+
CreatedAt githubv4.DateTime
289+
UpdatedAt githubv4.DateTime
290+
URL githubv4.URI
291+
}
292+
293+
typepageInfoFragmentstruct {
294+
HasNextPage githubv4.Boolean
295+
HasPreviousPage githubv4.Boolean
296+
StartCursor githubv4.String
297+
EndCursor githubv4.String
298+
}
259299

260-
comments,resp,err:=client.PullRequests.ListComments(ctx,owner,repo,pullNumber,opts)
300+
funcGetPullRequestReviewComments(ctx context.Context,gqlClient*githubv4.Client,owner,repostring,pullNumberint,paginationPaginationParams) (*mcp.CallToolResult,error) {
301+
// Convert pagination parameters to GraphQL format
302+
gqlParams,err:=pagination.ToGraphQLParams()
261303
iferr!=nil {
262-
returnghErrors.NewGitHubAPIErrorResponse(ctx,
263-
"failed to get pull request review comments",
264-
resp,
304+
returnmcp.NewToolResultError(fmt.Sprintf("invalid pagination parameters: %v",err)),nil
305+
}
306+
307+
// Default to 100 threads if not specified, max is 100 for GraphQL
308+
perPage:=int32(100)
309+
ifgqlParams.First!=nil&&*gqlParams.First>0 {
310+
perPage=*gqlParams.First
311+
}
312+
313+
// Build variables for GraphQL query
314+
vars:=map[string]interface{}{
315+
"owner":githubv4.String(owner),
316+
"repo":githubv4.String(repo),
317+
"prNum":githubv4.Int(pullNumber),
318+
"first":githubv4.Int(perPage),
319+
"commentsPerThread":githubv4.Int(50),// Max 50 comments per thread
320+
}
321+
322+
// Add cursor if provided
323+
ifgqlParams.After!=nil&&*gqlParams.After!="" {
324+
vars["after"]=githubv4.String(*gqlParams.After)
325+
}
326+
// Note: when after is nil, we still need to include it in the vars map
327+
// for GraphQL query construction, even though it's nullable
328+
if_,exists:=vars["after"];!exists {
329+
vars["after"]= (*githubv4.String)(nil)
330+
}
331+
332+
// Execute GraphQL query
333+
varqueryreviewThreadsQuery
334+
iferr:=gqlClient.Query(ctx,&query,vars);err!=nil {
335+
returnghErrors.NewGitHubGraphQLErrorResponse(ctx,
336+
"failed to get pull request review threads",
265337
err,
266338
),nil
267339
}
268-
deferfunc() {_=resp.Body.Close() }()
269340

270-
ifresp.StatusCode!=http.StatusOK {
271-
body,err:=io.ReadAll(resp.Body)
272-
iferr!=nil {
273-
returnnil,fmt.Errorf("failed to read response body: %w",err)
274-
}
275-
returnmcp.NewToolResultError(fmt.Sprintf("failed to get pull request review comments: %s",string(body))),nil
341+
// Build response with review threads and pagination info
342+
response:=map[string]interface{}{
343+
"reviewThreads":query.Repository.PullRequest.ReviewThreads.Nodes,
344+
"pageInfo":map[string]interface{}{
345+
"hasNextPage":query.Repository.PullRequest.ReviewThreads.PageInfo.HasNextPage,
346+
"hasPreviousPage":query.Repository.PullRequest.ReviewThreads.PageInfo.HasPreviousPage,
347+
"startCursor":string(query.Repository.PullRequest.ReviewThreads.PageInfo.StartCursor),
348+
"endCursor":string(query.Repository.PullRequest.ReviewThreads.PageInfo.EndCursor),
349+
},
350+
"totalCount":int(query.Repository.PullRequest.ReviewThreads.TotalCount),
276351
}
277352

278-
r,err:=json.Marshal(comments)
353+
r,err:=json.Marshal(response)
279354
iferr!=nil {
280355
returnnil,fmt.Errorf("failed to marshal response: %w",err)
281356
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp