| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -307,6 +307,86 @@ func TestToolsets(t *testing.T) { | |||
| 307 | 307 | require.False(t, toolsContains("pull_request_read"), "expected not to find 'pull_request_read' tool") | |
| 308 | 308 | } | |
| 309 | 309 | ||
| 310 | + func TestCreateIssueWithParent(t *testing.T) { | ||
| 311 | + t.Parallel() | ||
| 312 | + | ||
| 313 | + mcpClient := setupMCPClient(t) | ||
| 314 | + ctx := context.Background() | ||
| 315 | + | ||
| 316 | + t.Log("Getting current user...") | ||
| 317 | + resp, err := mcpClient.CallTool(ctx, &mcp.CallToolParams{Name: "get_me"}) | ||
| 318 | + require.NoError(t, err, "expected to call 'get_me' tool successfully") | ||
| 319 | + require.False(t, resp.IsError, fmt.Sprintf("expected result not to be an error: %+v", resp)) | ||
| 320 | + require.Len(t, resp.Content, 1, "expected content to have one item") | ||
| 321 | + | ||
| 322 | + textContent, ok := resp.Content[0].(*mcp.TextContent) | ||
| 323 | + require.True(t, ok, "expected content to be of type TextContent") | ||
| 324 | + | ||
| 325 | + var trimmedGetMeText struct { | ||
| 326 | + Login string `json:"login"` | ||
| 327 | + } | ||
| 328 | + err = json.Unmarshal([]byte(textContent.Text), &trimmedGetMeText) | ||
| 329 | + require.NoError(t, err, "expected to unmarshal text content successfully") | ||
| 330 | + currentOwner := trimmedGetMeText.Login | ||
| 331 | + | ||
| 332 | + repoName := fmt.Sprintf("github-mcp-server-e2e-%s-%d", t.Name(), time.Now().UnixMilli()) | ||
| 333 | + t.Logf("Creating repository %s/%s...", currentOwner, repoName) | ||
| 334 | + resp, err = mcpClient.CallTool(ctx, &mcp.CallToolParams{ | ||
| 335 | + Name: "create_repository", | ||
| 336 | + Arguments: map[string]any{ | ||
| 337 | + "name": repoName, | ||
| 338 | + "private": true, | ||
| 339 | + "autoInit": true, | ||
| 340 | + }, | ||
| 341 | + }) | ||
| 342 | + require.NoError(t, err, "expected to call 'create_repository' tool successfully") | ||
| 343 | + require.False(t, resp.IsError, fmt.Sprintf("expected result not to be an error: %+v", resp)) | ||
| 344 | + | ||
| 345 | + t.Cleanup(func() { | ||
| 346 | + ghClient := getRESTClient(t) | ||
| 347 | + t.Logf("Deleting repository %s/%s...", currentOwner, repoName) | ||
| 348 | + _, err := ghClient.Repositories.Delete(context.Background(), currentOwner, repoName) | ||
| 349 | + require.NoError(t, err, "expected to delete repository successfully") | ||
| 350 | + }) | ||
| 351 | + | ||
| 352 | + t.Logf("Creating parent issue in %s/%s...", currentOwner, repoName) | ||
| 353 | + resp, err = mcpClient.CallTool(ctx, &mcp.CallToolParams{ | ||
| 354 | + Name: "issue_write", | ||
| 355 | + Arguments: map[string]any{ | ||
| 356 | + "method": "create", | ||
| 357 | + "owner": currentOwner, | ||
| 358 | + "repo": repoName, | ||
| 359 | + "title": "Parent issue", | ||
| 360 | + }, | ||
| 361 | + }) | ||
| 362 | + require.NoError(t, err, "expected to call 'issue_write' tool successfully") | ||
| 363 | + require.False(t, resp.IsError, fmt.Sprintf("expected result not to be an error: %+v", resp)) | ||
| 364 | + | ||
| 365 | + t.Logf("Creating child issue under %s/%s#1...", currentOwner, repoName) | ||
| 366 | + resp, err = mcpClient.CallTool(ctx, &mcp.CallToolParams{ | ||
| 367 | + Name: "issue_write", | ||
| 368 | + Arguments: map[string]any{ | ||
| 369 | + "method": "create", | ||
| 370 | + "owner": currentOwner, | ||
| 371 | + "repo": repoName, | ||
| 372 | + "title": "Child issue", | ||
| 373 | + "parent_issue_number": 1, | ||
| 374 | + }, | ||
| 375 | + }) | ||
| 376 | + require.NoError(t, err, "expected to call 'issue_write' tool successfully") | ||
| 377 | + require.False(t, resp.IsError, fmt.Sprintf("expected result not to be an error: %+v", resp)) | ||
| 378 | + | ||
| 379 | + ghClient := getRESTClient(t) | ||
| 380 | + parentIssue, parentResponse, err := ghClient.Issues.Get(ctx, currentOwner, repoName, 1) | ||
| 381 | + require.NoError(t, err, "expected to get parent issue successfully") | ||
| 382 | + require.Equal(t, http.StatusOK, parentResponse.StatusCode, "expected to get parent issue successfully") | ||
| 383 | + | ||
| 384 | + childIssue, childResponse, err := ghClient.Issues.Get(ctx, currentOwner, repoName, 2) | ||
| 385 | + require.NoError(t, err, "expected to get child issue successfully") | ||
| 386 | + require.Equal(t, http.StatusOK, childResponse.StatusCode, "expected to get child issue successfully") | ||
| 387 | + require.Equal(t, parentIssue.GetURL(), childIssue.GetParentIssueURL(), "expected child issue to reference its parent") | ||
| 388 | + } | ||
| 389 | + | ||
| 310 | 390 | func TestTags(t *testing.T) { | |
| 311 | 391 | t.Parallel() | |
| 312 | 392 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2678,7 +2678,7 @@ Options are: | |||
| 2678 | 2678 | switch method { | |
| 2679 | 2679 | case "create": | |
| 2680 | 2680 | if parentProvided { | |
| 2681 | - result, err := createIssueWithParent(ctx, client, gqlClient, owner, repo, title, body, assignees, labels, milestoneNum, issueType, parentIssueNumber, parentOwner, parentRepo) | ||
| 2681 | + result, err := CreateIssueWithParent(ctx, client, gqlClient, owner, repo, title, body, assignees, labels, milestoneNum, issueType, parentIssueNumber, parentOwner, parentRepo) | ||
| 2682 | 2682 | return result, nil, err | |
| 2683 | 2683 | } | |
| 2684 | 2684 | ||
@@ -2737,7 +2737,8 @@ type createIssueParentMetadataQuery struct { | |||
| 2737 | 2737 | } `graphql:"parentRepository: repository(owner: $parentOwner, name: $parentRepo)"` | |
| 2738 | 2738 | } | |
| 2739 | 2739 | ||
| 2740 | - func createIssueWithParent( | ||
| 2740 | + // CreateIssueWithParent creates an issue and attaches it to its parent in one GraphQL mutation. | ||
| 2741 | + func CreateIssueWithParent( | ||
| 2741 | 2742 | ctx context.Context, | |
| 2742 | 2743 | client *github.Client, | |
| 2743 | 2744 | gqlClient *githubv4.Client, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -214,7 +214,7 @@ func GranularCreateIssue(t translations.TranslationHelperFunc) inventory.ServerT | |||
| 214 | 214 | if err != nil { | |
| 215 | 215 | return utils.NewToolResultErrorFromErr("failed to get GitHub GraphQL client", err), nil, nil | |
| 216 | 216 | } | |
| 217 | - result, err := createIssueWithParent(ctx, client, gqlClient, owner, repo, title, body, nil, nil, 0, "", parentIssueNumber, parentOwner, parentRepo) | ||
| 217 | + result, err := CreateIssueWithParent(ctx, client, gqlClient, owner, repo, title, body, nil, nil, 0, "", parentIssueNumber, parentOwner, parentRepo) | ||
| 218 | 218 | return result, nil, err | |
| 219 | 219 | } | |
| 220 | 220 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments