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

Commit5a4338c

Browse files
authored
adding review comments grouped as threads (#1554)
* adding review comments grouped as threads* minor fix* minor edit* update docs* fix docs* increase limit to 100* fixtext
1 parenta48e306 commit5a4338c

File tree

5 files changed

+357
-145
lines changed

5 files changed

+357
-145
lines changed

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ The following sets of tools are available:
991991
2. get_diff - Get the diff of a pull request.
992992
3. get_status - Get status of a head commit in a pull request. This reflects status of builds and checks.
993993
4. get_files - Get the list of files changed in a pull request. Use with pagination parameters to control the number of results returned.
994-
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.
994+
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.
995995
6. get_reviews - Get the reviews on a pull request. When asked for review comments, use get_review_comments method.
996996
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.
997997
(string, required)

‎pkg/github/__toolsnaps__/pull_request_read.snap‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"properties": {
1616
"method": {
1717
"type":"string",
18-
"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",
18+
"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",
1919
"enum": [
2020
"get",
2121
"get_diff",

‎pkg/github/pullrequests.go‎

Lines changed: 115 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
)
2222

2323
// PullRequestRead creates a tool to get details of a specific pull request.
24-
funcPullRequestRead(getClientGetClientFn,cache*lockdown.RepoAccessCache,t translations.TranslationHelperFunc,flagsFeatureFlags) (mcp.Tool, mcp.ToolHandlerFor[map[string]any,any]) {
24+
funcPullRequestRead(getClientGetClientFn,getGQLClientGetGQLClientFn,cache*lockdown.RepoAccessCache,t translations.TranslationHelperFunc,flagsFeatureFlags) (mcp.Tool, mcp.ToolHandlerFor[map[string]any,any]) {
2525
schema:=&jsonschema.Schema{
2626
Type:"object",
2727
Properties:map[string]*jsonschema.Schema{
@@ -33,7 +33,7 @@ Possible options:
3333
2. get_diff - Get the diff of a pull request.
3434
3. get_status - Get status of a head commit in a pull request. This reflects status of builds and checks.
3535
4. get_files - Get the list of files changed in a pull request. Use with pagination parameters to control the number of results returned.
36-
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.
36+
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.
3737
6. get_reviews - Get the reviews on a pull request. When asked for review comments, use get_review_comments method.
3838
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.
3939
`,
@@ -107,7 +107,15 @@ Possible options:
107107
result,err:=GetPullRequestFiles(ctx,client,owner,repo,pullNumber,pagination)
108108
returnresult,nil,err
109109
case"get_review_comments":
110-
result,err:=GetPullRequestReviewComments(ctx,client,cache,owner,repo,pullNumber,pagination,flags)
110+
gqlClient,err:=getGQLClient(ctx)
111+
iferr!=nil {
112+
returnutils.NewToolResultErrorFromErr("failed to get GitHub GQL client",err),nil,nil
113+
}
114+
cursorPagination,err:=OptionalCursorPaginationParams(args)
115+
iferr!=nil {
116+
returnutils.NewToolResultError(err.Error()),nil,nil
117+
}
118+
result,err:=GetPullRequestReviewComments(ctx,gqlClient,cache,owner,repo,pullNumber,cursorPagination,flags)
111119
returnresult,nil,err
112120
case"get_reviews":
113121
result,err:=GetPullRequestReviews(ctx,client,cache,owner,repo,pullNumber,flags)
@@ -282,54 +290,124 @@ func GetPullRequestFiles(ctx context.Context, client *github.Client, owner, repo
282290
returnutils.NewToolResultText(string(r)),nil
283291
}
284292

285-
funcGetPullRequestReviewComments(ctx context.Context,client*github.Client,cache*lockdown.RepoAccessCache,owner,repostring,pullNumberint,paginationPaginationParams,ffFeatureFlags) (*mcp.CallToolResult,error) {
286-
opts:=&github.PullRequestListCommentsOptions{
287-
ListOptions: github.ListOptions{
288-
PerPage:pagination.PerPage,
289-
Page:pagination.Page,
290-
},
293+
// GraphQL types for review threads query
294+
typereviewThreadsQuerystruct {
295+
Repositorystruct {
296+
PullRequeststruct {
297+
ReviewThreadsstruct {
298+
Nodes []reviewThreadNode
299+
PageInfopageInfoFragment
300+
TotalCount githubv4.Int
301+
}`graphql:"reviewThreads(first: $first, after: $after)"`
302+
}`graphql:"pullRequest(number: $prNum)"`
303+
}`graphql:"repository(owner: $owner, name: $repo)"`
304+
}
305+
306+
typereviewThreadNodestruct {
307+
ID githubv4.ID
308+
IsResolved githubv4.Boolean
309+
IsOutdated githubv4.Boolean
310+
IsCollapsed githubv4.Boolean
311+
Commentsstruct {
312+
Nodes []reviewCommentNode
313+
TotalCount githubv4.Int
314+
}`graphql:"comments(first: $commentsPerThread)"`
315+
}
316+
317+
typereviewCommentNodestruct {
318+
ID githubv4.ID
319+
Body githubv4.String
320+
Path githubv4.String
321+
Line*githubv4.Int
322+
Authorstruct {
323+
Login githubv4.String
291324
}
325+
CreatedAt githubv4.DateTime
326+
UpdatedAt githubv4.DateTime
327+
URL githubv4.URI
328+
}
292329

293-
comments,resp,err:=client.PullRequests.ListComments(ctx,owner,repo,pullNumber,opts)
330+
typepageInfoFragmentstruct {
331+
HasNextPage githubv4.Boolean
332+
HasPreviousPage githubv4.Boolean
333+
StartCursor githubv4.String
334+
EndCursor githubv4.String
335+
}
336+
337+
funcGetPullRequestReviewComments(ctx context.Context,gqlClient*githubv4.Client,cache*lockdown.RepoAccessCache,owner,repostring,pullNumberint,paginationCursorPaginationParams,ffFeatureFlags) (*mcp.CallToolResult,error) {
338+
// Convert pagination parameters to GraphQL format
339+
gqlParams,err:=pagination.ToGraphQLParams()
294340
iferr!=nil {
295-
returnghErrors.NewGitHubAPIErrorResponse(ctx,
296-
"failed to get pull request review comments",
297-
resp,
298-
err,
299-
),nil
341+
returnutils.NewToolResultError(fmt.Sprintf("invalid pagination parameters: %v",err)),nil
300342
}
301-
deferfunc() {_=resp.Body.Close() }()
302343

303-
ifresp.StatusCode!=http.StatusOK {
304-
body,err:=io.ReadAll(resp.Body)
305-
iferr!=nil {
306-
returnnil,fmt.Errorf("failed to read response body: %w",err)
307-
}
308-
returnutils.NewToolResultError(fmt.Sprintf("failed to get pull request review comments: %s",string(body))),nil
344+
// Build variables for GraphQL query
345+
vars:=map[string]any{
346+
"owner":githubv4.String(owner),
347+
"repo":githubv4.String(repo),
348+
"prNum":githubv4.Int(int32(pullNumber)),//nolint:gosec // pullNumber is controlled by user input validation
349+
"first":githubv4.Int(*gqlParams.First),
350+
"commentsPerThread":githubv4.Int(100),
351+
}
352+
353+
// Add cursor if provided
354+
ifgqlParams.After!=nil {
355+
vars["after"]=githubv4.String(*gqlParams.After)
356+
}else {
357+
vars["after"]= (*githubv4.String)(nil)
309358
}
310359

360+
// Execute GraphQL query
361+
varqueryreviewThreadsQuery
362+
iferr:=gqlClient.Query(ctx,&query,vars);err!=nil {
363+
returnghErrors.NewGitHubGraphQLErrorResponse(ctx,
364+
"failed to get pull request review threads",
365+
err,
366+
),nil
367+
}
368+
369+
// Lockdown mode filtering
311370
ifff.LockdownMode {
312371
ifcache==nil {
313372
returnnil,fmt.Errorf("lockdown cache is not configured")
314373
}
315-
filteredComments:=make([]*github.PullRequestComment,0,len(comments))
316-
for_,comment:=rangecomments {
317-
user:=comment.GetUser()
318-
ifuser==nil {
319-
continue
320-
}
321-
isSafeContent,err:=cache.IsSafeContent(ctx,user.GetLogin(),owner,repo)
322-
iferr!=nil {
323-
returnutils.NewToolResultError(fmt.Sprintf("failed to check lockdown mode: %v",err)),nil
324-
}
325-
ifisSafeContent {
326-
filteredComments=append(filteredComments,comment)
374+
375+
// Iterate through threads and filter comments
376+
fori:=rangequery.Repository.PullRequest.ReviewThreads.Nodes {
377+
thread:=&query.Repository.PullRequest.ReviewThreads.Nodes[i]
378+
filteredComments:=make([]reviewCommentNode,0,len(thread.Comments.Nodes))
379+
380+
for_,comment:=rangethread.Comments.Nodes {
381+
login:=string(comment.Author.Login)
382+
iflogin!="" {
383+
isSafeContent,err:=cache.IsSafeContent(ctx,login,owner,repo)
384+
iferr!=nil {
385+
returnnil,fmt.Errorf("failed to check lockdown mode: %w",err)
386+
}
387+
ifisSafeContent {
388+
filteredComments=append(filteredComments,comment)
389+
}
390+
}
327391
}
392+
393+
thread.Comments.Nodes=filteredComments
394+
thread.Comments.TotalCount=githubv4.Int(int32(len(filteredComments)))//nolint:gosec // comment count is bounded by API limits
328395
}
329-
comments=filteredComments
330396
}
331397

332-
r,err:=json.Marshal(comments)
398+
// Build response with review threads and pagination info
399+
response:=map[string]any{
400+
"reviewThreads":query.Repository.PullRequest.ReviewThreads.Nodes,
401+
"pageInfo":map[string]any{
402+
"hasNextPage":query.Repository.PullRequest.ReviewThreads.PageInfo.HasNextPage,
403+
"hasPreviousPage":query.Repository.PullRequest.ReviewThreads.PageInfo.HasPreviousPage,
404+
"startCursor":string(query.Repository.PullRequest.ReviewThreads.PageInfo.StartCursor),
405+
"endCursor":string(query.Repository.PullRequest.ReviewThreads.PageInfo.EndCursor),
406+
},
407+
"totalCount":int(query.Repository.PullRequest.ReviewThreads.TotalCount),
408+
}
409+
410+
r,err:=json.Marshal(response)
333411
iferr!=nil {
334412
returnnil,fmt.Errorf("failed to marshal response: %w",err)
335413
}
@@ -697,7 +775,7 @@ func UpdatePullRequest(getClient GetClientFn, getGQLClient GetGQLClientFn, t tra
697775
}`graphql:"repository(owner: $owner, name: $repo)"`
698776
}
699777

700-
err=gqlClient.Query(ctx,&prQuery,map[string]interface{}{
778+
err=gqlClient.Query(ctx,&prQuery,map[string]any{
701779
"owner":githubv4.String(owner),
702780
"repo":githubv4.String(repo),
703781
"prNum":githubv4.Int(pullNumber),// #nosec G115 - pull request numbers are always small positive integers

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp