Skip to content

Commit fc08155

Browse files
Merge pull request #184 from DiogoRibeiro7/codex/test-repo-functionality
Add customizable label configuration
2 parents 10d2c76 + a0a260b commit fc08155

File tree

8 files changed

+4328
-2702
lines changed

8 files changed

+4328
-2702
lines changed

.yarnrc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nodeLinker: node-modules

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ A GitHub Action that scans your codebase for inline TODOs, FIXMEs, and BUG comme
1111
- ✅ Extracts metadata like `priority`, `due`, etc.
1212
- ✅ Automatically labels issues based on type and metadata
1313
- ✅ Creates labels on the fly if they don't exist
14+
- ✅ Supports custom label colors and descriptions via JSON config
1415

1516
---
1617

@@ -75,8 +76,9 @@ If a label like `priority:high` or `due:2025-06-01` doesn't exist, it will be au
7576
## 📌 Notes
7677

7778
- Max **5 issues** are created per run to avoid rate limiting (configurable via the `limit` input)
78-
- **Duplicate detection** is not yet implemented _(coming soon)_
79-
- All labels are **auto-created with default colors** if missing
79+
- **Duplicate detection** is not yet implemented _(coming soon)_
80+
- All labels are **auto-created with default colors** if missing
81+
- Provide a JSON file via `label-config` to override colors and descriptions
8082

8183
---
8284

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ inputs:
3030
required: false
3131
description: Optional path to custom issue body template
3232

33+
label-config:
34+
required: false
35+
description: Optional path to JSON file with custom label colors and descriptions
36+
3337
llm:
3438
required: false
3539
description: Use LLM to generate issue titles and bodies

src/ActionMain.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { extractTodosWithStructuredTagsFromDir } from './parser/extractTodosWith
77
import { TodoItem } from './parser/types';
88
import { getExistingIssueTitles, createIssueIfNeeded } from './core/issueManager';
99
import { generateMarkdownReport, warnOverdueTodos } from './core/report';
10+
import { loadLabelConfig } from './core/labelManager';
1011
import { limitTodos, todoKey } from './core/todoUtils';
1112
import { generateChangelogFromTodos } from './core/changelog';
1213

@@ -18,6 +19,7 @@ async function run(): Promise<void> {
1819
const generateReport = core.getInput('report') === 'true';
1920
const titleTemplatePath = core.getInput('issue-title-template');
2021
const bodyTemplatePath = core.getInput('issue-body-template');
22+
const labelConfigPath = core.getInput('label-config');
2123
const workspace = process.env.GITHUB_WORKSPACE || '.';
2224

2325
// LLM support
@@ -29,6 +31,10 @@ async function run(): Promise<void> {
2931

3032
const useStructured = core.getInput('structured') === 'true';
3133

34+
if (labelConfigPath) {
35+
loadLabelConfig(labelConfigPath);
36+
}
37+
3238
const warnOverdue = core.getInput('warn-overdue') === 'true';
3339

3440
const todos: TodoItem[] = useStructured

src/core/labelManager.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as github from '@actions/github';
22
import * as core from '@actions/core';
3+
import fs from 'fs';
34
import { TodoItem } from '../parser/types';
45
import { 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.
2645
export 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 {

tests/fixtures/label-config.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"bug": { "color": "ff0000", "description": "Custom bug" },
3+
"priority:high": { "color": "00ff00", "description": "High priority" }
4+
}

tests/labelManager.test.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { describe, it, expect, vi, beforeEach } from 'vitest';
22
import * as core from '@actions/core';
3-
import { labelsFromMetadata, ensureLabelExists } from '../src/core/labelManager';
3+
import path from 'path';
4+
import { labelsFromMetadata, ensureLabelExists, loadLabelConfig } from '../src/core/labelManager';
45

56
const mockOctokit = {
67
rest: {
@@ -54,5 +55,24 @@ describe('ensureLabelExists', () => {
5455
description: 'Auto-created by smart-todo-action'
5556
});
5657
});
58+
59+
it('should use custom config for color and description', async () => {
60+
const error = { status: 404 } as any;
61+
octokit.rest.issues.getLabel.mockRejectedValueOnce(error);
62+
octokit.rest.issues.createLabel.mockResolvedValueOnce({});
63+
64+
const cfg = path.join(__dirname, 'fixtures/label-config.json');
65+
loadLabelConfig(cfg);
66+
67+
await ensureLabelExists(octokit, 'test-owner', 'test-repo', 'bug');
68+
69+
expect(octokit.rest.issues.createLabel).toHaveBeenCalledWith({
70+
owner: 'test-owner',
71+
repo: 'test-repo',
72+
name: 'bug',
73+
color: 'ff0000',
74+
description: 'Custom bug'
75+
});
76+
});
5777
});
5878

0 commit comments

Comments
 (0)