Skip to content

Commit

Permalink
fix: validate footers on commit
Browse files Browse the repository at this point in the history
  • Loading branch information
oknozor committed Sep 12, 2021
1 parent 4379e2f commit 2f95cf8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/bin/coco.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ fn main() -> Result<()> {
let message = matches.value_of("message").unwrap().to_string();
let scope = matches.value_of("scope").map(|scope| scope.to_string());
let body = matches.value_of("body").map(|body| body.to_string());
let footer = matches.value_of("footer").map(|footer| footer.to_string());
let footers = matches.value_of("footer").map(|footer| footer.to_string());
let breaking_change = matches.is_present("breaking-change");

cocogitto.conventional_commit(
&commit_type,
scope,
message,
body,
footer,
footers,
breaking_change,
)?;
}
Expand Down
30 changes: 19 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use conventional::changelog::{Changelog, ChangelogWriter};
use conventional::commit::Commit;
use conventional::commit::CommitConfig;
use conventional::version::{parse_pre_release, VersionIncrement};
use conventional_commit_parser::commit::{CommitType, ConventionalCommit, Footer};
use conventional_commit_parser::commit::{CommitType, ConventionalCommit};
use git::repository::Repository;
use git2::{Oid, RebaseOptions};
use hook::Hook;
Expand All @@ -41,6 +41,7 @@ use std::io::Write;
use std::path::{Path, PathBuf};
use std::process::{exit, Command, Stdio};
use tempfile::TempDir;
use conventional_commit_parser::parse_footers;

pub type CommitsMetadata = HashMap<CommitType, CommitConfig>;

Expand Down Expand Up @@ -348,25 +349,32 @@ impl CocoGitto {
footer: Option<String>,
is_breaking_change: bool,
) -> Result<()> {

// Ensure commit type is known
let commit_type = CommitType::from(commit_type);

let message = ConventionalCommit {
// Ensure footers are correctly formatted
let footers = match footer {
Some(footers) => parse_footers(&footers)?,
None => Vec::with_capacity(0),
};

let conventional_message = ConventionalCommit {
commit_type,
scope,
body,
// FIXME
footers: vec![Footer {
token: "".to_string(),
content: "".to_string(),
}],
footers,
summary,
is_breaking_change,
}
.to_string();
}.to_string();

// Validate the message
conventional_commit_parser::parse(&conventional_message)?;

conventional_commit_parser::parse(&message)?;
// Git commit
let oid = self.repository.commit(&conventional_message)?;

let oid = self.repository.commit(&message)?;
// Pretty print a conventional commit summary
let commit = self.repository.0.find_commit(oid)?;
let commit = Commit::from_git_commit(&commit)?;
println!("{}", commit);
Expand Down

0 comments on commit 2f95cf8

Please sign in to comment.