MCPcopy Index your code
hub / github.com/github/github-mcp-server / AddCommentToPendingReviewCall

Function AddCommentToPendingReviewCall

pkg/github/pullrequests.go:2121–2211  ·  view source on GitHub ↗

AddCommentToPendingReviewCall adds a review comment to the viewer's pending pull request review.

(ctx context.Context, client *githubv4.Client, params AddCommentToPendingReviewParams)

Source from the content-addressed store, hash-verified

2119
2120// AddCommentToPendingReviewCall adds a review comment to the viewer's pending pull request review.
2121func AddCommentToPendingReviewCall(ctx context.Context, client *githubv4.Client, params AddCommentToPendingReviewParams) (*mcp.CallToolResult, error) {
2122 // Get the current user
2123 var getViewerQuery struct {
2124 Viewer struct {
2125 Login githubv4.String
2126 }
2127 }
2128
2129 if err := client.Query(ctx, &getViewerQuery, nil); err != nil {
2130 return ghErrors.NewGitHubGraphQLErrorResponse(ctx,
2131 "failed to get current user",
2132 err,
2133 ), nil
2134 }
2135
2136 var getLatestReviewForViewerQuery struct {
2137 Repository struct {
2138 PullRequest struct {
2139 Reviews struct {
2140 Nodes []struct {
2141 ID githubv4.ID
2142 State githubv4.PullRequestReviewState
2143 URL githubv4.URI
2144 }
2145 } `graphql:"reviews(first: 1, author: $author)"`
2146 } `graphql:"pullRequest(number: $prNum)"`
2147 } `graphql:"repository(owner: $owner, name: $name)"`
2148 }
2149
2150 vars := map[string]any{
2151 "author": githubv4.String(getViewerQuery.Viewer.Login),
2152 "owner": githubv4.String(params.Owner),
2153 "name": githubv4.String(params.Repo),
2154 "prNum": githubv4.Int(params.PullNumber),
2155 }
2156
2157 if err := client.Query(ctx, &getLatestReviewForViewerQuery, vars); err != nil {
2158 return ghErrors.NewGitHubGraphQLErrorResponse(ctx,
2159 "failed to get latest review for current user",
2160 err,
2161 ), nil
2162 }
2163
2164 // Validate there is one review and the state is pending
2165 if len(getLatestReviewForViewerQuery.Repository.PullRequest.Reviews.Nodes) == 0 {
2166 return utils.NewToolResultError("No pending review found for the viewer"), nil
2167 }
2168
2169 review := getLatestReviewForViewerQuery.Repository.PullRequest.Reviews.Nodes[0]
2170 if review.State != githubv4.PullRequestReviewStatePending {
2171 errText := fmt.Sprintf("The latest review, found at %s is not pending", review.URL)
2172 return utils.NewToolResultError(errText), nil
2173 }
2174
2175 // Create a new review thread comment on the review.
2176 var addPullRequestReviewThreadMutation struct {
2177 AddPullRequestReviewThread struct {
2178 Thread struct {

Callers 2

Calls 5

NewToolResultErrorFunction · 0.92
NewToolResultTextFunction · 0.92
newGQLIntPtrFunction · 0.85
StringMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected