@@ -4,79 +4,60 @@ import path from 'path';
44import { extractTodosFromDir } from './parser/extractTodosFromDir' ;
55import { TodoItem } from './parser/types' ;
66
7+ const LABELS_BY_TAG : Record < string , string [ ] > = {
8+ TODO : [ 'enhancement' ] ,
9+ FIXME : [ 'bug' ] ,
10+ BUG : [ 'bug' ] ,
11+ HACK : [ 'technical-debt' ]
12+ } ;
13+
14+ function labelsFromMetadata ( metadata ?: Record < string , string > ) : string [ ] {
15+ if ( ! metadata ) return [ ] ;
16+ return Object . entries ( metadata ) . map ( ( [ key , value ] ) => `${ key } :${ value } ` ) ;
17+ }
18+
719async function run ( ) : Promise < void > {
8- try {
9- const token = core . getInput ( 'repo-token' , { required : true } ) ;
10- const workspace = process . env . GITHUB_WORKSPACE || '.' ;
11-
12- const todos : TodoItem [ ] = extractTodosFromDir ( workspace ) ;
13- const octokit = github . getOctokit ( token ) ;
14- const { owner, repo } = github . context . repo ;
15-
16- core . info ( `🔍 Found ${ todos . length } TODOs` ) ;
17-
18- // Limit to avoid triggering GitHub's rate limiter
19- const MAX_ISSUES = 5 ;
20-
21- const todosToCreate = todos
22- . filter ( todo => todo . text && todo . text . length > 5 )
23- . slice ( 0 , MAX_ISSUES ) ;
24-
25- for ( const todo of todosToCreate ) {
26- const title = `[${ todo . tag } ] ${ todo . text } ` ;
27- const body = `Found in \`${ todo . file } :${ todo . line } \`\n\n\`\`\`\n${ todo . text } \n\`\`\`` ;
28-
29- try {
30- await octokit . rest . issues . create ( {
31- owner,
32- repo,
33- title,
34- body
35- } ) ;
36-
37- core . info ( `✅ Created issue: ${ title } ` ) ;
38- } catch ( err : any ) {
39- core . warning ( `⚠️ Failed to create issue for: ${ title } — ${ err . message } ` ) ;
40- }
20+ try {
21+ const token = core . getInput ( 'repo-token' , { required : true } ) ;
22+ const workspace = process . env . GITHUB_WORKSPACE || '.' ;
23+
24+ const todos : TodoItem [ ] = extractTodosFromDir ( workspace ) ;
25+ const octokit = github . getOctokit ( token ) ;
26+ const { owner, repo } = github . context . repo ;
27+
28+ core . info ( `🔍 Found ${ todos . length } TODOs` ) ;
29+
30+ const MAX_ISSUES = 5 ;
31+ const todosToCreate = todos
32+ . filter ( todo => todo . text && todo . text . length > 5 )
33+ . slice ( 0 , MAX_ISSUES ) ;
34+
35+ for ( const todo of todosToCreate ) {
36+ const title = `[${ todo . tag } ] ${ todo . text } ` ;
37+ const body = `Found in \`${ todo . file } :${ todo . line } \`\n\n\`\`\`\n${ todo . text } \n\`\`\`` ;
38+ const tag = todo . tag . toUpperCase ( ) ;
39+ const baseLabels = LABELS_BY_TAG [ tag ] || [ 'todo' ] ;
40+ const metaLabels = labelsFromMetadata ( todo . metadata ) ;
41+ const labels = [ ...baseLabels , ...metaLabels ] ;
42+
43+ try {
44+ await octokit . rest . issues . create ( {
45+ owner,
46+ repo,
47+ title,
48+ body,
49+ labels
50+ } ) ;
51+
52+ core . info ( `✅ Created issue with labels [${ labels . join ( ', ' ) } ]: ${ title } ` ) ;
53+ } catch ( err : any ) {
54+ core . warning ( `⚠️ Failed to create issue for: ${ title } — ${ err . message } ` ) ;
4155 }
42-
43- } catch ( error : any ) {
44- core . setFailed ( `Action failed: ${ error . message } ` ) ;
4556 }
46- }
47-
48- run ( ) ;
49-
50-
51-
52- // async function run(): Promise<void> {
53- // try {
54- // const token = core.getInput('repo-token', { required: true });
55- // const workspace = process.env.GITHUB_WORKSPACE || '.';
56-
57- // const todos: TodoItem[] = extractTodosFromDir(workspace);
58- // const octokit = github.getOctokit(token);
59- // const { owner, repo } = github.context.repo;
6057
61- // core.info(`🔍 Found ${todos.length} TODOs`);
62-
63- // for (const todo of todos) {
64- // const title = `[${todo.tag}] ${todo.text}`;
65- // const body = `Found in \`${todo.file}:${todo.line}\`\n\n\`\`\`\n${todo.text}\n\`\`\``;
66-
67- // await octokit.rest.issues.create({
68- // owner,
69- // repo,
70- // title,
71- // body
72- // });
73-
74- // core.info(`✅ Created issue: ${title}`);
75- // }
76-
77- // } catch (error: any) {
78- // core.setFailed(`Action failed: ${error.message}`);
79- // }
80- // }
58+ } catch ( error : any ) {
59+ core . setFailed ( `Action failed: ${ error . message } ` ) ;
60+ }
61+ }
8162
82- // run();
63+ run ( ) ;
0 commit comments