11import * as core from '@actions/core' ;
22import * as github from '@actions/github' ;
33import { TodoItem } from '../parser/types' ;
4- import {
5- LABELS_BY_TAG ,
6- labelsFromMetadata ,
7- ensureLabelExists ,
8- labelsFromTodo // ⬅️ novo
9- } from './labelManager' ;
4+ import { LABELS_BY_TAG , labelsFromMetadata , ensureLabelExists , labelsFromTodo } from './labelManager' ;
105import { loadTemplate , applyTemplate } from '../templates/utils' ;
6+ import { generateIssueTitleAndBodyLLM } from './llm/generateIssueContent' ;
117
128export async function getExistingIssueTitles (
139 octokit : ReturnType < typeof github . getOctokit > ,
@@ -45,50 +41,64 @@ export async function getExistingIssueTitles(
4541}
4642
4743export async function createIssueIfNeeded (
48- octokit : ReturnType < typeof github . getOctokit > ,
49- owner : string ,
50- repo : string ,
51- todo : TodoItem ,
52- existingTitles : Set < string > ,
53- titlePath ?: string ,
54- bodyPath ?: string
55- ) : Promise < void > {
56- const titleTemplate = loadTemplate ( 'issueTitle.txt' ) ;
57- const bodyTemplate = loadTemplate ( 'issueBody.md' ) ;
58-
59- const flattened = {
60- ...todo ,
61- ...todo . metadata
62- } as Record < string , string | number > ;
63-
64- const title = applyTemplate ( titleTemplate , flattened ) ;
65- const body = applyTemplate ( bodyTemplate , flattened ) ;
66-
67-
68- if ( existingTitles . has ( title ) ) {
69- core . info ( `🟡 Skipping duplicate issue: ${ title } ` ) ;
70- return ;
71- }
72-
73- const labels = labelsFromTodo ( todo ) ;
44+ octokit : ReturnType < typeof github . getOctokit > ,
45+ owner : string ,
46+ repo : string ,
47+ todo : TodoItem ,
48+ existingTitles : Set < string > ,
49+ titlePath ?: string ,
50+ bodyPath ?: string
51+ ) : Promise < void > {
52+ const useLLM = core . getInput ( 'llm' ) === 'true' ;
7453
75-
76- for ( const label of labels ) {
77- await ensureLabelExists ( octokit , owner , repo , label ) ;
78- }
79-
54+ let title : string ;
55+ let body : string ;
56+
57+ if ( useLLM ) {
8058 try {
81- await octokit . rest . issues . create ( {
82- owner,
83- repo,
84- title,
85- body,
86- labels
87- } ) ;
88-
89- core . info ( `✅ Created issue with labels [${ labels . join ( ', ' ) } ]: ${ title } ` ) ;
59+ const result = await generateIssueTitleAndBodyLLM ( todo ) ;
60+ title = result . title ;
61+ body = result . body ;
9062 } catch ( err : any ) {
91- core . warning ( `⚠️ Failed to create issue for: ${ title } — ${ err . message } ` ) ;
63+ core . warning ( `⚠️ LLM fallback triggered for TODO: ${ todo . text } ` ) ;
64+ const titleTemplate = loadTemplate ( titlePath || 'issueTitle.txt' ) ;
65+ const bodyTemplate = loadTemplate ( bodyPath || 'issueBody.md' ) ;
66+ const flattened = { ...todo , ...todo . metadata } as Record < string , string | number > ;
67+ title = applyTemplate ( titleTemplate , flattened ) ;
68+ body = applyTemplate ( bodyTemplate , flattened ) ;
9269 }
70+ } else {
71+ const titleTemplate = loadTemplate ( titlePath || 'issueTitle.txt' ) ;
72+ const bodyTemplate = loadTemplate ( bodyPath || 'issueBody.md' ) ;
73+ const flattened = { ...todo , ...todo . metadata } as Record < string , string | number > ;
74+ title = applyTemplate ( titleTemplate , flattened ) ;
75+ body = applyTemplate ( bodyTemplate , flattened ) ;
76+ }
77+
78+ if ( existingTitles . has ( title ) ) {
79+ core . info ( `🟡 Skipping duplicate issue: ${ title } ` ) ;
80+ return ;
81+ }
82+
83+ const labels = labelsFromTodo ( todo ) ;
84+
85+ for ( const label of labels ) {
86+ await ensureLabelExists ( octokit , owner , repo , label ) ;
9387 }
88+
89+ try {
90+ await octokit . rest . issues . create ( {
91+ owner,
92+ repo,
93+ title,
94+ body,
95+ labels
96+ } ) ;
97+
98+ core . info ( `✅ Created issue with labels [${ labels . join ( ', ' ) } ]: ${ title } ` ) ;
99+ } catch ( err : any ) {
100+ core . warning ( `⚠️ Failed to create issue for: ${ title } — ${ err . message } ` ) ;
101+ }
102+ }
103+
94104
0 commit comments