Skip to content

Commit 51ff1a9

Browse files
committed
Harden atomic issue creation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: f71d9868-eef8-4fb0-84c6-df7c9a6a0ade
1 parent 60c43f9 commit 51ff1a9

3 files changed

Lines changed: 721 additions & 329 deletions

File tree

pkg/github/issues.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2726,11 +2726,13 @@ type createIssueMutation struct {
27262726

27272727
type createIssueParentMetadataQuery struct {
27282728
ChildRepository struct {
2729-
ID githubv4.ID
2729+
ID githubv4.ID
2730+
NameWithOwner githubv4.String
27302731
} `graphql:"childRepository: repository(owner: $owner, name: $repo)"`
27312732
ParentRepository struct {
27322733
Issue struct {
2733-
ID githubv4.ID
2734+
ID githubv4.ID
2735+
Number githubv4.Int
27342736
} `graphql:"issue(number: $parentIssueNumber)"`
27352737
} `graphql:"parentRepository: repository(owner: $parentOwner, name: $parentRepo)"`
27362738
}
@@ -2817,6 +2819,9 @@ func createIssueWithParent(
28172819
if err := gqlClient.Mutate(ctx, &mutation, input, nil); err != nil {
28182820
return ghErrors.NewGitHubGraphQLErrorResponse(ctx, "failed to create issue", err), nil
28192821
}
2822+
if mutation.CreateIssue.Issue.FullDatabaseID == "" || mutation.CreateIssue.Issue.URL.URL == nil {
2823+
return utils.NewToolResultError("failed to create issue: response did not include the created issue"), nil
2824+
}
28202825

28212826
response := MinimalResponse{
28222827
ID: string(mutation.CreateIssue.Issue.FullDatabaseID),
@@ -2861,10 +2866,10 @@ func resolveCreateIssueParent(ctx context.Context, gqlClient *githubv4.Client, o
28612866
if err := gqlClient.Query(ctx, &query, variables); err != nil {
28622867
return "", "", err
28632868
}
2864-
if query.ChildRepository.ID == "" {
2869+
if query.ChildRepository.NameWithOwner == "" {
28652870
return "", "", fmt.Errorf("repository %s/%s was not found", owner, repo)
28662871
}
2867-
if query.ParentRepository.Issue.ID == "" {
2872+
if query.ParentRepository.Issue.Number == 0 {
28682873
return "", "", fmt.Errorf("parent issue #%d was not found in %s/%s", parentIssueNumber, parentOwner, parentRepo)
28692874
}
28702875
return query.ChildRepository.ID, query.ParentRepository.Issue.ID, nil
@@ -2880,7 +2885,7 @@ func resolveUserID(ctx context.Context, gqlClient *githubv4.Client, login string
28802885
if err := gqlClient.Query(ctx, &query, map[string]any{"login": githubv4.String(login)}); err != nil {
28812886
return "", err
28822887
}
2883-
if query.User.ID == "" {
2888+
if query.User.Login == "" {
28842889
return "", fmt.Errorf("user %q was not found", login)
28852890
}
28862891
return query.User.ID, nil
@@ -2890,7 +2895,8 @@ func resolveMilestoneID(ctx context.Context, gqlClient *githubv4.Client, owner,
28902895
var query struct {
28912896
Repository struct {
28922897
Milestone struct {
2893-
ID githubv4.ID
2898+
ID githubv4.ID
2899+
Number githubv4.Int
28942900
} `graphql:"milestone(number: $milestoneNumber)"`
28952901
} `graphql:"repository(owner: $owner, name: $repo)"`
28962902
}
@@ -2902,7 +2908,7 @@ func resolveMilestoneID(ctx context.Context, gqlClient *githubv4.Client, owner,
29022908
if err := gqlClient.Query(ctx, &query, variables); err != nil {
29032909
return "", err
29042910
}
2905-
if query.Repository.Milestone.ID == "" {
2911+
if query.Repository.Milestone.Number == 0 {
29062912
return "", fmt.Errorf("milestone #%d was not found in %s/%s", milestoneNumber, owner, repo)
29072913
}
29082914
return query.Repository.Milestone.ID, nil

pkg/github/issues_create_test.go

Lines changed: 0 additions & 322 deletions
This file was deleted.

0 commit comments

Comments
 (0)