11#!/usr/bin/env bun
22
3- import type { Config } from './types' ;
3+ import type { Config , TodoItem } from './types' ;
44import { extractTodos } from './diff' ;
55import { matchTodos } from './matcher' ;
66import { isSimilar } from './similarity' ;
@@ -72,10 +72,7 @@ async function getDiff(config: Config): Promise<{ diffText: string; resolvedHead
7272
7373 console . log ( `[INFO] Push mode: comparing ${ config . baseSha . slice ( 0 , 7 ) } ...${ config . headSha . slice ( 0 , 7 ) } ` ) ;
7474 return {
75- diffText : await getDiffFromApi (
76- `/repos/${ config . owner } /${ config . repo } /compare/${ config . baseSha } ...${ config . headSha } ` ,
77- config . token ,
78- ) ,
75+ diffText : await getDiffFromApi ( `/repos/${ config . owner } /${ config . repo } /compare/${ config . baseSha } ...${ config . headSha } ` , config . token ) ,
7976 resolvedHeadSha : config . headSha ,
8077 } ;
8178}
@@ -101,24 +98,40 @@ async function run(): Promise<void> {
10198 const existingIssues = await fetchExistingIssues ( config ) ;
10299
103100 if ( config . importAll || config . pathFilter ) {
104- const toCreate = todos . filter ( ( t ) => t . type === 'add' ) . filter ( ( todo ) => {
105- return ! existingIssues . find ( ( i ) => i . title === todo . title || isSimilar ( i . title , todo . title ) ) ;
106- } ) ;
101+ const added = todos
102+ . filter ( ( t ) => t . type === 'add' )
103+ . filter ( ( todo ) => {
104+ return ! existingIssues . find ( ( i ) => i . title === todo . title || isSimilar ( i . title , todo . title ) ) ;
105+ } ) ;
106+
107+ const byTitle = new Map < string , TodoItem [ ] > ( ) ;
108+ for ( const todo of added ) {
109+ const list = byTitle . get ( todo . title ) ?? [ ] ;
110+ list . push ( todo ) ;
111+ byTitle . set ( todo . title , list ) ;
112+ }
107113
108- console . log ( `[INFO] Import: ${ toCreate . length } new issues to create` ) ;
114+ console . log ( `[INFO] Import: ${ byTitle . size } new issues to create ( ${ added . length } TODOs grouped by title) ` ) ;
109115
110- for ( const todo of toCreate ) {
111- await createIssue ( todo , config , resolvedHeadSha ) ;
116+ for ( const group of byTitle . values ( ) ) {
117+ await createIssue ( group , config , resolvedHeadSha ) ;
112118 }
113119 } else {
114120 const { toCreate, toClose, toUpdate, toReference } = matchTodos ( todos , existingIssues ) ;
115121
122+ const createByTitle = new Map < string , TodoItem [ ] > ( ) ;
123+ for ( const todo of toCreate ) {
124+ const list = createByTitle . get ( todo . title ) ?? [ ] ;
125+ list . push ( todo ) ;
126+ createByTitle . set ( todo . title , list ) ;
127+ }
128+
116129 console . log (
117- `[INFO] Actions: ${ toCreate . length } create, ${ toClose . length } close, ${ toUpdate . length } update, ${ toReference . length } reference` ,
130+ `[INFO] Actions: ${ createByTitle . size } create, ${ toClose . length } close, ${ toUpdate . length } update, ${ toReference . length } reference` ,
118131 ) ;
119132
120- for ( const todo of toCreate ) {
121- await createIssue ( todo , config , resolvedHeadSha ) ;
133+ for ( const group of createByTitle . values ( ) ) {
134+ await createIssue ( group , config , resolvedHeadSha ) ;
122135 }
123136
124137 for ( const todo of toClose ) {
0 commit comments