Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to use default editor for body prompt #39

Merged
merged 7 commits into from
Sep 25, 2024
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
26 changes: 26 additions & 0 deletions .github/workflows/release-plz.yml
Original file line number Diff line number Diff line change
@@ -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 }}
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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"]
27 changes: 27 additions & 0 deletions release-plz.toml
Original file line number Diff line number Diff line change
@@ -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
39 changes: 37 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn std::error::Error>> {
let commit_types = build_commit_types();
Expand All @@ -29,10 +32,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.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()?;
Expand All @@ -43,6 +46,34 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
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" {
Expand All @@ -62,6 +93,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

let mut issue_number_input = Readline::default()
.title("Enter the issue number:")
.validator(
|text| text.trim().parse::<i32>().is_ok(),
|text| format!("'{}' is not a valid integer", text),
)
.prompt()?;

let footer_type = footer_type_input.run()?;
Expand Down