* Fetches label node IDs for the given label names * @param {string} owner - Repository owner * @param {string} repo - Repository name * @param {string[]} labelNames - Array of label names to fetch IDs for * @returns {Promise >} Array of label objects with name a
(githubClient, owner, repo, labelNames)
| 135 | * @returns {Promise<Array<{name: string, id: string}>>} Array of label objects with name and ID |
| 136 | */ |
| 137 | async function fetchLabelIds(githubClient, owner, repo, labelNames) { |
| 138 | if (!labelNames || labelNames.length === 0) { |
| 139 | return []; |
| 140 | } |
| 141 | |
| 142 | try { |
| 143 | const allLabels = await fetchAllRepoLabels(githubClient, owner, repo); |
| 144 | const labelMap = new Map(allLabels.map(label => [label.name.toLowerCase(), label])); |
| 145 | |
| 146 | // Match requested labels (case-insensitive) |
| 147 | const matchedLabels = []; |
| 148 | const unmatchedLabels = []; |
| 149 | |
| 150 | for (const requestedLabel of labelNames) { |
| 151 | const normalizedName = requestedLabel.toLowerCase(); |
| 152 | const matchedLabel = labelMap.get(normalizedName); |
| 153 | if (matchedLabel) { |
| 154 | matchedLabels.push({ name: matchedLabel.name, id: matchedLabel.id }); |
| 155 | } else { |
| 156 | unmatchedLabels.push(requestedLabel); |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | if (unmatchedLabels.length > 0) { |
| 161 | core.warning(`Could not find label IDs for: ${unmatchedLabels.join(", ")}`); |
| 162 | const MAX_DISPLAY = 20; |
| 163 | const displayedLabels = allLabels.slice(0, MAX_DISPLAY).map(l => l.name); |
| 164 | const truncationNote = allLabels.length > MAX_DISPLAY ? ` … (${allLabels.length} total)` : ""; |
| 165 | core.info(`These labels may not exist in the repository. Available labels: ${displayedLabels.join(", ")}${truncationNote}`); |
| 166 | } |
| 167 | |
| 168 | return matchedLabels; |
| 169 | } catch (error) { |
| 170 | core.warning(`Failed to fetch label IDs: ${getErrorMessage(error)}`); |
| 171 | return []; |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * Applies labels to a discussion using GraphQL |
no test coverage detected