@@ -29,9 +29,11 @@ const API_DELAY_MS = 500;
2929 * @param {string } [closeOlderKey] - Optional explicit deduplication key. When set, the
3030 * `gh-aw-close-key` marker is used as the primary search term and exact filter instead
3131 * of the workflow-id / workflow-call-id markers.
32+ * @param {Set<number> } [additionalExcludeNumbers] - Optional set of additional issue numbers
33+ * to exclude from the results (e.g. all issues created in the current run).
3234 * @returns {Promise<Array<{number: number, title: string, html_url: string, labels: Array<{name: string}>, created_at: string}>> } Matching issues
3335 */
34- async function searchOlderIssues ( github , owner , repo , workflowId , excludeNumber , callerWorkflowId , closeOlderKey ) {
36+ async function searchOlderIssues ( github , owner , repo , workflowId , excludeNumber , callerWorkflowId , closeOlderKey , additionalExcludeNumbers ) {
3537 core . info ( `Starting search for older issues in ${ owner } /${ repo } ` ) ;
3638 core . info ( ` Workflow ID: ${ workflowId || "(none)" } ` ) ;
3739 core . info ( ` Exclude issue number: ${ excludeNumber } ` ) ;
@@ -68,6 +70,7 @@ async function searchOlderIssues(github, owner, repo, workflowId, excludeNumber,
6870 const { filtered : filteredItems , counters } = filterByMarker ( {
6971 items : result . data . items ,
7072 excludeNumber,
73+ additionalExcludeNumbers,
7174 exactMarker,
7275 entityType : "issue" ,
7376 additionalFilter : ( item , extra ) => {
@@ -183,16 +186,19 @@ function getCloseOlderIssueMessage({ newIssueUrl, newIssueNumber, workflowName,
183186 * @param {string } runUrl - URL of the workflow run
184187 * @param {string } [callerWorkflowId] - Optional calling workflow identity for precise filtering
185188 * @param {string } [closeOlderKey] - Optional explicit deduplication key for close-older matching
189+ * @param {Set<number> } [currentRunIssueNumbers] - Optional set of issue numbers created in the
190+ * current run. When provided, these issues are excluded from the close-older search so that
191+ * issues created earlier in the same run are never incorrectly closed.
186192 * @returns {Promise<Array<{number: number, html_url: string}>> } List of closed issues
187193 */
188- async function closeOlderIssues ( github , owner , repo , workflowId , newIssue , workflowName , runUrl , callerWorkflowId , closeOlderKey ) {
194+ async function closeOlderIssues ( github , owner , repo , workflowId , newIssue , workflowName , runUrl , callerWorkflowId , closeOlderKey , currentRunIssueNumbers ) {
189195 const result = await closeOlderEntities ( github , owner , repo , workflowId , newIssue , workflowName , runUrl , {
190196 entityType : "issue" ,
191197 entityTypePlural : "issues" ,
192- // Use a closure so callerWorkflowId and closeOlderKey are forwarded to searchOlderIssues
193- // without going through the closeOlderEntities extraArgs mechanism (which appends
194- // excludeNumber last)
195- searchOlderEntities : ( gh , o , r , wid , excludeNumber ) => searchOlderIssues ( gh , o , r , wid , excludeNumber , callerWorkflowId , closeOlderKey ) ,
198+ // Use a closure so callerWorkflowId, closeOlderKey, and currentRunIssueNumbers are
199+ // forwarded to searchOlderIssues without going through the closeOlderEntities
200+ // extraArgs mechanism (which appends excludeNumber last)
201+ searchOlderEntities : ( gh , o , r , wid , excludeNumber ) => searchOlderIssues ( gh , o , r , wid , excludeNumber , callerWorkflowId , closeOlderKey , currentRunIssueNumbers ) ,
196202 getCloseMessage : params =>
197203 getCloseOlderIssueMessage ( {
198204 newIssueUrl : params . newEntityUrl ,
0 commit comments