fetchIssueIDs retrieves issue IDs via the GraphQL API. When duplicateOf is 0, it fetches only the main issue ID. When duplicateOf is non-zero, it fetches both the main issue and duplicate issue IDs in a single query.
(ctx context.Context, gqlClient *githubv4.Client, owner, repo string, issueNumber int, duplicateOf int)
| 56 | // When duplicateOf is 0, it fetches only the main issue ID. |
| 57 | // When duplicateOf is non-zero, it fetches both the main issue and duplicate issue IDs in a single query. |
| 58 | func fetchIssueIDs(ctx context.Context, gqlClient *githubv4.Client, owner, repo string, issueNumber int, duplicateOf int) (githubv4.ID, githubv4.ID, error) { |
| 59 | // Build query variables common to both cases |
| 60 | vars := map[string]any{ |
| 61 | "owner": githubv4.String(owner), |
| 62 | "repo": githubv4.String(repo), |
| 63 | "issueNumber": githubv4.Int(issueNumber), // #nosec G115 - issue numbers are always small positive integers |
| 64 | } |
| 65 | |
| 66 | if duplicateOf == 0 { |
| 67 | // Only fetch the main issue ID |
| 68 | var query struct { |
| 69 | Repository struct { |
| 70 | Issue struct { |
| 71 | ID githubv4.ID |
| 72 | } `graphql:"issue(number: $issueNumber)"` |
| 73 | } `graphql:"repository(owner: $owner, name: $repo)"` |
| 74 | } |
| 75 | |
| 76 | if err := gqlClient.Query(ctx, &query, vars); err != nil { |
| 77 | return "", "", fmt.Errorf("failed to get issue ID: %w", err) |
| 78 | } |
| 79 | |
| 80 | return query.Repository.Issue.ID, "", nil |
| 81 | } |
| 82 | |
| 83 | // Fetch both issue IDs in a single query |
| 84 | var query struct { |
| 85 | Repository struct { |
| 86 | Issue struct { |
| 87 | ID githubv4.ID |
| 88 | } `graphql:"issue(number: $issueNumber)"` |
| 89 | DuplicateIssue struct { |
| 90 | ID githubv4.ID |
| 91 | } `graphql:"duplicateIssue: issue(number: $duplicateOf)"` |
| 92 | } `graphql:"repository(owner: $owner, name: $repo)"` |
| 93 | } |
| 94 | |
| 95 | // Add duplicate issue number to variables |
| 96 | vars["duplicateOf"] = githubv4.Int(duplicateOf) // #nosec G115 - issue numbers are always small positive integers |
| 97 | |
| 98 | if err := gqlClient.Query(ctx, &query, vars); err != nil { |
| 99 | return "", "", fmt.Errorf("failed to get issue ID: %w", err) |
| 100 | } |
| 101 | |
| 102 | return query.Repository.Issue.ID, query.Repository.DuplicateIssue.ID, nil |
| 103 | } |
| 104 | |
| 105 | // getCloseStateReason converts a string state reason to the appropriate enum value |
| 106 | func getCloseStateReason(stateReason string) IssueClosedStateReason { |
no test coverage detected