(t *testing.T)
| 840 | } |
| 841 | |
| 842 | func TestRequestCopilotReview(t *testing.T) { |
| 843 | t.Parallel() |
| 844 | |
| 845 | if getE2EHost() != "" && getE2EHost() != "https://github.com" { |
| 846 | t.Skip("Skipping test because the host does not support copilot reviews") |
| 847 | } |
| 848 | |
| 849 | mcpClient := setupMCPClient(t) |
| 850 | ctx := context.Background() |
| 851 | |
| 852 | // First, who am I |
| 853 | |
| 854 | t.Log("Getting current user...") |
| 855 | resp, err := mcpClient.CallTool(ctx, &mcp.CallToolParams{Name: "get_me"}) |
| 856 | require.NoError(t, err, "expected to call 'get_me' tool successfully") |
| 857 | require.False(t, resp.IsError, fmt.Sprintf("expected result not to be an error: %+v", resp)) |
| 858 | |
| 859 | require.False(t, resp.IsError, "expected result not to be an error") |
| 860 | require.Len(t, resp.Content, 1, "expected content to have one item") |
| 861 | |
| 862 | textContent, ok := resp.Content[0].(*mcp.TextContent) |
| 863 | require.True(t, ok, "expected content to be of type TextContent") |
| 864 | |
| 865 | var trimmedGetMeText struct { |
| 866 | Login string `json:"login"` |
| 867 | } |
| 868 | err = json.Unmarshal([]byte(textContent.Text), &trimmedGetMeText) |
| 869 | require.NoError(t, err, "expected to unmarshal text content successfully") |
| 870 | |
| 871 | currentOwner := trimmedGetMeText.Login |
| 872 | |
| 873 | // Then create a repository with a README (via autoInit) |
| 874 | repoName := fmt.Sprintf("github-mcp-server-e2e-%s-%d", t.Name(), time.Now().UnixMilli()) |
| 875 | |
| 876 | t.Logf("Creating repository %s/%s...", currentOwner, repoName) |
| 877 | _, err = mcpClient.CallTool(ctx, &mcp.CallToolParams{ |
| 878 | Name: "create_repository", |
| 879 | Arguments: map[string]any{ |
| 880 | "name": repoName, |
| 881 | "private": true, |
| 882 | "autoInit": true, |
| 883 | }, |
| 884 | }) |
| 885 | require.NoError(t, err, "expected to call 'create_repository' tool successfully") |
| 886 | require.False(t, resp.IsError, fmt.Sprintf("expected result not to be an error: %+v", resp)) |
| 887 | |
| 888 | // Cleanup the repository after the test |
| 889 | t.Cleanup(func() { |
| 890 | // MCP Server doesn't support deletions, but we can use the GitHub Client |
| 891 | ghClient := gogithub.NewClient(nil).WithAuthToken(getE2EToken(t)) |
| 892 | t.Logf("Deleting repository %s/%s...", currentOwner, repoName) |
| 893 | _, err := ghClient.Repositories.Delete(context.Background(), currentOwner, repoName) |
| 894 | require.NoError(t, err, "expected to delete repository successfully") |
| 895 | }) |
| 896 | |
| 897 | // Create a branch on which to create a new commit |
| 898 | |
| 899 | t.Logf("Creating branch in %s/%s...", currentOwner, repoName) |
nothing calls this directly
no test coverage detected