Skip to content
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- add trace logs for push_commit function(pr [#373])
- add prefix option for version tags in CLI commands(pr [#375])

### Changed

Expand Down Expand Up @@ -771,6 +772,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#371]: https://github.com/jerus-org/pcu/pull/371
[#373]: https://github.com/jerus-org/pcu/pull/373
[#374]: https://github.com/jerus-org/pcu/pull/374
[#375]: https://github.com/jerus-org/pcu/pull/375
[Unreleased]: https://github.com/jerus-org/pcu/compare/v0.4.7...HEAD
[0.4.7]: https://github.com/jerus-org/pcu/compare/v0.4.6...v0.4.7
[0.4.6]: https://github.com/jerus-org/pcu/compare/v0.4.5...v0.4.6
Expand Down
12 changes: 12 additions & 0 deletions src/cli/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ pub struct PullRequest {
/// Signal an early exit as the changelog is already updated
#[clap(short, long, default_value_t = false)]
pub early_exit: bool,
/// Prefix for the version tag (default 'v')
#[clap(short, long, default_value_t = String::from("v"))]
pub prefix: String,
}

#[derive(Debug, Parser, Clone)]
Expand All @@ -62,6 +65,9 @@ pub struct Release {
/// Update the changelog by renaming the unreleased section with the version number
#[arg(short, long, default_value_t = false)]
pub update_changelog: bool,
/// Prefix for the version tag (default 'v')
#[clap(short, long, default_value_t = String::from("v"))]
pub prefix: String,
}

/// Configuration for the Commit command
Expand All @@ -73,6 +79,9 @@ pub struct Commit {
/// Message to add to the commit when pushing
#[arg(short, long)]
commit_message: String,
/// Prefix for the version tag (default 'v')
#[clap(short, long, default_value_t = String::from("v"))]
pub prefix: String,
}

impl Commit {
Expand All @@ -97,6 +106,9 @@ pub struct Push {
/// Disable the push command
#[arg(short, long, default_value_t = false)]
pub no_push: bool,
/// Prefix for the version tag (default 'v')
#[clap(short, long, default_value_t = String::from("v"))]
pub prefix: String,
}

impl Push {
Expand Down
33 changes: 23 additions & 10 deletions src/cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,24 @@ async fn run_pull_request(sign: Sign, args: PullRequest) -> Result<CIExit> {

let commit_message = "chore: update changelog for pr";

commit_changed_files(&client, sign, commit_message, None).await?;
commit_changed_files(&client, sign, commit_message, &args.prefix, None).await?;

push_committed(&client, None, false).await?;
push_committed(&client, &args.prefix, None, false).await?;

Ok(CIExit::Updated)
}

async fn run_commit(sign: Sign, args: Commit) -> Result<CIExit> {
let client = get_client(Commands::Commit(args.clone())).await?;

commit_changed_files(&client, sign, args.commit_message(), args.tag_opt()).await?;
commit_changed_files(
&client,
sign,
args.commit_message(),
&args.prefix,
args.tag_opt(),
)
.await?;

Ok(CIExit::Committed)
}
Expand All @@ -145,6 +152,7 @@ async fn commit_changed_files(
client: &Client,
sign: Sign,
commit_message: &str,
prefix: &str,
tag_opt: Option<&str>,
) -> Result<()> {
let hdr_style = Style::new().bold().underline();
Expand All @@ -170,7 +178,7 @@ async fn commit_changed_files(

log::info!("Commit the staged changes");

client.commit_staged(sign, commit_message, tag_opt)?;
client.commit_staged(sign, commit_message, prefix, tag_opt)?;

log::debug!("{}", "Check Committed".style(hdr_style));
log::debug!("WorkDir files:\n\t{:?}", client.repo_files_not_staged()?);
Expand All @@ -186,7 +194,7 @@ async fn commit_changed_files(
async fn run_push(args: Push) -> Result<CIExit> {
let client = get_client(Commands::Push(args.clone())).await?;

push_committed(&client, args.tag_opt(), args.no_push).await?;
push_committed(&client, &args.prefix, args.tag_opt(), args.no_push).await?;

if !args.no_push {
Ok(CIExit::Pushed(
Expand All @@ -199,11 +207,16 @@ async fn run_push(args: Push) -> Result<CIExit> {
}
}

async fn push_committed(client: &Client, tag_opt: Option<&str>, no_push: bool) -> Result<()> {
async fn push_committed(
client: &Client,
prefix: &str,
tag_opt: Option<&str>,
no_push: bool,
) -> Result<()> {
log::info!("Push the commit");
log::trace!("tag_opt: {tag_opt:?} and no_push: {no_push}");

client.push_commit(tag_opt, no_push)?;
client.push_commit(prefix, tag_opt, no_push)?;
let hdr_style = Style::new().bold().underline();
log::debug!("{}", "Check Push".style(hdr_style));
log::debug!("Branch status: {}", client.branch_status()?);
Expand Down Expand Up @@ -251,12 +264,12 @@ async fn run_release(sign: Sign, args: Release) -> Result<CIExit> {

let commit_message = "chore: update changelog for pr";

commit_changed_files(&client, sign, commit_message, Some(&version)).await?;
commit_changed_files(&client, sign, commit_message, &args.prefix, Some(&version)).await?;

push_committed(&client, Some(&version), false).await?;
push_committed(&client, &args.prefix, Some(&version), false).await?;
}

client.make_release(&version).await?;
client.make_release(&args.prefix, &version).await?;

Ok(CIExit::Released)
}
Expand Down
12 changes: 7 additions & 5 deletions src/lib/ops/git_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ pub trait GitOps {
&self,
sign: Sign,
commit_message: &str,
prefix: &str,
tag: Option<&str>,
) -> Result<(), Error>;
fn push_commit(&self, version: Option<&str>, no_push: bool) -> Result<(), Error>;
fn push_commit(&self, prefix: &str, version: Option<&str>, no_push: bool) -> Result<(), Error>;
#[allow(async_fn_in_trait)]
async fn label_next_pr(
&self,
Expand Down Expand Up @@ -148,6 +149,7 @@ impl GitOps for Client {
&self,
sign: Sign,
commit_message: &str,
prefix: &str,
tag: Option<&str>,
) -> Result<(), Error> {
log::trace!("Commit staged with sign {sign:?}");
Expand Down Expand Up @@ -252,14 +254,14 @@ impl GitOps for Client {
};

if let Some(version_tag) = tag {
let version_tag = format!("v{}", version_tag);
let version_tag = format!("{prefix}{version_tag}");
self.create_tag(&version_tag, commit_id, &sig)?;
}

Ok(())
}

fn push_commit(&self, version: Option<&str>, no_push: bool) -> Result<(), Error> {
fn push_commit(&self, prefix: &str, version: Option<&str>, no_push: bool) -> Result<(), Error> {
log::trace!("version: {version:?} and no_push: {no_push}");
let mut remote = self.git_repo.find_remote("origin")?;
log::trace!("Pushing changes to {:?}", remote.name());
Expand Down Expand Up @@ -287,8 +289,8 @@ impl GitOps for Client {
let mut tag_ref = String::from("");

if let Some(version_tag) = version {
log::trace!("Found version tag: {}", version_tag);
tag_ref = format!("refs/tags/v{version_tag}");
log::trace!("Found version tag: {prefix}{version_tag}");
tag_ref = format!("refs/tags/{prefix}{version_tag}");
log::trace!("Tag ref: {tag_ref}");
push_refs.push(&tag_ref);
};
Expand Down
8 changes: 4 additions & 4 deletions src/lib/ops/make_release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use octocrate::repos::create_release::RequestMakeLatest;

pub trait MakeRelease {
#[allow(async_fn_in_trait)]
async fn make_release(&self, version: &str) -> Result<(), Error>;
async fn make_release(&self, prefix: &str, version: &str) -> Result<(), Error>;
fn release_unreleased(&mut self, version: &str) -> Result<(), Error>;
}

Expand All @@ -30,7 +30,7 @@ impl MakeRelease for Client {
Ok(())
}

async fn make_release(&self, version: &str) -> Result<(), Error> {
async fn make_release(&self, prefix: &str, version: &str) -> Result<(), Error> {
log::debug!("Making release {version}");

let opts = ChangelogParseOptions::default();
Expand All @@ -42,10 +42,10 @@ impl MakeRelease for Client {
}
};

let release_notes = changelog.release_notes(version)?;
let release_notes = changelog.release_notes(prefix, version)?;
log::trace!("Release notes: {:#?}", release_notes);

let tag = format!("v{version}");
let tag = format!("{prefix}{version}");
let commit = Self::get_commitish_for_tag(self, &tag).await?;
log::trace!("Commit: {:#?}", commit);

Expand Down
6 changes: 3 additions & 3 deletions src/lib/utilities/release_notes_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ pub struct ReleaseNotes {
}

pub trait ReleaseNotesProvider {
fn release_notes(&self, release: &str) -> Result<ReleaseNotes, Error>;
fn release_notes(&self, prefix: &str, release: &str) -> Result<ReleaseNotes, Error>;
}

impl ReleaseNotesProvider for Changelog {
fn release_notes(&self, release: &str) -> Result<ReleaseNotes, Error> {
let name = format!("v{release}");
fn release_notes(&self, prefix: &str, release: &str) -> Result<ReleaseNotes, Error> {
let name = format!("{prefix}{release}");

let version = match Version::parse(release) {
Ok(version) => version,
Expand Down