(ctx context.Context, client *githubv4.Client, params PullRequestReviewWriteParams)
| 1827 | } |
| 1828 | |
| 1829 | func CreatePullRequestReview(ctx context.Context, client *githubv4.Client, params PullRequestReviewWriteParams) (*mcp.CallToolResult, error) { |
| 1830 | var getPullRequestQuery struct { |
| 1831 | Repository struct { |
| 1832 | PullRequest struct { |
| 1833 | ID githubv4.ID |
| 1834 | } `graphql:"pullRequest(number: $prNum)"` |
| 1835 | } `graphql:"repository(owner: $owner, name: $repo)"` |
| 1836 | } |
| 1837 | |
| 1838 | if err := client.Query(ctx, &getPullRequestQuery, map[string]any{ |
| 1839 | "owner": githubv4.String(params.Owner), |
| 1840 | "repo": githubv4.String(params.Repo), |
| 1841 | "prNum": githubv4.Int(params.PullNumber), |
| 1842 | }); err != nil { |
| 1843 | return ghErrors.NewGitHubGraphQLErrorResponse(ctx, |
| 1844 | "failed to get pull request", |
| 1845 | err, |
| 1846 | ), nil |
| 1847 | } |
| 1848 | |
| 1849 | // Now we have the GQL ID, we can create a review |
| 1850 | var addPullRequestReviewMutation struct { |
| 1851 | AddPullRequestReview struct { |
| 1852 | PullRequestReview struct { |
| 1853 | ID githubv4.ID // We don't need this, but a selector is required or GQL complains. |
| 1854 | } |
| 1855 | } `graphql:"addPullRequestReview(input: $input)"` |
| 1856 | } |
| 1857 | |
| 1858 | addPullRequestReviewInput := githubv4.AddPullRequestReviewInput{ |
| 1859 | PullRequestID: getPullRequestQuery.Repository.PullRequest.ID, |
| 1860 | CommitOID: newGQLStringlikePtr[githubv4.GitObjectID](params.CommitID), |
| 1861 | } |
| 1862 | |
| 1863 | // Event and Body are provided if we submit a review |
| 1864 | if params.Event != "" { |
| 1865 | addPullRequestReviewInput.Event = newGQLStringlike[githubv4.PullRequestReviewEvent](params.Event) |
| 1866 | addPullRequestReviewInput.Body = githubv4.NewString(githubv4.String(params.Body)) |
| 1867 | } |
| 1868 | |
| 1869 | if err := client.Mutate( |
| 1870 | ctx, |
| 1871 | &addPullRequestReviewMutation, |
| 1872 | addPullRequestReviewInput, |
| 1873 | nil, |
| 1874 | ); err != nil { |
| 1875 | return utils.NewToolResultError(err.Error()), nil |
| 1876 | } |
| 1877 | |
| 1878 | // Return nothing interesting, just indicate success for the time being. |
| 1879 | // In future, we may want to return the review ID, but for the moment, we're not leaking |
| 1880 | // API implementation details to the LLM. |
| 1881 | if params.Event == "" { |
| 1882 | return utils.NewToolResultText("pending pull request created"), nil |
| 1883 | } |
| 1884 | return utils.NewToolResultText("pull request review submitted successfully"), nil |
| 1885 | } |
| 1886 |
no test coverage detected