Skip to content

Commit

Permalink
feat: add month cli argument
Browse files Browse the repository at this point in the history
  • Loading branch information
azat-io committed Oct 19, 2024
1 parent d3c3c3f commit edf5b95
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 7 deletions.
114 changes: 114 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ edition = "2021"

[dependencies]
chrono = { version = "0.4.38", features = ["serde"] }
clap = { version = "4.5.20", features = ["derive"] }
futures = "0.3.31"
indicatif = "0.17.8"
open = "5.3.0"
Expand Down
17 changes: 17 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@
"repository": "azat-io/todoctor",
"author": "Azat S. <to@azat.io>",
"license": "MIT",
"keywords": [
"analysis",
"fixme",
"git-analysis",
"source-code-analysis",
"technical-debt",
"todo-comment",
"todo",
"visualization"
],
"bin": {
"todoctor": "./bin/todoctor"
},
Expand All @@ -30,6 +40,13 @@
"test:types": "tsc --noEmit --pretty",
"test:unit": "cargo test"
},
"publishConfig": {
"access": "public"
},
"files": [
"./bin",
"./dist"
],
"devDependencies": {
"@azat-io/eslint-config-typescript": "^1.10.0",
"@azat-io/stylelint-config": "^0.1.1",
Expand Down
30 changes: 29 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@

Todoctor is a powerful tool for analyzing, tracking, and visualizing technical debt in your codebase using Git. It collects and monitors `TODO`/`FIXME` comments in your code, allowing you to observe changes over time.

## Why

Developers often leave `TODO` comments in the code to highlight areas that need improvement or refactoring. However, these comments are rarely converted into tasks in tracking systems.

As a result, todos remain hidden in the codebase and can sit there for years without attention, leading to a hidden backlog of work. This tool tracks these todo comments and prevents them from being forgotten.

## Features

- Automatically extracts `TODO`, `FIXME`, and other custom tags from your codebase.
- Automatically extracts `TODO`, `FIXME`, and other tags from your codebase.
- Supports JavaScript and TypeScript programming languages that Git tracks.
- Analyzes each commit to gather and update comment history.
- Integrates with `git blame` to track the authorship and timing of changes.
Expand All @@ -41,6 +47,28 @@ npx todoctor

The program will automatically collect data and display the history of `TODO` / `FIXME` comments across commits.

## Options

Todoctor supports the following command-line options:

### --month \<N>

Specifies the number of months to include when tracking TODOs in the repository. If not provided, defaults to 3 months.

Example:

```sh
todoctor --months 6
```

### --help

Displays this help message with available options.

### --version

Displays the current version of Todoctor.

## License

MIT &copy; [Azat S.](https://azat.io)
29 changes: 23 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use clap::{CommandFactory, Parser};
use futures::future::join_all;
use indicatif::{ProgressBar, ProgressStyle};
use open;
Expand Down Expand Up @@ -31,10 +32,29 @@ use tokio::sync::Semaphore;
const TODOCTOR_DIR: &str = "todoctor";
const TODO_JSON_FILE: &str = "todoctor/data.json";
const HISTORY_TEMP_FILE: &str = "todo_history_temp.json";
const MONTHS: u32 = 3;

#[derive(Parser, Debug)]
#[command(name = "todoctor", about = "Tracks TODO comments in code")]
struct Cli {
/// Number of months to process
#[arg(short, long, default_value_t = 3, value_parser = clap::value_parser!(u32).range(1..))]
month: u32,
}

#[tokio::main]
async fn main() {
let version = get_todoctor_version()
.await
.unwrap_or_else(|| "Unknown version".to_string());

let version_for_cli = version.clone();
let version_static: &'static str =
Box::leak(version_for_cli.into_boxed_str());

let args = Cli::command().version(version_static).get_matches();

let months = args.get_one::<u32>("month").unwrap();

if !check_git_repository(".").await {
eprintln!("Error: This is not a Git repository.");
process::exit(1);
Expand Down Expand Up @@ -128,7 +148,7 @@ async fn main() {

todos_with_blame.sort_by(|a, b| a.blame.date.cmp(&b.blame.date));

let mut history: Vec<(String, String)> = get_history(Some(MONTHS)).await;
let mut history: Vec<(String, String)> = get_history(Some(*months)).await;
history = remove_duplicate_dates(history);

let temp_file =
Expand Down Expand Up @@ -231,9 +251,6 @@ async fn main() {
.expect("Error: Could not get current directory.");
let project_name =
get_project_name().unwrap_or_else(|| "Unknown Project".to_string());
let version = get_todoctor_version()
.await
.unwrap_or_else(|| "Unknown Version".to_string());

let file = File::open(HISTORY_TEMP_FILE).expect("Failed to open file");
let reader = BufReader::new(file);
Expand All @@ -246,7 +263,7 @@ async fn main() {
todo_history_data.push(entry);
}
todo_history_data =
add_missing_days(todo_history_data, MONTHS, todos_with_blame.len());
add_missing_days(todo_history_data, *months, todos_with_blame.len());

fs::remove_file(HISTORY_TEMP_FILE)
.await
Expand Down

0 comments on commit edf5b95

Please sign in to comment.