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

Function DeletePendingPullRequestReview

pkg/github/pullrequests.go:1972–2050  ·  view source on GitHub ↗
(ctx context.Context, client *githubv4.Client, params PullRequestReviewWriteParams)

Source from the content-addressed store, hash-verified

1970}
1971
1972func DeletePendingPullRequestReview(ctx context.Context, client *githubv4.Client, params PullRequestReviewWriteParams) (*mcp.CallToolResult, error) {
1973 // First we'll get the current user
1974 var getViewerQuery struct {
1975 Viewer struct {
1976 Login githubv4.String
1977 }
1978 }
1979
1980 if err := client.Query(ctx, &getViewerQuery, nil); err != nil {
1981 return ghErrors.NewGitHubGraphQLErrorResponse(ctx,
1982 "failed to get current user",
1983 err,
1984 ), nil
1985 }
1986
1987 var getLatestReviewForViewerQuery struct {
1988 Repository struct {
1989 PullRequest struct {
1990 Reviews struct {
1991 Nodes []struct {
1992 ID githubv4.ID
1993 State githubv4.PullRequestReviewState
1994 URL githubv4.URI
1995 }
1996 } `graphql:"reviews(first: 1, author: $author)"`
1997 } `graphql:"pullRequest(number: $prNum)"`
1998 } `graphql:"repository(owner: $owner, name: $name)"`
1999 }
2000
2001 vars := map[string]any{
2002 "author": githubv4.String(getViewerQuery.Viewer.Login),
2003 "owner": githubv4.String(params.Owner),
2004 "name": githubv4.String(params.Repo),
2005 "prNum": githubv4.Int(params.PullNumber),
2006 }
2007
2008 if err := client.Query(ctx, &getLatestReviewForViewerQuery, vars); err != nil {
2009 return ghErrors.NewGitHubGraphQLErrorResponse(ctx,
2010 "failed to get latest review for current user",
2011 err,
2012 ), nil
2013 }
2014
2015 // Validate there is one review and the state is pending
2016 if len(getLatestReviewForViewerQuery.Repository.PullRequest.Reviews.Nodes) == 0 {
2017 return utils.NewToolResultError("No pending review found for the viewer"), nil
2018 }
2019
2020 review := getLatestReviewForViewerQuery.Repository.PullRequest.Reviews.Nodes[0]
2021 if review.State != githubv4.PullRequestReviewStatePending {
2022 errText := fmt.Sprintf("The latest review, found at %s is not pending", review.URL)
2023 return utils.NewToolResultError(errText), nil
2024 }
2025
2026 // Prepare the mutation
2027 var deletePullRequestReviewMutation struct {
2028 DeletePullRequestReview struct {
2029 PullRequestReview struct {

Callers 2

PullRequestReviewWriteFunction · 0.85

Calls 4

NewToolResultErrorFunction · 0.92
NewToolResultTextFunction · 0.92
StringMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected