Skip to content

Commit

Permalink
fix: display hook-profiles value in cli and safe check commit type
Browse files Browse the repository at this point in the history
  • Loading branch information
oknozor committed Nov 30, 2021
1 parent ce9882c commit fa59679
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 12 deletions.
11 changes: 10 additions & 1 deletion cog.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ pre_bump_hooks = [
"cargo bump {{version}}",
]


# A list of command to run AFTER creating a version.
# `{{version}}` will be interpretted as your target version
post_bump_hooks = [
Expand All @@ -41,6 +40,16 @@ post_bump_hooks = [
"cargo publish"
]

# A custom named bump profile, the inner post/pre bump hook will be used
# instead of the main ones when running `cog bump --hook-profile example --auto`
[bump_profiles.example]
pre_bump_hooks = [
"echo 'bumping from {{latest}} to {{version}} using a named profile'"
]
post_bump_hooks = [
"echo 'we are done'"
]

# An optional list of additional allowed commit type
# `coco {commit_type}` commit command will be generated at runtime
[commit_types]
Expand Down
8 changes: 7 additions & 1 deletion src/bin/cog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use cocogitto::conventional::version::VersionIncrement;
use cocogitto::git::hook::HookKind;
use cocogitto::log::filter::{CommitFilter, CommitFilters};
use cocogitto::log::output::Output;
use cocogitto::CocoGitto;
use cocogitto::{CocoGitto, HOOK_PROFILES};

const APP_SETTINGS: &[AppSettings] = &[
AppSettings::SubcommandRequiredElseHelp,
Expand Down Expand Up @@ -186,6 +186,11 @@ fn main() -> Result<()> {
}

fn app<'a, 'b>() -> App<'a, 'b> {
let hook_profiles: Vec<&str> = HOOK_PROFILES
.iter()
.map(|profile| profile.as_ref())
.collect();

let check_command = SubCommand::with_name(CHECK)
.settings(SUBCOMMAND_SETTINGS)
.about("Verify all commit message against the conventional commit specification")
Expand Down Expand Up @@ -329,6 +334,7 @@ fn app<'a, 'b>() -> App<'a, 'b> {
.help("Specify the bump profile hooks to run")
.short("hp")
.long("hook-profile")
.possible_values(&hook_profiles)
.takes_value(true),
)
.display_order(6);
Expand Down
14 changes: 8 additions & 6 deletions src/conventional/changelog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ impl Changelog {
.into_group_map();

for (commit_type, commits) in grouped {
let meta = &COMMITS_METADATA[&commit_type];

write!(&mut out, "\n### {}\n\n", meta.changelog_title).unwrap();
out.extend(commits);
if let Some(meta) = COMMITS_METADATA.get(&commit_type) {
write!(&mut out, "\n### {}\n\n", meta.changelog_title).unwrap();
out.extend(commits);
}
}

out
Expand Down Expand Up @@ -137,14 +137,16 @@ mod test {

// Act
let content = ch.markdown(false);
println!("{}", content);

// Assert
println!("{}", content);
assert_that(&content)
assert_that!(content)
.contains("[5375e1](https://github.com/oknozor/cocogitto/commit/5375e15770ddf8821d0c1ad393d315e243014c15) - this is a commit message - coco");

assert_that!(content).contains(
"[5375e1](https://github.com/oknozor/cocogitto/commit/5375e15770ddf8821d0c1ad393d315e243014c15) - this is an other commit message - cogi"
);

assert_that!(content).contains("## 5375e1..35085f -");
assert_that!(content).contains("### Features");
assert_that!(content).does_not_contain("### Tests");
Expand Down
6 changes: 3 additions & 3 deletions src/conventional/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ impl Commit {
let username = AUTHORS
.iter()
.find(|author| author.signature == self.author);
let github_author = username.map(|username| {
let github_author = username.map(|user| {
format!(
"[{}](https://github.com/{})",
&username.username, &username.username
"[{username}](https://github.com/{username})",
username = &user.username
)
});
let oid = REMOTE_URL.as_ref().map(|remote_url| {
Expand Down
13 changes: 12 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,25 @@ lazy_static! {
// This cannot be carried by `Cocogitto` struct since we need it to be available in `Changelog`,
// `Commit` etc. Be ensure that `CocoGitto::new` is called before using this in order to bypass
// unwrapping in case of error.
pub static ref COMMITS_METADATA: CommitsMetadata = {
pub static ref COMMITS_METADATA: CommitsMetadata = {
if let Ok(repo) = Repository::open(".") {
Settings::get(&repo).unwrap_or_default().commit_types()
} else {
Settings::default().commit_types()
}
};

pub static ref HOOK_PROFILES: Vec<String> = {
if let Ok(repo) = Repository::open(".") {
Settings::get(&repo).unwrap_or_default().bump_profiles
.keys()
.cloned()
.collect()
} else {
vec![]
}
};

static ref REMOTE_URL: Option<String> = {
if let Ok(repo) = Repository::open(".") {
Settings::get(&repo).unwrap_or_default().github
Expand Down

0 comments on commit fa59679

Please sign in to comment.