Allow to specify multiple 'footer' tags per trackingid entry

The documentation says:

  "A single trackingid entry can have multiple footer tags"

However the implementation was only considering the first one
that was listed. So for a configuration like:

    [trackingid "jira-bug"]
      footer = Bugfix:
      footer = Bug:
      match = JRA\\d{2,8}
      system = JIRA

only "Bugfix:" would be considered, and "Bug:" would be ignored.

Fix it so that all footer tags are recognized.

Change-Id: Ib6706d0743bb9a2fd116cb260c8e4270e765c91a
This commit is contained in:
David Pursehouse
2015-02-19 14:52:45 +09:00
parent 2b3a38fe2a
commit ce7f68675b
2 changed files with 22 additions and 8 deletions

View File

@@ -3363,6 +3363,7 @@ bug:<tracking id>.
---- ----
[trackingid "jira-bug"] [trackingid "jira-bug"]
footer = Bugfix: footer = Bugfix:
footer = Bug:
match = JRA\\d{2,8} match = JRA\\d{2,8}
system = JIRA system = JIRA
@@ -3374,11 +3375,15 @@ bug:<tracking id>.
[[trackingid.name.footer]]trackingid.<name>.footer:: [[trackingid.name.footer]]trackingid.<name>.footer::
+ +
A prefix tag that identify the footer line to parse for tracking ids. A prefix tag that identifies the footer line to parse for tracking ids.
Several trackingid entries can have the same footer tag. A single +
trackingid entry can have multiple footer tags. If multiple footer Several trackingid entries can have the same footer tag, and a single trackingid
tags are specified, each tag will be parsed separately. entry can have multiple footer tags.
(the trailing ":" is optional) +
If multiple footer tags are specified, each tag will be parsed separately and
duplicates will be ignored.
+
The trailing ":" is optional.
[[trackingid.name.match]]trackingid.<name>.match:: [[trackingid.name.match]]trackingid.<name>.match::
+ +

View File

@@ -24,7 +24,11 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.regex.PatternSyntaxException; import java.util.regex.PatternSyntaxException;
/** Provides a list of all configured {@link TrackingFooter}s. */ /** Provides a list of all configured {@link TrackingFooter}s. */
@@ -43,8 +47,11 @@ public class TrackingFootersProvider implements Provider<TrackingFooters> {
for (String name : cfg.getSubsections(TRACKING_ID_TAG)) { for (String name : cfg.getSubsections(TRACKING_ID_TAG)) {
boolean configValid = true; boolean configValid = true;
String footer = cfg.getString(TRACKING_ID_TAG, name, FOOTER_TAG); Set<String> footers = new HashSet<>(
if (footer == null || footer.isEmpty()) { Arrays.asList(cfg.getStringList(TRACKING_ID_TAG, name, FOOTER_TAG)));
footers.removeAll(Collections.singleton(null));
if (footers.isEmpty()) {
configValid = false; configValid = false;
log.error("Missing " + TRACKING_ID_TAG + "." + name + "." + FOOTER_TAG log.error("Missing " + TRACKING_ID_TAG + "." + name + "." + FOOTER_TAG
+ " in gerrit.config"); + " in gerrit.config");
@@ -71,7 +78,9 @@ public class TrackingFootersProvider implements Provider<TrackingFooters> {
if (configValid) { if (configValid) {
try { try {
for (String footer : footers) {
trackingFooters.add(new TrackingFooter(footer, match, system)); trackingFooters.add(new TrackingFooter(footer, match, system));
}
} catch (PatternSyntaxException e) { } catch (PatternSyntaxException e) {
log.error("Invalid pattern \"" + match + "\" in gerrit.config " log.error("Invalid pattern \"" + match + "\" in gerrit.config "
+ TRACKING_ID_TAG + "." + name + "." + REGEX_TAG + ": " + TRACKING_ID_TAG + "." + name + "." + REGEX_TAG + ": "