11// @ts -check
22/// <reference types="@actions/github-script" />
33
4- const { AGENT_LOGIN_NAMES , getAvailableAgentLogins, findAgent, getIssueDetails, getPullRequestDetails, assignAgentToIssue, generatePermissionErrorSummary } = require ( "./assign_agent_helpers.cjs" ) ;
4+ const { AGENT_LOGIN_NAMES , getAgentLogins , getAvailableAgentLogins, findAgent, getIssueDetails, getPullRequestDetails, assignAgentToIssue, generatePermissionErrorSummary } = require ( "./assign_agent_helpers.cjs" ) ;
55const { getErrorMessage } = require ( "./error_helpers.cjs" ) ;
66const { resolveTarget, isStagedMode } = require ( "./safe_output_helpers.cjs" ) ;
77const { generateStagedPreview } = require ( "./staged_preview.cjs" ) ;
@@ -327,15 +327,15 @@ async function main(config = {}) {
327327
328328 try {
329329 // Find agent (use cache to avoid repeated lookups)
330- let agentId = agentCache [ agentName ] ;
331- if ( ! agentId ) {
330+ let agentLogin = agentCache [ agentName ] ;
331+ if ( ! agentLogin ) {
332332 core . info ( `Looking for ${ agentName } coding agent...` ) ;
333- agentId = await findAgent ( effectiveOwner , effectiveRepo , agentName , issueNumber || pullNumber , githubClient ) ;
334- if ( ! agentId ) {
333+ agentLogin = await findAgent ( effectiveOwner , effectiveRepo , agentName , issueNumber || pullNumber , githubClient ) ;
334+ if ( ! agentLogin ) {
335335 throw new Error ( `${ agentName } coding agent is not available for this repository` ) ;
336336 }
337- agentCache [ agentName ] = agentId ;
338- core . info ( `Found ${ agentName } coding agent (ID : ${ agentId } )` ) ;
337+ agentCache [ agentName ] = agentLogin ;
338+ core . info ( `Found ${ agentName } coding agent (login : ${ agentLogin } )` ) ;
339339 }
340340
341341 // Get issue or PR details
@@ -371,7 +371,8 @@ async function main(config = {}) {
371371 // Skip if agent is already assigned and no explicit per-item pull_request_repo is specified.
372372 // When a different pull_request_repo is provided on the message, allow re-assignment
373373 // so Copilot can be triggered for a different target repository on the same issue.
374- if ( currentAssignees . some ( a => a . id === agentId ) && ! shouldAllowReassignment ) {
374+ const knownLogins = getAgentLogins ( agentName ) ;
375+ if ( currentAssignees . some ( a => a . login === agentLogin || knownLogins . includes ( a . login ) ) && ! shouldAllowReassignment ) {
375376 core . info ( `${ agentName } is already assigned to ${ type } #${ number } ` ) ;
376377 _allResults . push ( { issue_number : issueNumber , pull_number : pullNumber , agent : agentName , owner : effectiveOwner , repo : effectiveRepo , pull_request_repo : effectivePullRequestRepoSlug , success : true } ) ;
377378 return { success : true } ;
@@ -383,7 +384,7 @@ async function main(config = {}) {
383384 if ( customInstructions ) core . info ( `Using custom instructions: ${ customInstructions . substring ( 0 , 100 ) } ${ customInstructions . length > 100 ? "..." : "" } ` ) ;
384385 if ( effectiveBaseBranch ) core . info ( `Using base branch: ${ effectiveBaseBranch } ` ) ;
385386
386- const success = await assignAgentToIssue ( assignableId , agentId , currentAssignees , agentName , allowedAgents , model , customAgent , customInstructions , effectiveBaseBranch , githubClient , taskContext , effectivePullRequestRepoSlug ) ;
387+ const success = await assignAgentToIssue ( assignableId , agentLogin , currentAssignees , agentName , allowedAgents , model , customAgent , customInstructions , effectiveBaseBranch , githubClient , taskContext , effectivePullRequestRepoSlug ) ;
387388 if ( ! success ) throw new Error ( `Failed to assign ${ agentName } via REST` ) ;
388389
389390 core . info ( `Successfully assigned ${ agentName } coding agent to ${ type } #${ number } ` ) ;
@@ -392,14 +393,42 @@ async function main(config = {}) {
392393 } catch ( error ) {
393394 let errorMessage = getErrorMessage ( error ) ;
394395
396+ // When the agent specified an issue_number that turns out to be a PR, skip
397+ // silently without posting a comment — error comments on PRs are confusing.
398+ if ( /** @type {any } */ error . isPullRequest ) {
399+ core . warning ( `Skipping assign_to_agent for #${ number } : target is a pull request, not an issue.` ) ;
400+ _allResults . push ( {
401+ issue_number : issueNumber ,
402+ pull_number : pullNumber ,
403+ agent : agentName ,
404+ owner : effectiveOwner ,
405+ repo : effectiveRepo ,
406+ pull_request_repo : effectivePullRequestRepoSlug ,
407+ success : false ,
408+ skipped : true ,
409+ error : errorMessage ,
410+ } ) ;
411+ return { success : false , skipped : true , error : errorMessage } ;
412+ }
413+
395414 const isAuthError = [ "Bad credentials" , "Not Authenticated" , "Resource not accessible" , "Insufficient permissions" , "requires authentication" ] . some ( msg => errorMessage . includes ( msg ) ) ;
396415 const isAvailabilityError = errorMessage . includes ( "coding agent is not available for this repository" ) ;
397416
398417 if ( ignoreIfError && ( isAuthError || isAvailabilityError ) ) {
399418 const errorType = isAuthError ? "authentication/permission" : "agent availability" ;
400419 core . warning ( `Agent assignment failed for ${ agentName } on ${ type } #${ number } due to ${ errorType } error. Skipping due to ignore-if-error=true.` ) ;
401420 core . info ( `Error details: ${ errorMessage } ` ) ;
402- _allResults . push ( { issue_number : issueNumber , pull_number : pullNumber , agent : agentName , owner : effectiveOwner , repo : effectiveRepo , pull_request_repo : effectivePullRequestRepoSlug , success : true , skipped : true } ) ;
421+ _allResults . push ( {
422+ issue_number : issueNumber ,
423+ pull_number : pullNumber ,
424+ agent : agentName ,
425+ owner : effectiveOwner ,
426+ repo : effectiveRepo ,
427+ pull_request_repo : effectivePullRequestRepoSlug ,
428+ success : true ,
429+ skipped : true ,
430+ error : errorMessage ,
431+ } ) ;
403432 return { success : true , skipped : true } ;
404433 }
405434
@@ -451,18 +480,24 @@ function getAssignToAgentAssigned() {
451480
452481/**
453482 * Returns the "assignment_errors" output string for step outputs.
454- * Format: "issue:N:agent:error" or "pr:N:agent:error" per failure, newline-separated.
483+ * Format: "issue:N:agent:error" or "pr:N:agent:error" per failure/skipped-with-error,
484+ * newline-separated.
455485 * @returns {string }
456486 */
457487function getAssignToAgentErrors ( ) {
458- return _allResults
459- . filter ( r => ! r . success && ! r . skipped )
460- . map ( r => {
461- const number = r . issue_number || r . pull_number ;
462- const prefix = r . issue_number ? "issue" : "pr" ;
463- return `${ prefix } :${ number } :${ r . agent } :${ r . error } ` ;
464- } )
465- . join ( "\n" ) ;
488+ return (
489+ _allResults
490+ // Include skipped(ignore-if-error) entries that still captured an error so
491+ // downstream failure handling can surface assignment problems in issue/comment reports.
492+ // Include hard failures (!success) and ignored failures (skipped=true with error).
493+ . filter ( r => r . error && ( r . skipped || ! r . success ) )
494+ . map ( r => {
495+ const number = r . issue_number || r . pull_number ;
496+ const prefix = r . issue_number ? "issue" : "pr" ;
497+ return `${ prefix } :${ number } :${ r . agent } :${ r . error } ` ;
498+ } )
499+ . join ( "\n" )
500+ ) ;
466501}
467502
468503/**
0 commit comments