Initial upload: GitPulse - Developer Productivity Analyzer CLI tool
Some checks failed
CI / release (push) Has been cancelled
CI / test (push) Has been cancelled

This commit is contained in:
2026-02-04 15:45:43 +00:00
parent 7b634ac1b0
commit 4c39d7839c

59
src/export/csv.rs Normal file
View File

@@ -0,0 +1,59 @@
use crate::models::AnalysisResult;
use anyhow::{Context, Result};
use csv::{Writer, WriterBuilder};
use std::fs::File;
use std::path::PathBuf;
pub fn export_csv(result: &AnalysisResult, path: &PathBuf) -> Result<()> {
let mut wtr = WriterBuilder::new()
.delimiter(b',')
.has_headers(true)
.from_path(path)
.context("Failed to create CSV writer")?;
wtr.write_record(&[
"Name", "Email", "Commits", "Lines Added", "Lines Removed", "Net Change",
])?;
for author in &result.contributors.top_contributors {
wtr.write_record(&[
&author.name,
&author.email,
&author.commits.to_string(),
&author.lines_added.to_string(),
&author.lines_removed.to_string(),
&author.net_change.to_string(),
])?;
}
wtr.flush()?;
Ok(())
}
pub fn export_contributors_detailed(result: &AnalysisResult, path: &PathBuf) -> Result<()> {
let mut wtr = Writer::from_path(path)?;
wtr.write_record(&[
"Name", "Email", "Commits", "Lines Added", "Lines Removed",
"Net Change", "Files Changed", "First Commit", "Last Commit",
"Avg Commits/Day"
])?;
for author in &result.contributors.top_contributors {
wtr.write_record(&[
&author.name,
&author.email,
&author.commits.to_string(),
&author.lines_added.to_string(),
&author.lines_removed.to_string(),
&author.net_change.to_string(),
&author.files_changed.to_string(),
&author.first_commit,
&author.last_commit,
&format!("{:.2}", author.average_commits_per_day),
])?;
}
wtr.flush()?;
Ok(())
}