* Finds an existing parent issue for a group, or creates a new one if needed * @param {object} params - Parameters for finding/creating parent issue * @param {object} params.githubClient - Authenticated GitHub client * @param {string} params.groupId - The group identifier * @param {string} param
({ githubClient, groupId, owner, repo, titlePrefix, labels, workflowName, workflowSourceURL, expiresHours = 0 })
| 136 | * @returns {Promise<number|null>} - Parent issue number or null if creation failed |
| 137 | */ |
| 138 | async function findOrCreateParentIssue({ githubClient, groupId, owner, repo, titlePrefix, labels, workflowName, workflowSourceURL, expiresHours = 0 }) { |
| 139 | const markerComment = `<!-- gh-aw-group: ${groupId} -->`; |
| 140 | |
| 141 | // Search for existing parent issue with the group marker |
| 142 | core.info(`Searching for existing parent issue for group: ${groupId}`); |
| 143 | const existingParent = await searchForExistingParent(githubClient, owner, repo, markerComment); |
| 144 | if (existingParent) { |
| 145 | return existingParent; |
| 146 | } |
| 147 | |
| 148 | // No suitable parent issue found, create a new one |
| 149 | core.info(`Creating new parent issue for group: ${groupId}`); |
| 150 | try { |
| 151 | const template = createParentIssueTemplate(groupId, titlePrefix, workflowName, workflowSourceURL, expiresHours); |
| 152 | const { data: parentIssue } = await withRetry( |
| 153 | () => |
| 154 | githubClient.rest.issues.create({ |
| 155 | owner, |
| 156 | repo, |
| 157 | title: template.title, |
| 158 | body: template.body, |
| 159 | labels: labels, |
| 160 | }), |
| 161 | { initialDelayMs: 15000, maxDelayMs: 45000, jitterMs: 10000 }, |
| 162 | `create_parent_issue for group ${groupId}` |
| 163 | ); |
| 164 | |
| 165 | core.info(`Created new parent issue #${parentIssue.number}: ${parentIssue.html_url}`); |
| 166 | return parentIssue.number; |
| 167 | } catch (error) { |
| 168 | core.error(`Failed to create parent issue: ${getErrorMessage(error)}`); |
| 169 | return null; |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | /** |
| 174 | * Creates a parent issue template for grouping sub-issues |
no test coverage detected