* Process close entity items from agent output * @param {EntityConfig} config - Entity configuration * @param {EntityCallbacks} callbacks - Entity-specific API callbacks * @param {Object} handlerConfig - Handler-specific configuration object * @returns {Promise<Array<{entity: {number: number, ht
(config, callbacks, handlerConfig = {})
| 462 | * @returns {Promise<Array<{entity: {number: number, html_url: string, title: string}, comment: {id: number, html_url: string}}>|undefined>} |
| 463 | */ |
| 464 | async function processCloseEntityItems(config, callbacks, handlerConfig = {}) { |
| 465 | // Check if we're in staged mode |
| 466 | const isStaged = isStagedMode(handlerConfig); |
| 467 | |
| 468 | const result = loadAgentOutput(); |
| 469 | if (!result.success) { |
| 470 | return; |
| 471 | } |
| 472 | |
| 473 | // Find all items of this type |
| 474 | const items = result.items.filter(/** @param {any} item */ item => item.type === config.itemType); |
| 475 | if (items.length === 0) { |
| 476 | core.info(`No ${config.itemTypeDisplay} items found in agent output`); |
| 477 | return; |
| 478 | } |
| 479 | |
| 480 | core.info(`Found ${items.length} ${config.itemTypeDisplay} item(s)`); |
| 481 | |
| 482 | // Get configuration from handlerConfig object (not environment variables) |
| 483 | const requiredLabels = handlerConfig.required_labels || []; |
| 484 | const requiredTitlePrefix = handlerConfig.required_title_prefix || ""; |
| 485 | const target = handlerConfig.target || "triggering"; |
| 486 | |
| 487 | core.info(`Configuration: requiredLabels=${requiredLabels.join(",")}, requiredTitlePrefix=${requiredTitlePrefix}, target=${target}`); |
| 488 | |
| 489 | // Check if we're in the correct entity context |
| 490 | const isEntityContext = config.contextEvents.some(event => context.eventName === event); |
| 491 | |
| 492 | // If in staged mode, emit step summary instead of closing entities |
| 493 | if (isStaged) { |
| 494 | await generateCloseEntityStagedPreview(config, items, requiredLabels, requiredTitlePrefix); |
| 495 | return; |
| 496 | } |
| 497 | |
| 498 | // Validate context based on target configuration |
| 499 | if (target === "triggering" && !isEntityContext) { |
| 500 | core.info(`Target is "triggering" but not running in ${config.displayName} context, skipping ${config.displayName} close`); |
| 501 | return; |
| 502 | } |
| 503 | |
| 504 | // Extract triggering context for footer generation |
| 505 | const triggeringIssueNumber = context.payload?.issue?.number; |
| 506 | const triggeringPRNumber = context.payload?.pull_request?.number; |
| 507 | |
| 508 | const closedEntities = []; |
| 509 | |
| 510 | // Process each item |
| 511 | for (let i = 0; i < items.length; i++) { |
| 512 | const item = items[i]; |
| 513 | core.info(`Processing ${config.itemTypeDisplay} item ${i + 1}/${items.length}: bodyLength=${item.body.length}`); |
| 514 | |
| 515 | // Resolve entity number |
| 516 | const resolved = resolveEntityNumber(config, target, item, isEntityContext); |
| 517 | if (!resolved.success) { |
| 518 | core.info(resolved.message); |
| 519 | continue; |
| 520 | } |
| 521 | const entityNumber = resolved.number; |
nothing calls this directly
no test coverage detected