Skip to content
Open
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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "tests/test_repo2"]
path = tests/test_repo2
url = https://github.com/saschagrunert/test2
[submodule "tests/test_repo3"]
path = tests/test_repo3
url = git@github.com:jwir3/ghp-release-cleaner
14 changes: 14 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,20 @@ mod tests {
assert!(journal.generate_template().is_ok());
}

#[test]
fn output_correctly_categorized() {
let mut journal = GitJournal::new("./tests/test_repo3").unwrap();
assert!(journal
.parse_log("444b3a64355557844beb848d80051ada2c00176a..HEAD", "rc", 0, true, false, None, None)
.is_ok());
assert_eq!(journal.parser.result.len(), 4);
assert_eq!(journal.parser.result[0].name, "Unreleased");
assert_eq!(journal.parser.result[0].commits.len(), 2);
assert_eq!(journal.parser.result[0].commits[0].summary.tags.len(), 1);
assert!(journal.print_log(false, None, Some("CHANGELOG.md")).is_ok());
assert!(journal.print_log(true, None, Some("CHANGELOG.md")).is_ok());
}

#[test]
fn path_failure() {
assert!(GitJournal::new("/etc/").is_err());
Expand Down
19 changes: 17 additions & 2 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ pub struct FooterElement {
}

lazy_static! {
static ref RE_TAGS: Regex = Regex::new(r"[ \n]:(.*?):").unwrap();
static ref RE_TAGS: Regex = Regex::new(r"[ \n]*:(.*?):").unwrap();
static ref RE_FOOTER: Regex = RegexBuilder::new(r"^([\w-]+):\s(.*)$")
.multi_line(true)
.build()
Expand Down Expand Up @@ -827,12 +827,25 @@ impl Parser {
}

fn parse_summary<'a>(&mut self, input: &'a [u8]) -> ParserResult<'a, SummaryElement> {
// Before we do anything, let's parse the entire summary line for tags so that we don't
// skip any tags that happen before, say, the category.
let entire_string = str_or_empty(input);
let mut tags = vec![];
for cap in RE_TAGS.captures_iter(entire_string) {
tags.push((&cap[1]).to_string());
}

let (input, p_prefix) = opt(separated_pair(alpha1, char('-'), digit1))(input)?;
let (input, _) = space0(input)?;
let (input, p_category) = self.parse_category(input)?;
let (input, _) = space1(input)?;
let (input, p_tags_rest) = map(rest, Self::parse_and_consume_tags)(input)?;

let p_tags_rest_vec = p_tags_rest.0;
tags.extend(p_tags_rest_vec);
tags.sort();
tags.dedup();

Ok((
input,
SummaryElement {
Expand All @@ -841,7 +854,7 @@ impl Parser {
format!("{}-{}", str_or_empty(p.0), str_or_empty(p.1))
}),
category: p_category.to_owned(),
tags: p_tags_rest.0,
tags: tags,
text: p_tags_rest.1,
},
))
Expand All @@ -850,6 +863,7 @@ impl Parser {
fn parse_and_consume_tags(input: &[u8]) -> (Vec<String>, String) {
let string = str_or_empty(input);
let mut tags = vec![];

for cap in RE_TAGS.captures_iter(string) {
if let Some(tag) = cap.get(1) {
tags.extend(
Expand Down Expand Up @@ -888,6 +902,7 @@ impl Parser {
.next()
.ok_or_else(|| format_err!("Summar line parsing: Commit message length too small."))?
.trim();

let mut parsed_summary = match self.clone().parse_summary(summary_line.as_bytes()) {
Ok((_, parsed)) => parsed,
_ => bail!("Summary parsing failed: '{}'", summary_line),
Expand Down
1 change: 1 addition & 0 deletions tests/test_repo3
Submodule test_repo3 added at 85aab3