Skip to content

Commit

Permalink
danielflower#3 Adding support for issue management tools
Browse files Browse the repository at this point in the history
  • Loading branch information
danielflower committed Sep 18, 2011
1 parent 92a0fca commit 25acbb6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,17 @@ public JiraIssueLinkConverter(Log log, String urlPrefix) {
this.log = log;
// strip off trailing slash
urlPrefix = urlPrefix.endsWith("/") ? urlPrefix.substring(0, urlPrefix.length() - 2) : urlPrefix;
// strip off jira code
// strip off jira project code
this.urlPrefix = urlPrefix.substring(0, urlPrefix.lastIndexOf("/") + 1);
this.pattern = Pattern.compile("(.*[^A-Z]|)([A-Z]+-[0-9]+)(.*)");
this.pattern = Pattern.compile("[A-Z]+-[0-9]+");
}

@Override
public String formatCommitMessage(String original) {
try {
Matcher matcher = pattern.matcher(original);
if (matcher.matches()) {
String startText = matcher.group(1);
String jiraCode = matcher.group(2);
String endText = matcher.group(3);
String result = matcher.replaceAll("<a href=\"" + urlPrefix + jiraCode + "\">" + jiraCode + "</a>");
return startText + result + endText;
}
String result = matcher.replaceAll("<a href=\"" + urlPrefix + "$0\">$0</a>");
return result;
} catch (Exception e) {
// log, but don't let this small setback fail the build
log.info("Unable to parse issue tracking URL in commit message: " + original, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ public void lowercaseGHHyphenNumberInMiddleIsRendered() {
"Some commit message. Closes <a href=\"" + PREFIX + "10\">gh-10</a> it's true");
}

@Test
public void multipleIssueNumbersAreAllRendered() {
test("#1 Some commit message. Closes gh-10 it's true, also gh-11 and GH-13",
"Some commit message. Closes <a href=\"" + PREFIX + "10\">gh-10</a> it's true, also <a href=\""
+ PREFIX + "\"10\">gh-11</a> and <a href=\"" + PREFIX + "10\">GH-13</a>");
}

@Test
public void urlMissingTrailingSlashHasItAppendedCorrectly() {
GitHubIssueLinkConverter converter = new GitHubIssueLinkConverter(new SystemStreamLog(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,21 @@ public void jiraCodeAtBeginningIsRendered() {
@Test
public void multipleJiraCodesAreRendered() {
test("CONF-10 Some CONF-12 commit message CONF-13",
"<a href=\"" + PREFIX + "-10\">CONF-10</a> Some CONF-12 commit message CONF-13");
"<a href=\"" + PREFIX + "-10\">CONF-10</a> Some <a href=\"" + PREFIX
+ "-12\">CONF-12</a> commit message <a href=\"" + PREFIX + "-13\">CONF-13</a>");
}

@Test
public void jiraCodesInOtherProjectsAreRendered() {
test("CONF-10 Some commit message related to JRA-23013", "<a href=\"" + PREFIX + "-10\">CONF-10</a> Some commit message related to " +
"<a href=\"https://jira.atlassian.com/browse/JRA-23013\">JRA-23013</a>");
}

@Test
public void lowerCaseJiraCodesAreIgnored() {
test("conf-10 Some commit message", "conf-10 Some commit message");
}


@Test
public void urlWithTrailingSlashHasItRemovedCorrectly() {
JiraIssueLinkConverter converter = new JiraIssueLinkConverter(new SystemStreamLog(),
Expand Down

0 comments on commit 25acbb6

Please sign in to comment.