Skip to content

Commit

Permalink
feat: add post-bump-hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
tranzystorekk authored and oknozor committed Oct 11, 2020
1 parent 64c0afd commit a56b1e2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::commit::{CommitConfig, CommitMessage, CommitType};
use crate::error::ErrorKind::Semver;
use crate::filter::CommitFilters;
use crate::repository::Repository;
use crate::settings::Settings;
use crate::settings::{HookType, Settings};
use crate::version::{parse_pre_release, VersionIncrement};
use anyhow::{Context, Result};
use chrono::Utc;
Expand Down Expand Up @@ -396,13 +396,15 @@ impl CocoGitto {
.write()
.map_err(|err| anyhow!("Unable to write CHANGELOG.md : {}", err))?;

self.run_bump_hooks(&version_str)?;
self.run_hooks(HookType::PreBump, &version_str)?;

self.repository.add_all()?;
self.repository
.commit(&format!("chore(version): {}", next_version))?;
self.repository.create_tag(&version_str)?;

self.run_hooks(HookType::PostBump, &version_str)?;

let bump = format!("{} -> {}", current_version, next_version).green();
println!("Bumped version : {}", bump);

Expand Down Expand Up @@ -502,11 +504,11 @@ impl CocoGitto {
}
}

fn run_bump_hooks(&self, next_version: &str) -> Result<()> {
fn run_hooks(&self, hook_type: HookType, next_version: &str) -> Result<()> {
let settings = Settings::get(&self.repository)?;

let hooks = settings
.hooks
.get_hooks(hook_type)
.iter()
.map(String::as_str)
.map(Hook::from_str)
Expand Down
16 changes: 16 additions & 0 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,21 @@ use std::path::PathBuf;
type CommitsMetadataSettings = HashMap<String, CommitConfig>;
pub(crate) type AuthorSettings = Vec<AuthorSetting>;

#[derive(Copy, Clone)]
pub(crate) enum HookType {
PreBump,
PostBump,
}

#[derive(Debug, Deserialize, Serialize)]
pub(crate) struct Settings {
pub changelog_path: Option<PathBuf>,
pub github: Option<String>,
#[serde(default)]
pub hooks: Vec<String>,
#[serde(default)]
pub post_bump_hooks: Vec<String>,
#[serde(default)]
pub authors: AuthorSettings,
#[serde(default)]
pub commit_types: CommitsMetadataSettings,
Expand All @@ -33,6 +41,7 @@ impl Default for Settings {
changelog_path: Some(PathBuf::from("CHANGELOG.md")),
commit_types: Default::default(),
hooks: vec![],
post_bump_hooks: vec![],
authors: vec![],
github: None,
}
Expand Down Expand Up @@ -127,4 +136,11 @@ impl Settings {

default_types
}

pub fn get_hooks(&self, hook_type: HookType) -> &Vec<String> {
match hook_type {
HookType::PreBump => &self.hooks,
HookType::PostBump => &self.post_bump_hooks,
}
}
}

0 comments on commit a56b1e2

Please sign in to comment.