Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions pkg/github/pullrequests.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
"github.com/github/github-mcp-server/pkg/translations"
)

const (
errFailedToGetPullRequest = "failed to get pull request"
)

// GetPullRequest creates a tool to get details of a specific pull request.
func GetPullRequest(getClient GetClientFn, t translations.TranslationHelperFunc) (mcp.Tool, server.ToolHandlerFunc) {
return mcp.NewTool("get_pull_request",
Expand Down Expand Up @@ -59,7 +63,7 @@
pr, resp, err := client.PullRequests.Get(ctx, owner, repo, pullNumber)
if err != nil {
return ghErrors.NewGitHubAPIErrorResponse(ctx,
"failed to get pull request",
errFailedToGetPullRequest,
resp,
err,
), nil
Expand All @@ -71,7 +75,7 @@
if err != nil {
return nil, fmt.Errorf("failed to read response body: %w", err)
}
return mcp.NewToolResultError(fmt.Sprintf("failed to get pull request: %s", string(body))), nil
return mcp.NewToolResultError(fmt.Sprintf("%s: %s", errFailedToGetPullRequest, string(body))), nil
}

r, err := json.Marshal(pr)
Expand Down Expand Up @@ -695,7 +699,7 @@
pr, resp, err := client.PullRequests.Get(ctx, owner, repo, pullNumber)
if err != nil {
return ghErrors.NewGitHubAPIErrorResponse(ctx,
"failed to get pull request",
errFailedToGetPullRequest,
resp,
err,
), nil
Expand All @@ -707,7 +711,7 @@
if err != nil {
return nil, fmt.Errorf("failed to read response body: %w", err)
}
return mcp.NewToolResultError(fmt.Sprintf("failed to get pull request: %s", string(body))), nil
return mcp.NewToolResultError(fmt.Sprintf("%s: %s", errFailedToGetPullRequest, string(body))), nil
}

// Get combined status for the head SHA
Expand Down Expand Up @@ -1014,7 +1018,7 @@

var getPullRequestQuery struct {
Repository struct {
PullRequest struct {

Check warning on line 1021 in pkg/github/pullrequests.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Extract this nested anonymous struct into a named type for better readability and reusability.

See more on https://sonarcloud.io/project/issues?id=COG-GTM_github-mcp-server&issues=AZsO2KZyunsNbwD4gsqS&open=AZsO2KZyunsNbwD4gsqS&pullRequest=68
ID githubv4.ID
} `graphql:"pullRequest(number: $prNum)"`
} `graphql:"repository(owner: $owner, name: $repo)"`
Expand All @@ -1025,7 +1029,7 @@
"prNum": githubv4.Int(params.PullNumber),
}); err != nil {
return ghErrors.NewGitHubGraphQLErrorResponse(ctx,
"failed to get pull request",
errFailedToGetPullRequest,
err,
), nil
}
Expand All @@ -1033,7 +1037,7 @@
// Now we have the GQL ID, we can create a review
var addPullRequestReviewMutation struct {
AddPullRequestReview struct {
PullRequestReview struct {

Check warning on line 1040 in pkg/github/pullrequests.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Extract this nested anonymous struct into a named type for better readability and reusability.

See more on https://sonarcloud.io/project/issues?id=COG-GTM_github-mcp-server&issues=AZsO2KZyunsNbwD4gsqT&open=AZsO2KZyunsNbwD4gsqT&pullRequest=68
ID githubv4.ID // We don't need this, but a selector is required or GQL complains.
}
} `graphql:"addPullRequestReview(input: $input)"`
Expand Down Expand Up @@ -1108,7 +1112,7 @@

var getPullRequestQuery struct {
Repository struct {
PullRequest struct {

Check warning on line 1115 in pkg/github/pullrequests.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Extract this nested anonymous struct into a named type for better readability and reusability.

See more on https://sonarcloud.io/project/issues?id=COG-GTM_github-mcp-server&issues=AZsO2KZyunsNbwD4gsqU&open=AZsO2KZyunsNbwD4gsqU&pullRequest=68
ID githubv4.ID
} `graphql:"pullRequest(number: $prNum)"`
} `graphql:"repository(owner: $owner, name: $repo)"`
Expand All @@ -1119,7 +1123,7 @@
"prNum": githubv4.Int(params.PullNumber),
}); err != nil {
return ghErrors.NewGitHubGraphQLErrorResponse(ctx,
"failed to get pull request",
errFailedToGetPullRequest,
err,
), nil
}
Expand All @@ -1127,7 +1131,7 @@
// Now we have the GQL ID, we can create a pending review
var addPullRequestReviewMutation struct {
AddPullRequestReview struct {
PullRequestReview struct {

Check warning on line 1134 in pkg/github/pullrequests.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Extract this nested anonymous struct into a named type for better readability and reusability.

See more on https://sonarcloud.io/project/issues?id=COG-GTM_github-mcp-server&issues=AZsO2KZyunsNbwD4gsqV&open=AZsO2KZyunsNbwD4gsqV&pullRequest=68
ID githubv4.ID // We don't need this, but a selector is required or GQL complains.
}
} `graphql:"addPullRequestReview(input: $input)"`
Expand Down Expand Up @@ -1247,8 +1251,8 @@

var getLatestReviewForViewerQuery struct {
Repository struct {
PullRequest struct {

Check warning on line 1254 in pkg/github/pullrequests.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Extract this nested anonymous struct into a named type for better readability and reusability.

See more on https://sonarcloud.io/project/issues?id=COG-GTM_github-mcp-server&issues=AZsO2KZyunsNbwD4gsqW&open=AZsO2KZyunsNbwD4gsqW&pullRequest=68
Reviews struct {

Check warning on line 1255 in pkg/github/pullrequests.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Extract this nested anonymous struct into a named type for better readability and reusability.

See more on https://sonarcloud.io/project/issues?id=COG-GTM_github-mcp-server&issues=AZsO2KZyunsNbwD4gsqX&open=AZsO2KZyunsNbwD4gsqX&pullRequest=68
Nodes []struct {
ID githubv4.ID
State githubv4.PullRequestReviewState
Expand All @@ -1266,7 +1270,7 @@
"prNum": githubv4.Int(params.PullNumber),
}

if err := client.Query(context.Background(), &getLatestReviewForViewerQuery, vars); err != nil {

Check warning on line 1273 in pkg/github/pullrequests.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use the available context parameter 'ctx' instead of creating a new background context.

See more on https://sonarcloud.io/project/issues?id=COG-GTM_github-mcp-server&issues=AZsO2KZyunsNbwD4gsqf&open=AZsO2KZyunsNbwD4gsqf&pullRequest=68
return ghErrors.NewGitHubGraphQLErrorResponse(ctx,
"failed to get latest review for current user",
err,
Expand All @@ -1287,7 +1291,7 @@
// Then we can create a new review thread comment on the review.
var addPullRequestReviewThreadMutation struct {
AddPullRequestReviewThread struct {
Thread struct {

Check warning on line 1294 in pkg/github/pullrequests.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Extract this nested anonymous struct into a named type for better readability and reusability.

See more on https://sonarcloud.io/project/issues?id=COG-GTM_github-mcp-server&issues=AZsO2KZyunsNbwD4gsqY&open=AZsO2KZyunsNbwD4gsqY&pullRequest=68
ID githubv4.ID // We don't need this, but a selector is required or GQL complains.
}
} `graphql:"addPullRequestReviewThread(input: $input)"`
Expand Down Expand Up @@ -1384,8 +1388,8 @@

var getLatestReviewForViewerQuery struct {
Repository struct {
PullRequest struct {

Check warning on line 1391 in pkg/github/pullrequests.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Extract this nested anonymous struct into a named type for better readability and reusability.

See more on https://sonarcloud.io/project/issues?id=COG-GTM_github-mcp-server&issues=AZsO2KZyunsNbwD4gsqZ&open=AZsO2KZyunsNbwD4gsqZ&pullRequest=68
Reviews struct {

Check warning on line 1392 in pkg/github/pullrequests.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Extract this nested anonymous struct into a named type for better readability and reusability.

See more on https://sonarcloud.io/project/issues?id=COG-GTM_github-mcp-server&issues=AZsO2KZyunsNbwD4gsqa&open=AZsO2KZyunsNbwD4gsqa&pullRequest=68
Nodes []struct {
ID githubv4.ID
State githubv4.PullRequestReviewState
Expand All @@ -1403,7 +1407,7 @@
"prNum": githubv4.Int(params.PullNumber),
}

if err := client.Query(context.Background(), &getLatestReviewForViewerQuery, vars); err != nil {

Check warning on line 1410 in pkg/github/pullrequests.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use the available context parameter 'ctx' instead of creating a new background context.

See more on https://sonarcloud.io/project/issues?id=COG-GTM_github-mcp-server&issues=AZsO2KZyunsNbwD4gsqg&open=AZsO2KZyunsNbwD4gsqg&pullRequest=68
return ghErrors.NewGitHubGraphQLErrorResponse(ctx,
"failed to get latest review for current user",
err,
Expand All @@ -1424,7 +1428,7 @@
// Prepare the mutation
var submitPullRequestReviewMutation struct {
SubmitPullRequestReview struct {
PullRequestReview struct {

Check warning on line 1431 in pkg/github/pullrequests.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Extract this nested anonymous struct into a named type for better readability and reusability.

See more on https://sonarcloud.io/project/issues?id=COG-GTM_github-mcp-server&issues=AZsO2KZyunsNbwD4gsqb&open=AZsO2KZyunsNbwD4gsqb&pullRequest=68
ID githubv4.ID // We don't need this, but a selector is required or GQL complains.
}
} `graphql:"submitPullRequestReview(input: $input)"`
Expand Down Expand Up @@ -1508,8 +1512,8 @@

var getLatestReviewForViewerQuery struct {
Repository struct {
PullRequest struct {

Check warning on line 1515 in pkg/github/pullrequests.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Extract this nested anonymous struct into a named type for better readability and reusability.

See more on https://sonarcloud.io/project/issues?id=COG-GTM_github-mcp-server&issues=AZsO2KZyunsNbwD4gsqc&open=AZsO2KZyunsNbwD4gsqc&pullRequest=68
Reviews struct {

Check warning on line 1516 in pkg/github/pullrequests.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Extract this nested anonymous struct into a named type for better readability and reusability.

See more on https://sonarcloud.io/project/issues?id=COG-GTM_github-mcp-server&issues=AZsO2KZyunsNbwD4gsqd&open=AZsO2KZyunsNbwD4gsqd&pullRequest=68
Nodes []struct {
ID githubv4.ID
State githubv4.PullRequestReviewState
Expand All @@ -1527,7 +1531,7 @@
"prNum": githubv4.Int(params.PullNumber),
}

if err := client.Query(context.Background(), &getLatestReviewForViewerQuery, vars); err != nil {

Check warning on line 1534 in pkg/github/pullrequests.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use the available context parameter 'ctx' instead of creating a new background context.

See more on https://sonarcloud.io/project/issues?id=COG-GTM_github-mcp-server&issues=AZsO2KZyunsNbwD4gsqh&open=AZsO2KZyunsNbwD4gsqh&pullRequest=68
return ghErrors.NewGitHubGraphQLErrorResponse(ctx,
"failed to get latest review for current user",
err,
Expand All @@ -1548,7 +1552,7 @@
// Prepare the mutation
var deletePullRequestReviewMutation struct {
DeletePullRequestReview struct {
PullRequestReview struct {

Check warning on line 1555 in pkg/github/pullrequests.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Extract this nested anonymous struct into a named type for better readability and reusability.

See more on https://sonarcloud.io/project/issues?id=COG-GTM_github-mcp-server&issues=AZsO2KZyunsNbwD4gsqe&open=AZsO2KZyunsNbwD4gsqe&pullRequest=68
ID githubv4.ID // We don't need this, but a selector is required or GQL complains.
}
} `graphql:"deletePullRequestReview(input: $input)"`
Expand Down