@@ -11,6 +11,7 @@ const { ERR_NOT_FOUND } = require("./error_codes.cjs");
1111const { createCloseEntityHandler, ISSUE_CONFIG } = require ( "./close_entity_helpers.cjs" ) ;
1212const { loadTemporaryIdMapFromResolved, resolveRepoIssueTarget } = require ( "./temporary_id.cjs" ) ;
1313const { getErrorMessage } = require ( "./error_helpers.cjs" ) ;
14+ const { normalizeIssueIntentMetadata } = require ( "./issue_intents.cjs" ) ;
1415
1516/**
1617 * Parse a `duplicate_of` value into { owner, repo, issueNumber }.
@@ -154,17 +155,32 @@ async function addIssueComment(github, owner, repo, issueNumber, message) {
154155 * @param {string } owner - Repository owner
155156 * @param {string } repo - Repository name
156157 * @param {number } issueNumber - Issue number
157- * @param {string } [ stateReason] - The reason for closing: "COMPLETED", "NOT_PLANNED", or "DUPLICATE"
158+ * @param {string } stateReason - The reason for closing: "COMPLETED", "NOT_PLANNED", or "DUPLICATE"
158159 * @returns {Promise<{number: number, html_url: string, title: string, node_id: string}> } Issue details
159160 */
160- async function closeIssue ( github , owner , repo , issueNumber , stateReason ) {
161- const { data : issue } = await github . rest . issues . update ( {
161+ async function closeIssue ( github , owner , repo , issueNumber , stateReason , intentMetadata , useIssueIntent ) {
162+ const baseParams = {
162163 owner,
163164 repo,
164165 issue_number : issueNumber ,
165166 state : "closed" ,
166167 state_reason : ( stateReason || "COMPLETED" ) . toLowerCase ( ) ,
167- } ) ;
168+ } ;
169+
170+ const hasIntentMetadata = Boolean ( intentMetadata && Object . keys ( intentMetadata ) . length > 0 ) ;
171+ if ( useIssueIntent && hasIntentMetadata ) {
172+ try {
173+ const { data : issue } = await github . request ( "PATCH /repos/{owner}/{repo}/issues/{issue_number}" , {
174+ ...baseParams ,
175+ ...intentMetadata ,
176+ } ) ;
177+ return issue ;
178+ } catch ( error ) {
179+ core . warning ( `Issue-intent close path unavailable, falling back to legacy close path: ${ getErrorMessage ( error ) } ` ) ;
180+ }
181+ }
182+
183+ const { data : issue } = await github . rest . issues . update ( baseParams ) ;
168184
169185 return issue ;
170186}
@@ -176,12 +192,13 @@ async function closeIssue(github, owner, repo, issueNumber, stateReason) {
176192 */
177193async function main ( config = { } ) {
178194 const configStateReason = config . state_reason || "COMPLETED" ;
195+ const issueIntentEnabled = config . issue_intent !== false ;
179196 const requiredLabels = config . required_labels || [ ] ;
180197 const requiredTitlePrefix = config . required_title_prefix || "" ;
181198 const { defaultTargetRepo, allowedRepos } = resolveTargetRepoConfig ( config ) ;
182199 const githubClient = await createAuthenticatedGitHubClient ( config ) ;
183200
184- core . info ( `Close issue configuration: max=${ config . max || 10 } , state_reason=${ configStateReason } ` ) ;
201+ core . info ( `Close issue configuration: max=${ config . max || 10 } , state_reason=${ configStateReason } , issue_intent= ${ issueIntentEnabled } ` ) ;
185202 if ( requiredLabels . length > 0 ) {
186203 core . info ( `Required labels: ${ requiredLabels . join ( ", " ) } ` ) ;
187204 }
@@ -265,9 +282,10 @@ async function main(config = {}) {
265282 closeEntity ( github , owner , repo , entityNumber , item ) {
266283 // Support item-level state_reason override, falling back to config-level default
267284 const stateReason = item . state_reason || configStateReason ;
285+ const intentMetadata = issueIntentEnabled ? normalizeIssueIntentMetadata ( item ) : { } ;
268286 core . info ( `Closing issue #${ entityNumber } with state_reason=${ stateReason } ` ) ;
269287
270- const closePromise = closeIssue ( github , owner , repo , entityNumber , stateReason ) ;
288+ const closePromise = closeIssue ( github , owner , repo , entityNumber , stateReason , intentMetadata , issueIntentEnabled ) ;
271289
272290 // When duplicate_of is provided and state_reason is DUPLICATE, create the native duplicate relationship
273291 const stateReasonUpper = stateReason . toUpperCase ( ) ;
0 commit comments