gitai/features/commit/
mod.rs

1mod cli;
2mod relevance;
3pub mod review;
4pub mod types;
5
6pub mod prompt;
7pub mod service;
8
9pub use cli::{handle_message_command, handle_pr_command};
10use git2::FileMode;
11pub use review::handle_review_command;
12pub use service::CommitService;
13pub use types::{
14    GeneratedMessage, GeneratedPullRequest, format_commit_message, format_pull_request,
15};
16
17use crate::git::CommitResult;
18use std::fmt::Write;
19
20pub fn format_commit_result(result: &CommitResult, message: &str) -> String {
21    let mut output = format!(
22        "[{} {}] {}\n",
23        result.branch,
24        result.commit_hash,
25        message.lines().next().unwrap_or("")
26    );
27
28    writeln!(
29        &mut output,
30        " {} file{} changed, {} insertion{}(+), {} deletion{}(-)",
31        result.files_changed,
32        if result.files_changed == 1 { "" } else { "s" },
33        result.insertions,
34        if result.insertions == 1 { "" } else { "s" },
35        result.deletions,
36        if result.deletions == 1 { "" } else { "s" }
37    )
38    .expect("writing to string should never fail");
39
40    for (file, mode) in &result.new_files {
41        writeln!(
42            &mut output,
43            " create mode {} {}",
44            format_file_mode(*mode),
45            file
46        )
47        .expect("writing to string should never fail");
48    }
49
50    output
51}
52
53fn format_file_mode(mode: FileMode) -> String {
54    match mode {
55        FileMode::Blob => "100644",
56        FileMode::BlobExecutable => "100755",
57        FileMode::Link => "120000",
58        FileMode::Commit => "160000",
59        FileMode::Tree => "040000",
60        _ => "000000",
61    }
62    .to_string()
63}