Skip to content

Commit 357f56c

Browse files
Merge pull request #177 from DiogoRibeiro7/codex/add-overdue-todo-detection-feature
Add overdue TODO warnings
2 parents 698b134 + d517ece commit 357f56c

File tree

4 files changed

+53
-1
lines changed

4 files changed

+53
-1
lines changed

action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ inputs:
1717
description: Use structured tag extraction with @assignee, #module, and key=value
1818
default: 'false'
1919

20+
warn-overdue:
21+
required: false
22+
description: Emit warnings for TODOs with due dates in the past
23+
default: 'false'
24+
2025
issue-title-template:
2126
required: false
2227
description: Optional path to custom issue title template

src/ActionMain.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { extractTodosFromDir } from './parser/extractTodosFromDir';
77
import { extractTodosWithStructuredTagsFromDir } from './parser/extractTodosWithStructuredTagsFromDir'; // 👈 novo
88
import { TodoItem } from './parser/types';
99
import { getExistingIssueTitles, createIssueIfNeeded } from './core/issueManager';
10-
import { generateMarkdownReport } from './core/report';
10+
import { generateMarkdownReport, warnOverdueTodos } from './core/report';
1111
import { limitTodos, todoKey } from './core/todoUtils';
1212
import { generateChangelogFromTodos } from './core/changelog';
1313

@@ -30,6 +30,8 @@ async function run(): Promise<void> {
3030

3131
const useStructured = core.getInput('structured') === 'true';
3232

33+
const warnOverdue = core.getInput('warn-overdue') === 'true';
34+
3335
const todos: TodoItem[] = useStructured
3436
? extractTodosWithStructuredTagsFromDir(workspace)
3537
: extractTodosFromDir(workspace);
@@ -48,6 +50,10 @@ async function run(): Promise<void> {
4850
return true;
4951
});
5052

53+
if (warnOverdue) {
54+
warnOverdueTodos(uniqueTodos);
55+
}
56+
5157
const issueLimit = parseInt(core.getInput('limit') || '5', 10);
5258
const todosToCreate = limitTodos(uniqueTodos, issueLimit);
5359

src/core/report.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import fs from 'fs';
22
import path from 'path';
33
import { TodoItem } from '../parser/types';
44
import { todoKey } from './todoUtils';
5+
import * as core from '@actions/core';
56

67
const PRIORITY_ORDER = ['high', 'medium', 'low'];
78

@@ -13,6 +14,21 @@ function getDue(todo: TodoItem): string {
1314
return todo.metadata?.due ?? '';
1415
}
1516

17+
export function findOverdueTodos(todos: TodoItem[]): TodoItem[] {
18+
const today = new Date().toISOString().split('T')[0];
19+
return todos.filter(t => {
20+
const due = t.metadata?.due;
21+
return typeof due === 'string' && due < today;
22+
});
23+
}
24+
25+
export function warnOverdueTodos(todos: TodoItem[]): void {
26+
const overdue = findOverdueTodos(todos);
27+
for (const todo of overdue) {
28+
core.warning(`\u23F0 Overdue TODO (${todo.metadata!.due}): ${todo.text} (${todo.file}:${todo.line})`);
29+
}
30+
}
31+
1632
function sortTodos(a: TodoItem, b: TodoItem): number {
1733
const pa = getPriority(a);
1834
const pb = getPriority(b);

tests/overdueDetection.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { describe, it, expect } from 'vitest';
2+
import { findOverdueTodos } from '../src/core/report';
3+
import { TodoItem } from '../src/parser/types';
4+
5+
function format(date: Date) {
6+
return date.toISOString().split('T')[0];
7+
}
8+
9+
describe('findOverdueTodos', () => {
10+
it('detects todos with past due dates', () => {
11+
const yesterday = format(new Date(Date.now() - 86400000));
12+
const today = format(new Date());
13+
const tomorrow = format(new Date(Date.now() + 86400000));
14+
const todos: TodoItem[] = [
15+
{ tag: 'TODO', text: 'past', file: 'a.ts', line: 1, metadata: { due: yesterday } },
16+
{ tag: 'TODO', text: 'today', file: 'b.ts', line: 2, metadata: { due: today } },
17+
{ tag: 'TODO', text: 'future', file: 'c.ts', line: 3, metadata: { due: tomorrow } },
18+
{ tag: 'TODO', text: 'none', file: 'd.ts', line: 4 }
19+
];
20+
21+
const result = findOverdueTodos(todos);
22+
expect(result.length).toBe(1);
23+
expect(result[0].text).toBe('past');
24+
});
25+
});

0 commit comments

Comments
 (0)