Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ pub use git::{get_commits_in_range, open_repo, resolve_ref};
const SHA_ABBREV_LEN: usize = 8;

/// Abbreviates a SHA to the first 8 characters (or less if shorter).
fn abbreviate_sha(sha: &str) -> &str {
&sha[..SHA_ABBREV_LEN.min(sha.len())]
pub fn abbreviate_sha(sha: &str) -> &str {
sha.get(..SHA_ABBREV_LEN).unwrap_or(sha)
}
Comment thread
agherzan marked this conversation as resolved.

/// Runs a check and reports results.
Expand Down
19 changes: 18 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// SPDX-License-Identifier: Apache-2.0

use clap::{Parser, Subcommand};
use gitlance::{checks, git, output, run_check};
use gitlance::{abbreviate_sha, checks, git, output, run_check};
use std::process::exit;

#[derive(Parser)]
Expand Down Expand Up @@ -45,6 +45,20 @@ enum Commands {
All,
}

/// Displays the list of commits being tested
fn display_commits(commits: &[git::Commit]) {
let count = commits.len();
let plural = if count == 1 { "commit" } else { "commits" };
println!("Testing {} {}:", count, plural);

for commit in commits {
let sha_abbrev = abbreviate_sha(&commit.sha);
let first_line = commit.message.lines().next().unwrap_or("");
println!(" {} {}", sha_abbrev, first_line);
}
println!();
}

fn main() {
let cli = Cli::parse();

Expand Down Expand Up @@ -102,6 +116,9 @@ fn main() {
exit(0);
}

// Display the commits being tested
display_commits(&commits);

// Run the appropriate check(s)
let overall_passed = match command {
Commands::WipFixup => run_check("WIP/Fixup", &checks::wip_fixup::check_commits(&commits)),
Expand Down
Loading