diff --git a/.github/workflows/release-plz.yml b/.github/workflows/release-plz.yml new file mode 100644 index 0000000..7f6d474 --- /dev/null +++ b/.github/workflows/release-plz.yml @@ -0,0 +1,26 @@ +name: Continuous Deployment + +on: + push: + branches: + - main + +jobs: + release-plz: + name: Release-plz + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + token: ${{ secrets.RELEASE_PLZ_TOKEN }} + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + + - name: Run release-plz + uses: MarcoIeni/release-plz-action@v0.5 + env: + GITHUB_TOKEN: ${{ secrets.RELEASE_PLZ_TOKEN }} + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} diff --git a/Cargo.lock b/Cargo.lock index 3c92f71..0ceacbd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -128,7 +128,7 @@ dependencies = [ [[package]] name = "git-commitizen" -version = "0.1.0-rc.2" +version = "0.1.1" dependencies = [ "git2", "openssl", diff --git a/Cargo.toml b/Cargo.toml index 4da1ddf..7f7e936 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "git-commitizen" -version = "0.1.0" +version = "0.1.1" edition = "2021" authors = ["Jain Ramchurn"] description = "A simple commitizen CLI tool in rust" @@ -15,6 +15,7 @@ categories = ["development-tools"] git2 = "0.19.0" promkit = "0.4.5" openssl = { version = "0.10", features = ["vendored"] } +tempfile = "3.2" [dev-dependencies] tempfile = "3.2" @@ -49,3 +50,5 @@ tap = "k3ii/homebrew-tap" formula = "git-cz" # Publish jobs to run in CI publish-jobs = ["homebrew"] +# Ignore out-of-date contents +allow-dirty = ["ci"] diff --git a/release-plz.toml b/release-plz.toml new file mode 100644 index 0000000..a411f82 --- /dev/null +++ b/release-plz.toml @@ -0,0 +1,27 @@ +[workspace] +# path of the git-cliff configuration +changelog_config = "cliff.toml" + +# enable changelog updates +changelog_update = true + +# update dependencies with `cargo update` +dependencies_update = true + +# create tags for the releases +git_tag_enable = true + +# disable GitHub releases +git_release_enable = false + +# labels for the release PR +pr_labels = ["release"] + +# disallow updating repositories with uncommitted changes +allow_dirty = false + +# disallow packaging with uncommitted changes +publish_allow_dirty = false + +# disable running `cargo-semver-checks` +semver_check = false diff --git a/src/main.rs b/src/main.rs index dea133e..a4ed80c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,10 @@ use git_commitizen::{ }; use promkit::preset::query_selector::QuerySelector; use promkit::{preset::confirm::Confirm, preset::readline::Readline, suggest::Suggest}; +use std::env; use std::path::Path; +use std::process::Command; +use tempfile; fn main() -> Result<(), Box> { let commit_types = build_commit_types(); @@ -29,10 +32,10 @@ fn main() -> Result<(), Box> { .prompt()?; let mut description_input = Readline::default() - .title("Write a SHORT, IMPERATIVE tense description of the change:") + .title("Write a short, imperative tense description of the change:") .prompt()?; let mut body_input = Readline::default() - .title("Provide a LONGER description of the change:") + .title("Provide a longer description of the change(press 'e' to open editor):") .prompt()?; let selection = p.run()?; @@ -43,6 +46,34 @@ fn main() -> Result<(), Box> { let description = description_input.run()?; let body = body_input.run()?; + let body = if body.trim().to_lowercase() == "e" { + // Create a temporary file + let temp_file = tempfile::NamedTempFile::new()?; + let temp_path = temp_file + .path() + .to_str() + .expect("Failed to get temp file path"); + + // Determine the editor command + let editor_command = if cfg!(target_os = "windows") { + env::var("EDITOR").unwrap_or_else(|_| "notepad".to_string()) + } else { + env::var("EDITOR").unwrap_or_else(|_| "vim".to_string()) + }; + + // Open the editor + let status = Command::new(&editor_command).arg(temp_path).status()?; + + if !status.success() { + eprintln!("Editor exited with non-zero status"); + } + + // Read the contents of the temp file + std::fs::read_to_string(temp_path)? + } else { + body + }; + // New footer confirmation prompt let mut footer_confirm = Confirm::new("Do you want to add a footer?").prompt()?; let footer = if footer_confirm.run()?.to_lowercase() == "y" { @@ -62,6 +93,10 @@ fn main() -> Result<(), Box> { let mut issue_number_input = Readline::default() .title("Enter the issue number:") + .validator( + |text| text.trim().parse::().is_ok(), + |text| format!("'{}' is not a valid integer", text), + ) .prompt()?; let footer_type = footer_type_input.run()?;