gitstats/
lib.rs

1use std::collections::HashMap;
2use std::path::PathBuf;
3
4use serde::{Deserialize, Serialize};
5
6mod impls;
7mod repo;
8mod test;
9pub mod traits;
10
11#[derive(Debug, Clone)]
12pub struct Repo {
13	inner: PathBuf,
14}
15
16#[derive(Debug, Clone, Serialize, Deserialize)]
17pub struct CommitHash(String);
18
19#[derive(Debug, Default, Hash, Clone, Serialize, Deserialize)]
20pub struct Author {
21	pub name: String,
22	pub email: Option<String>,
23}
24
25#[derive(Clone, Debug, Default, Serialize, Deserialize)]
26pub struct CommitArgs {
27	since: Option<i64>,
28	until: Option<i64>,
29	author: Option<Author>,
30	exclude_merges: bool,
31	exclude_author: Option<String>,
32	target_branch: Option<String>,
33}
34
35pub struct CommitArgsBuilder(CommitArgs);
36
37#[derive(Debug, Clone, Copy, Default, Serialize)]
38pub struct CommitStats {
39	pub files_changed: u32,
40	pub lines_added: u32,
41	pub lines_deleted: u32,
42}
43
44#[derive(Debug, Clone, Serialize)]
45#[allow(dead_code)]
46pub struct CommitDetail {
47	pub hash: CommitHash,
48	pub author: Author,
49	pub author_timestamp: i64,
50	pub stats: CommitStats,
51}
52
53#[derive(Debug, Clone, Serialize)]
54#[allow(dead_code)]
55pub struct MinimalCommitDetail {
56	pub hash: CommitHash,
57	pub author_timestamp: i64,
58	pub stats: CommitStats,
59}
60
61#[derive(Debug, Clone, Serialize)]
62pub struct GlobalStat {
63	pub author: Author,
64	pub commits_count: usize,
65	pub stats: CommitStats,
66}
67
68#[derive(Debug, Clone, Serialize, Default)]
69pub struct SimpleStat {
70	pub commits_count: usize,
71	pub stats: CommitStats,
72}
73
74pub enum SortStatsBy {
75	Commits,
76	FilesChanged,
77	LinesAdded,
78	LinesDeleted,
79}
80
81#[derive(Debug, Clone, Serialize)]
82pub struct CommitsPerAuthor(pub(crate) HashMap<Author, Vec<MinimalCommitDetail>>);
83
84#[derive(Debug, Clone, Serialize)]
85pub struct CommitsPerWeekday(pub(crate) HashMap<u8, HashMap<Author, SimpleStat>>);
86
87#[derive(Debug, Clone, Serialize)]
88pub struct CommitsPerDayHour(pub(crate) HashMap<u32, HashMap<Author, SimpleStat>>);
89
90#[derive(Debug, Clone, Serialize)]
91pub struct CommitsPerMonth(pub(crate) HashMap<String, HashMap<Author, SimpleStat>>);
92
93///
94/// Contains an hashmap where the key is the Author and the value is a matrix[weekday, hour] of stats
95#[derive(Debug, Clone, Serialize)]
96pub struct CommitsHeatMap(pub(crate) HashMap<Author, Vec<Vec<SimpleStat>>>);
97
98#[derive(Debug, Clone, Copy, Serialize)]
99pub struct Detail {
100	/// repository size in Kilobytes
101	pub size: u64,
102	/// total commits
103	pub commits_count: usize,
104	// first commit timestamp
105	pub first_commit: Option<i64>,
106	// last commit timestamp
107	pub last_commit: Option<i64>,
108}