Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Address atomic issue creation review
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: f71d9868-eef8-4fb0-84c6-df7c9a6a0ade
  • Loading branch information
zwick committed Aug 24, 2026
commit 4bf240f70228c7a54cfccc99b70f3dbe5b8ace18
80 changes: 80 additions & 0 deletions e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,86 @@ func TestToolsets(t *testing.T) {
require.False(t, toolsContains("pull_request_read"), "expected not to find 'pull_request_read' tool")
}

func TestCreateIssueWithParent(t *testing.T) {
t.Parallel()

mcpClient := setupMCPClient(t)
ctx := context.Background()

t.Log("Getting current user...")
resp, err := mcpClient.CallTool(ctx, &mcp.CallToolParams{Name: "get_me"})
require.NoError(t, err, "expected to call 'get_me' tool successfully")
require.False(t, resp.IsError, fmt.Sprintf("expected result not to be an error: %+v", resp))
require.Len(t, resp.Content, 1, "expected content to have one item")

textContent, ok := resp.Content[0].(*mcp.TextContent)
require.True(t, ok, "expected content to be of type TextContent")

var trimmedGetMeText struct {
Login string `json:"login"`
}
err = json.Unmarshal([]byte(textContent.Text), &trimmedGetMeText)
require.NoError(t, err, "expected to unmarshal text content successfully")
currentOwner := trimmedGetMeText.Login

repoName := fmt.Sprintf("github-mcp-server-e2e-%s-%d", t.Name(), time.Now().UnixMilli())
t.Logf("Creating repository %s/%s...", currentOwner, repoName)
resp, err = mcpClient.CallTool(ctx, &mcp.CallToolParams{
Name: "create_repository",
Arguments: map[string]any{
"name": repoName,
"private": true,
"autoInit": true,
},
})
require.NoError(t, err, "expected to call 'create_repository' tool successfully")
require.False(t, resp.IsError, fmt.Sprintf("expected result not to be an error: %+v", resp))

t.Cleanup(func() {
ghClient := getRESTClient(t)
t.Logf("Deleting repository %s/%s...", currentOwner, repoName)
_, err := ghClient.Repositories.Delete(context.Background(), currentOwner, repoName)
require.NoError(t, err, "expected to delete repository successfully")
})

t.Logf("Creating parent issue in %s/%s...", currentOwner, repoName)
resp, err = mcpClient.CallTool(ctx, &mcp.CallToolParams{
Name: "issue_write",
Arguments: map[string]any{
"method": "create",
"owner": currentOwner,
"repo": repoName,
"title": "Parent issue",
},
})
require.NoError(t, err, "expected to call 'issue_write' tool successfully")
require.False(t, resp.IsError, fmt.Sprintf("expected result not to be an error: %+v", resp))

t.Logf("Creating child issue under %s/%s#1...", currentOwner, repoName)
resp, err = mcpClient.CallTool(ctx, &mcp.CallToolParams{
Name: "issue_write",
Arguments: map[string]any{
"method": "create",
"owner": currentOwner,
"repo": repoName,
"title": "Child issue",
"parent_issue_number": 1,
},
})
require.NoError(t, err, "expected to call 'issue_write' tool successfully")
require.False(t, resp.IsError, fmt.Sprintf("expected result not to be an error: %+v", resp))

ghClient := getRESTClient(t)
parentIssue, parentResponse, err := ghClient.Issues.Get(ctx, currentOwner, repoName, 1)
require.NoError(t, err, "expected to get parent issue successfully")
require.Equal(t, http.StatusOK, parentResponse.StatusCode, "expected to get parent issue successfully")

childIssue, childResponse, err := ghClient.Issues.Get(ctx, currentOwner, repoName, 2)
require.NoError(t, err, "expected to get child issue successfully")
require.Equal(t, http.StatusOK, childResponse.StatusCode, "expected to get child issue successfully")
require.Equal(t, parentIssue.GetURL(), childIssue.GetParentIssueURL(), "expected child issue to reference its parent")
}

func TestTags(t *testing.T) {
t.Parallel()

Expand Down
5 changes: 3 additions & 2 deletions pkg/github/issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -2678,7 +2678,7 @@ Options are:
switch method {
case "create":
if parentProvided {
result, err := createIssueWithParent(ctx, client, gqlClient, owner, repo, title, body, assignees, labels, milestoneNum, issueType, parentIssueNumber, parentOwner, parentRepo)
result, err := CreateIssueWithParent(ctx, client, gqlClient, owner, repo, title, body, assignees, labels, milestoneNum, issueType, parentIssueNumber, parentOwner, parentRepo)
return result, nil, err
Comment thread
zwick marked this conversation as resolved.
}

Expand Down Expand Up @@ -2737,7 +2737,8 @@ type createIssueParentMetadataQuery struct {
} `graphql:"parentRepository: repository(owner: $parentOwner, name: $parentRepo)"`
}

func createIssueWithParent(
// CreateIssueWithParent creates an issue and attaches it to its parent in one GraphQL mutation.
func CreateIssueWithParent(
ctx context.Context,
client *github.Client,
gqlClient *githubv4.Client,
Expand Down
2 changes: 1 addition & 1 deletion pkg/github/issues_granular.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func GranularCreateIssue(t translations.TranslationHelperFunc) inventory.ServerT
if err != nil {
return utils.NewToolResultErrorFromErr("failed to get GitHub GraphQL client", err), nil, nil
}
result, err := createIssueWithParent(ctx, client, gqlClient, owner, repo, title, body, nil, nil, 0, "", parentIssueNumber, parentOwner, parentRepo)
result, err := CreateIssueWithParent(ctx, client, gqlClient, owner, repo, title, body, nil, nil, 0, "", parentIssueNumber, parentOwner, parentRepo)
return result, nil, err
}

Expand Down
Loading