summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Grunert <Sascha.Grunert@rohde-schwarz.com>2016-09-21 16:38:13 +0200
committerSascha Grunert <Sascha.Grunert@rohde-schwarz.com>2016-09-21 16:38:13 +0200
commit917fd1837d431f586b7b96c0dcd6207545fc756b (patch)
tree226e2315ea27cf6e4dc7b2f6c18144d6e9f8a88a
parentd1d1dd0b4cadc64aed1ce33d504e927437cb53dd (diff)
Changed templating to work with arrays of tables0.3.0
- Fixed ordering within templates
-rw-r--r--README.md24
-rw-r--r--rfc/0002-output-templating.md40
-rw-r--r--src/parser.rs110
-rw-r--r--tests/template.toml16
4 files changed, 111 insertions, 79 deletions
diff --git a/README.md b/README.md
index 989885a..354039c 100644
--- a/README.md
+++ b/README.md
@@ -185,12 +185,18 @@ The design of commit message templates is described in
using this template for the test repository:
```toml
-[default]
+[[tag]]
+tag = "default"
+name = "Default"
-[tag1]
+[[tag]]
+tag = "tag1"
name = "Section 1"
-[tag1.tag2]
+[[tag]]
+[[tag.subtag]]
+tag = "tag2"
+name = "Subsection 1"
footers = ["Fixes"]
```
@@ -201,8 +207,8 @@ To use such a template just use the `-t` option:
[git-journal] [INFO] Skipping commit: Summary parsing: 'Merge branch 'test_branch''
[git-journal] [OKAY] Parsing done.
-# Unreleased (2016-09-20):
-## default
+# Unreleased (2016-09-21):
+## Default
- [Removed] file3.txt
- [Removed] file4.txt
- [Removed] file5.txt
@@ -221,14 +227,14 @@ To use such a template just use the `-t` option:
- [Added] file4 again
- This paragraph explains the change in detail
-## tag2
+### Subsection 1
- [Fixed] multiple issues
Fixes:
#1, #2, #1, #2, #3, #5, #6, #7
# v2 (2016-09-12):
-## default
+## Default
- [Added] file3.txt
```
@@ -237,8 +243,8 @@ Everything which is untagged will go into the `default` section. The name of `ta
uncategorized since the templating engine gives the possibility to split commits into multiple pieces. Parsed paragraphs
are converted to single list items to always provide a clean markdown. The footers are specified as an toml array of
strings which will output the selected footer keys at the correct position of the log. Please consider that the
-accumulation of the tags are related to the complete tag, not just the section where there printed. Other command line
-options like in the default output are available as well.
+accumulation of the footers are related to the complete tag, not just the section where there printed. Other command
+line options like in the default output are available as well.
### Commit message preparation and verification
[prepverify]: #prepverify
diff --git a/rfc/0002-output-templating.md b/rfc/0002-output-templating.md
index 20b7272..4c78bab 100644
--- a/rfc/0002-output-templating.md
+++ b/rfc/0002-output-templating.md
@@ -18,17 +18,33 @@ Changelog. The format of an output template consists of
example for such a template looks like this:
```toml
-[default]
-
-[tag1]
-name = "Section 1"
-[tag1.subtag1]
-[tag1.subtag2]
-
-[tag2]
-footers = ["Fixes", "Reviewed-by"]
+[[tag]]
+tag = "feature"
+name = "Feature"
+
+[[tag]]
+tag = "doc"
+name = "Documentation"
+
+[[tag]]
+[[tag.subtag]]
+tag = "doc_internal"
+name = "Internal documentation"
+
+[[tag]]
+[[tag.subtag]]
+tag = "doc_cust"
+name = "Customer documentation"
+
+[[tag]]
+tag = "internal"
+name = "Internal"
+footers = ["Fixes"]
```
-Every tag represents a toml table which can be nested as well. The `name` field inside the table maps the related tag to
-a chosen name. The `default` table can be used to specify every commit item which contains no tag at all. The `footers`
-array specifies the to be printed commit footers.
+Every tag represents a toml table which can be nested as well. Arrays of tables can be used to keep the order of the
+items, whereas the name of the array does not matter at all. The `tag` fields corresponds to the commit message tag and
+the `name` field inside the table maps the related tag to a chosen name.
+
+The `default` table can be used to specify every commit item which contains no tag at all. The `footers` array specifies
+the to be printed commit footers.
diff --git a/src/parser.rs b/src/parser.rs
index 46d65da..d974045 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -17,6 +17,7 @@ use config::Config;
static DEFAULT_TAG: &'static str = "default";
static FOOTER_TAG: &'static str = "footers";
static NAME_TAG: &'static str = "name";
+static TAG: &'static str = "tag";
#[derive(Debug)]
pub enum Error {
@@ -205,9 +206,10 @@ impl ParsedTag {
let mut file = try!(File::open(template));
let mut toml_string = String::new();
try!(file.read_to_string(&mut toml_string));
- let toml = try!(toml::Parser::new(&toml_string).parse()
- .ok_or(toml::Error::Custom("Could not parse toml template.".to_owned())));
- try!(self.print_commits_in_table(&mut term, &mut vec, &toml, &mut 2, config, &compact));
+ let toml = try!(toml::Parser::new(&toml_string)
+ .parse()
+ .ok_or(toml::Error::Custom("Could not parse toml template.".to_owned())));
+ try!(self.print_commits_in_table(&mut term, &mut vec, &toml, &mut 1, config, &compact));
}
None => {
for commit in &self.commits {
@@ -236,64 +238,68 @@ impl ParsedTag {
config: &Config,
compact: &bool)
-> Result<(), Error> {
- for (tag, value) in table {
- if let toml::Value::Table(ref table) = *value {
- let header_lvl: String = iter::repeat('#').take(*level).collect();
-
- // Get the corresponding name for the section, as fallback use the tag name
- let name = match table.get(NAME_TAG) {
- Some(name_value) => name_value.as_str().unwrap_or(tag),
- None => tag,
- };
-
- // Do not print at all if none of the commits matches to the section
- // Differenciate between compact and non compact prints
- if (*compact &&
- ((self.commits.iter().filter(|c| c.summary.contains_tag(Some(tag))).count() > 0 &&
- !config.excluded_commit_tags.contains(tag)) ||
- (tag == DEFAULT_TAG &&
- self.commits.iter().filter(|c| c.summary.contains_untagged_elements()).count() > 0))) ||
- (!*compact &&
- ((self.commits.iter().filter(|c| c.contains_tag(Some(tag))).count() > 0 &&
- !config.excluded_commit_tags.contains(tag)) ||
- (tag == DEFAULT_TAG &&
- self.commits.iter().filter(|c| c.contains_untagged_elements()).count() > 0))) {
-
-
- if config.colored_output {
- try!(term.fg(term::color::BRIGHT_RED));
+ for value in table {
+ if let toml::Value::Array(ref array) = *value.1 {
+ for item in array {
+ if let toml::Value::Table(ref table) = *item {
+ *level += 1;
+ try!(self.print_commits_in_table(term, vec, table, level, config, compact));
+ *level -= 1;
}
- tryw!(term, "\n{} {}", header_lvl, name);
- tryw!(vec, "\n{} {}", header_lvl, name);
+ }
+ }
+ }
- try!(term.reset());
+ let header_lvl: String = iter::repeat('#').take(*level).collect();
+ let tag = match table.get(TAG) {
+ Some(t) => t.as_str().unwrap_or(""),
+ None => return Ok(()),
+ };
+ let name = match table.get(NAME_TAG) {
+ Some(name_value) => name_value.as_str().unwrap_or(tag),
+ None => tag,
+ };
- // Print commits for this tag
- for commit in &self.commits {
- if *compact {
- try!(commit.summary
- .print_to_term_and_write_to_vector(&mut term, &mut vec, config, Some(tag)));
- } else {
- try!(commit.print_to_term_and_write_to_vector(&mut term, &mut vec, config, Some(tag)));
- }
- }
+ if (*compact &&
+ ((self.commits.iter().filter(|c| c.summary.contains_tag(Some(tag))).count() > 0 &&
+ !config.excluded_commit_tags.contains(&tag.to_owned())) ||
+ (tag == DEFAULT_TAG &&
+ self.commits.iter().filter(|c| c.summary.contains_untagged_elements()).count() > 0))) ||
+ (!*compact &&
+ ((self.commits.iter().filter(|c| c.contains_tag(Some(tag))).count() > 0 &&
+ !config.excluded_commit_tags.contains(&tag.to_owned())) ||
+ (tag == DEFAULT_TAG && self.commits.iter().filter(|c| c.contains_untagged_elements()).count() > 0))) {
- trywln!(term, "");
- trywln!(vec, "");
- }
- // Print footers is specified in template
- if let Some(footers) = table.get(FOOTER_TAG) {
- if let toml::Value::Array(ref array) = *footers {
- try!(self.print_footers(term, vec, Some(array), config));
- }
+ if config.colored_output {
+ try!(term.fg(term::color::BRIGHT_RED));
+ }
+ tryw!(term, "\n{} {}", header_lvl, name);
+ tryw!(vec, "\n{} {}", header_lvl, name);
+
+ try!(term.reset());
+
+ // Print commits for this tag
+ for commit in &self.commits {
+ if *compact {
+ try!(commit.summary
+ .print_to_term_and_write_to_vector(&mut term, &mut vec, config, Some(tag)));
+ } else {
+ try!(commit.print_to_term_and_write_to_vector(&mut term, &mut vec, config, Some(tag)));
}
+ }
- *level += 1;
- try!(self.print_commits_in_table(term, vec, table, level, config, compact));
- *level -= 1;
+ trywln!(term, "");
+ trywln!(vec, "");
+ }
+
+ // Print footers is specified in template
+ if let Some(footers) = table.get(FOOTER_TAG) {
+ if let toml::Value::Array(ref array) = *footers {
+ try!(self.print_footers(term, vec, Some(array), config));
}
}
+
Ok(())
}
diff --git a/tests/template.toml b/tests/template.toml
index 39b4997..bf6f1ea 100644
--- a/tests/template.toml
+++ b/tests/template.toml
@@ -1,9 +1,13 @@
-[default]
+[[tag]]
+tag = "default"
+name = "Default"
-[tag1]
+[[tag]]
+tag = "tag1"
name = "Section 1"
-[tag1.par]
-[tag1.subtag2]
-[tag2]
-footers = ["Fixes", "Change-ID"]
+[[tag]]
+[[tag.subtag]]
+tag = "tag2"
+name = "Subsection 1"
+footers = ["Fixes"]