* Build update data from message * @param {Object} item - The message item * @param {Object} config - Configuration object * @returns {{success: true, data: Object} | {success: false, error: string}} Update data result
(item, config)
| 263 | * @returns {{success: true, data: Object} | {success: false, error: string}} Update data result |
| 264 | */ |
| 265 | function buildDiscussionUpdateData(item, config) { |
| 266 | const updateData = {}; |
| 267 | |
| 268 | if (item.title !== undefined) { |
| 269 | if (config.allow_title !== true) { |
| 270 | return { success: false, error: "Title updates are not allowed by the safe-outputs configuration" }; |
| 271 | } |
| 272 | // Sanitize title for Unicode security (no prefix handling needed for updates) |
| 273 | updateData.title = sanitizeTitle(item.title); |
| 274 | } |
| 275 | if (item.body !== undefined) { |
| 276 | if (config.allow_body !== true) { |
| 277 | return { success: false, error: "Body updates are not allowed by the safe-outputs configuration" }; |
| 278 | } |
| 279 | updateData.body = item.body; |
| 280 | } |
| 281 | |
| 282 | // Handle labels update when allowed |
| 283 | if (config.allow_labels === true && item.labels !== undefined) { |
| 284 | if (!Array.isArray(item.labels)) { |
| 285 | return { success: false, error: "Invalid labels value: must be an array" }; |
| 286 | } |
| 287 | |
| 288 | const limitResult = tryEnforceArrayLimit(item.labels, MAX_LABELS, "labels"); |
| 289 | if (!limitResult.success) { |
| 290 | core.warning(`Discussion update label limit exceeded: ${limitResult.error}`); |
| 291 | return { success: false, error: limitResult.error }; |
| 292 | } |
| 293 | |
| 294 | const allowedLabels = config.allowed_labels || []; |
| 295 | const labelsResult = validateLabels(item.labels, allowedLabels.length > 0 ? allowedLabels : undefined, MAX_LABELS); |
| 296 | if (!labelsResult.valid) { |
| 297 | return { success: false, error: labelsResult.error ?? "Invalid labels" }; |
| 298 | } |
| 299 | |
| 300 | updateData.labels = labelsResult.value ?? []; |
| 301 | } |
| 302 | |
| 303 | // Pass footer config to executeUpdate (default to true) |
| 304 | updateData._includeFooter = parseBoolTemplatable(config.footer, true); |
| 305 | |
| 306 | return { success: true, data: updateData }; |
| 307 | } |
| 308 | |
| 309 | /** |
| 310 | * Format success result for discussion update |
nothing calls this directly
no test coverage detected