Add: add commits info for projects
This commit is contained in:
parent
bc5eacf367
commit
d8aa24600f
5 changed files with 1851 additions and 8 deletions
1791
Cargo.lock
generated
1791
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -4,10 +4,12 @@ version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
chrono = "0.4.42"
|
||||||
clap = { version = "4.5.53", features = ["derive"] }
|
clap = { version = "4.5.53", features = ["derive"] }
|
||||||
crossterm = "0.29.0"
|
crossterm = "0.29.0"
|
||||||
directories = "6.0.0"
|
directories = "6.0.0"
|
||||||
fs_extra = "1.3.0"
|
fs_extra = "1.3.0"
|
||||||
|
gix = "0.75.0"
|
||||||
serde = { version = "1.0.228", features = ["derive"] }
|
serde = { version = "1.0.228", features = ["derive"] }
|
||||||
serde_json = "1.0.145"
|
serde_json = "1.0.145"
|
||||||
thiserror = "2.0.17"
|
thiserror = "2.0.17"
|
||||||
|
|
|
||||||
15
src/lib.rs
15
src/lib.rs
|
|
@ -2,6 +2,7 @@ mod cli;
|
||||||
mod config;
|
mod config;
|
||||||
mod core;
|
mod core;
|
||||||
mod misc;
|
mod misc;
|
||||||
|
mod projects;
|
||||||
mod templates;
|
mod templates;
|
||||||
mod timer;
|
mod timer;
|
||||||
|
|
||||||
|
|
@ -10,6 +11,7 @@ use std::{fs, process};
|
||||||
|
|
||||||
use cli::{CLI, Commands, PomodoroAction, ProjectsAction, TemplateAction};
|
use cli::{CLI, Commands, PomodoroAction, ProjectsAction, TemplateAction};
|
||||||
use config::{Config, load_config, save_config};
|
use config::{Config, load_config, save_config};
|
||||||
|
use projects::commits_info;
|
||||||
use templates::{list_templates, load_template};
|
use templates::{list_templates, load_template};
|
||||||
use timer::run_timer;
|
use timer::run_timer;
|
||||||
|
|
||||||
|
|
@ -178,7 +180,18 @@ fn process_command(mut cfg: Config) {
|
||||||
eprintln!("Projects:");
|
eprintln!("Projects:");
|
||||||
for project in cfg.projects {
|
for project in cfg.projects {
|
||||||
match project.file_name() {
|
match project.file_name() {
|
||||||
Some(name) => eprintln!("{}", name.display()),
|
Some(name) => {
|
||||||
|
if let Ok(info) = commits_info(project.clone()) {
|
||||||
|
eprintln!(
|
||||||
|
"{}:\n\t{} commits\n\tlast update: {}",
|
||||||
|
name.display(),
|
||||||
|
info.cnt,
|
||||||
|
info.format_date()
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
eprintln!("{}: can't get info", name.display());
|
||||||
|
};
|
||||||
|
}
|
||||||
None => eprintln!(
|
None => eprintln!(
|
||||||
"Error: project folder/file empty name '{}'",
|
"Error: project folder/file empty name '{}'",
|
||||||
project.display()
|
project.display()
|
||||||
|
|
|
||||||
48
src/projects/info.rs
Normal file
48
src/projects/info.rs
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
use chrono::{DateTime, Local, Utc};
|
||||||
|
use gix::discover;
|
||||||
|
|
||||||
|
use std::{
|
||||||
|
io::{Error, ErrorKind},
|
||||||
|
path::PathBuf,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub struct CommitsInfo {
|
||||||
|
pub cnt: usize,
|
||||||
|
pub updated: DateTime<Local>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CommitsInfo {
|
||||||
|
pub fn new(commits_cnt: usize, last_commit_seconds: i64) -> CommitsInfo {
|
||||||
|
CommitsInfo {
|
||||||
|
cnt: commits_cnt,
|
||||||
|
updated: from_seconds_to_local(last_commit_seconds),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn format_date(&self) -> String {
|
||||||
|
format!("{}, {}", self.updated.date_naive(), self.updated.time()).to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn from_seconds_to_local(seconds: i64) -> DateTime<Local> {
|
||||||
|
let dt_utc: DateTime<Utc> = DateTime::from_timestamp(seconds, 0).expect("");
|
||||||
|
dt_utc.with_timezone(&Local)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn commits_info(repository_path: PathBuf) -> Result<CommitsInfo, Error> {
|
||||||
|
let repository = match discover(repository_path) {
|
||||||
|
Ok(repo) => repo,
|
||||||
|
Err(err) => {
|
||||||
|
return Err(Error::new(ErrorKind::InvalidData, err));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let head_commit = repository.head_commit().unwrap();
|
||||||
|
|
||||||
|
let revwalk = repository.rev_walk([head_commit.id()]);
|
||||||
|
|
||||||
|
Ok(CommitsInfo::new(
|
||||||
|
revwalk.all().unwrap().count(),
|
||||||
|
head_commit.time().unwrap().seconds,
|
||||||
|
))
|
||||||
|
}
|
||||||
3
src/projects/mod.rs
Normal file
3
src/projects/mod.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
mod info;
|
||||||
|
|
||||||
|
pub use info::commits_info;
|
||||||
Loading…
Add table
Add a link
Reference in a new issue