1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
mod change;
pub mod changelog;
pub mod config;
pub mod util;
pub mod version;

use change::commit_changes;
use changelog::generate_and_insert_changelogs;
use colored::Colorize;
use config::Config;
use util::check_for_uncommitted_changes;
use version::{increment_version, write_new_version_to_file, VersionDesignation};

pub const EXPECTED_CONFIG_FILE_NAME: &str = "gitscribe.json";

/// Handles the version change when the any subcommand is used
/// # Arguments
/// * `config` - The config struct
/// * `version_designation` - The version designation
/// # Examples
/// ```
/// use gitscribe::Config;
/// let config = Config::create_default();
/// gitscribe::handle_version_bump(config, VersionDesignation::Patch);
/// ```
pub fn handle_version_bump(config: Config, version_designation: VersionDesignation) {
    // check if there are uncommitted changes
    check_for_uncommitted_changes();
    let version = increment_version(&config, version_designation);
    let config = write_new_version_to_file(config, version.clone());
    let changelog = generate_and_insert_changelogs(&version, &config);

    match changelog {
        Ok(changelog) => {
            changelog.iter().for_each(|log| println!("{}", log.cyan()));
        }
        Err(_) => {
            println!("{}", "Failed to generate changelog".red());
        }
    }

    commit_changes(version.to_string());
}