MCPcopy
hub / github.com/github/github-mcp-server / GetPullRequestReviewComments

Function GetPullRequestReviewComments

pkg/github/pullrequests.go:461–529  ·  view source on GitHub ↗
(ctx context.Context, gqlClient *githubv4.Client, deps ToolDependencies, owner, repo string, pullNumber int, pagination CursorPaginationParams)

Source from the content-addressed store, hash-verified

459}
460
461func GetPullRequestReviewComments(ctx context.Context, gqlClient *githubv4.Client, deps ToolDependencies, owner, repo string, pullNumber int, pagination CursorPaginationParams) (*mcp.CallToolResult, error) {
462 cache, err := deps.GetRepoAccessCache(ctx)
463 if err != nil {
464 return nil, fmt.Errorf("failed to get repo access cache: %w", err)
465 }
466 ff := deps.GetFlags(ctx)
467
468 // Convert pagination parameters to GraphQL format
469 gqlParams, err := pagination.ToGraphQLParams()
470 if err != nil {
471 return utils.NewToolResultError(fmt.Sprintf("invalid pagination parameters: %v", err)), nil
472 }
473
474 // Build variables for GraphQL query
475 vars := map[string]any{
476 "owner": githubv4.String(owner),
477 "repo": githubv4.String(repo),
478 "prNum": githubv4.Int(int32(pullNumber)), //nolint:gosec // pullNumber is controlled by user input validation
479 "first": githubv4.Int(*gqlParams.First),
480 "commentsPerThread": githubv4.Int(100),
481 }
482
483 // Add cursor if provided
484 if gqlParams.After != nil {
485 vars["after"] = githubv4.String(*gqlParams.After)
486 } else {
487 vars["after"] = (*githubv4.String)(nil)
488 }
489
490 // Execute GraphQL query
491 var query reviewThreadsQuery
492 if err := gqlClient.Query(ctx, &query, vars); err != nil {
493 return ghErrors.NewGitHubGraphQLErrorResponse(ctx,
494 "failed to get pull request review threads",
495 err,
496 ), nil
497 }
498
499 // Lockdown mode filtering
500 if ff.LockdownMode {
501 if cache == nil {
502 return nil, fmt.Errorf("lockdown cache is not configured")
503 }
504
505 // Iterate through threads and filter comments
506 for i := range query.Repository.PullRequest.ReviewThreads.Nodes {
507 thread := &query.Repository.PullRequest.ReviewThreads.Nodes[i]
508 filteredComments := make([]reviewCommentNode, 0, len(thread.Comments.Nodes))
509
510 for _, comment := range thread.Comments.Nodes {
511 login := string(comment.Author.Login)
512 if login != "" {
513 isSafeContent, err := cache.IsSafeContent(ctx, login, owner, repo)
514 if err != nil {
515 return nil, fmt.Errorf("failed to check lockdown mode: %w", err)
516 }
517 if isSafeContent {
518 filteredComments = append(filteredComments, comment)

Callers 1

PullRequestReadFunction · 0.85

Calls 8

NewToolResultErrorFunction · 0.92
MarshalledTextResultFunction · 0.85
IsSafeContentMethod · 0.80
GetRepoAccessCacheMethod · 0.65
GetFlagsMethod · 0.65
ToGraphQLParamsMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected