@@ -139,8 +139,8 @@ type CommandExecution = Extract<OrchestrationV2TurnItem, { readonly type: "comma
139139/**
140140 * The change requests a shell command opened: the URLs a host's create command printed, on lines
141141 * of their own unless the host reads its output another way. One the command also names, as
142- * `gh pr view 12` does, existed before it ran. More URLs than create commands means something
143- * else printed some, such as `gh pr list`, so none are taken.
142+ * `gh pr view 12` does, existed before it ran. More of a host's URLs than its create commands
143+ * means something else printed some, such as `gh pr list`, so none of that host's are taken.
144144 */
145145export function changeRequestsCreatedBy ( input : string , output : string ) {
146146 if ( ! CREATE_COMMANDS . some ( ( { command } ) => command . test ( input ) ) ) return [ ] ;
@@ -156,10 +156,11 @@ export function changeRequestsCreatedBy(input: string, output: string) {
156156 const otherScript = shellSegments ( script )
157157 . filter ( ( segment ) => createCommandCount ( shellCode ( segment ) ) === 0 )
158158 . join ( "\n" ) ;
159- const created = new Map < string , ThreadPullRequestKey & { readonly url : string } > ( ) ;
159+ const created : Array < ThreadPullRequestKey & { readonly url : string } > = [ ] ;
160160 for ( const { definition, run } of CREATE_COMMANDS ) {
161- if ( code . match ( run ) === null || definition . changeRequestListCommand ?. test ( otherCommands ) )
162- continue ;
161+ const hostCreates = [ ...code . matchAll ( run ) ] . length ;
162+ if ( hostCreates === 0 || definition . changeRequestListCommand ?. test ( otherCommands ) ) continue ;
163+ const hostCreated = new Map < string , ThreadPullRequestKey & { readonly url : string } > ( ) ;
163164 const printed =
164165 definition . changeRequestCreateOutputUrls ?.( output ) ??
165166 Array . from ( output . matchAll ( URL_LINE ) , ( [ , url = "" ] ) => url ) ;
@@ -172,10 +173,11 @@ export function changeRequestsCreatedBy(input: string, output: string) {
172173 // Quoted text in the other commands counts, as in `printf '.../pull/12'`.
173174 if ( named . test ( otherScript ) ) continue ;
174175 const key = normalizeThreadPullRequestKey ( link ) ;
175- created . set ( threadPullRequestKeyOf ( key ) , { ...key , url } ) ;
176+ hostCreated . set ( threadPullRequestKeyOf ( key ) , { ...key , url } ) ;
176177 }
178+ if ( hostCreated . size <= hostCreates ) created . push ( ...hostCreated . values ( ) ) ;
177179 }
178- return created . size > creates ? [ ] : [ ... created . values ( ) ] ;
180+ return created ;
179181}
180182
181183const isPullRequestProviderError = Schema . is ( PullRequestProviderError ) ;
0 commit comments