11import * as github from '@actions/github' ;
22import * as core from '@actions/core' ;
3+ import fs from 'fs' ;
34import { TodoItem } from '../parser/types' ;
45import { classifyTodoText } from './classifier' ; // Novo: classificador heurístico ou LLM
56
@@ -22,6 +23,24 @@ export const LABEL_COLORS: Record<string, string> = {
2223 doc : '0075ca'
2324} ;
2425
26+ export interface LabelDefinition {
27+ color ?: string ;
28+ description ?: string ;
29+ }
30+
31+ let CUSTOM_LABEL_CONFIG : Record < string , LabelDefinition > = { } ;
32+
33+ export function loadLabelConfig ( path : string ) : void {
34+ try {
35+ const raw = fs . readFileSync ( path , 'utf8' ) ;
36+ CUSTOM_LABEL_CONFIG = JSON . parse ( raw ) ;
37+ core . info ( `\uD83D\uDCC4 Loaded label config from ${ path } ` ) ;
38+ } catch ( err : any ) {
39+ core . warning ( `⚠️ Failed to load label config: ${ err . message } ` ) ;
40+ CUSTOM_LABEL_CONFIG = { } ;
41+ }
42+ }
43+
2544// Fallback para labels metadata:priority, due, etc.
2645export function labelsFromMetadata ( metadata ?: Record < string , string > ) : string [ ] {
2746 if ( ! metadata ) return [ ] ;
@@ -50,13 +69,15 @@ export async function ensureLabelExists(
5069 } catch ( err : any ) {
5170 if ( err . status === 404 ) {
5271 const base = label . split ( ':' ) [ 0 ] ;
53- const color = LABEL_COLORS [ base ] || 'cccccc' ;
72+ const custom = CUSTOM_LABEL_CONFIG [ label ] || CUSTOM_LABEL_CONFIG [ base ] || { } ;
73+ const color = custom . color || LABEL_COLORS [ base ] || 'cccccc' ;
74+ const description = custom . description || 'Auto-created by smart-todo-action' ;
5475 await octokit . rest . issues . createLabel ( {
5576 owner,
5677 repo,
5778 name : label ,
5879 color,
59- description : 'Auto-created by smart-todo-action'
80+ description
6081 } ) ;
6182 core . info ( `🏷️ Created label: ${ label } ` ) ;
6283 } else {
0 commit comments