Skip to content

Commit

Permalink
Delivery of fix to #159 (#160)
Browse files Browse the repository at this point in the history
* Corrected groupId & version of fugue

* Updated to 0.9.2

* Bug #157 - adding test for empty text

* Correcting capitalisation on Jira

* Moving on to next snapshot iteration

* Fixed #159 - updated to use the project URL
  • Loading branch information
dgrierso committed May 12, 2021
1 parent 6a218fe commit fae88d9
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@ public String getSettingsKey() {
return settingsKey;
}

public String getJiraURL() {
return jiraURL;
}

public void setJiraProjectKey(String jiraProjectKey) {
this.jiraProjectKey = jiraProjectKey;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ private void output(JiraRestClient restClient, Iterable<Issue> issues) throws IO
String formatPackage = ( format.contains(".") ? "" : "net.sigmalab.maven.plugin.jira.formats" );

Class<?> clazz = Class.forName(formatPackage + "." + format);
Constructor<?> constructor = clazz.getConstructor(JiraRestClient.class, Iterable.class, String.class,
String.class);
generator = (Generator) constructor.newInstance(restClient, issues, beforeText, afterText);
Constructor<?> constructor = clazz.getConstructor(JiraRestClient.class, Iterable.class, String.class,
String.class, String.class);
generator = (Generator) constructor.newInstance(restClient, issues, this.getJiraURL(), beforeText, afterText);

log.info("Using " + format + " format for release notes.");
}
Expand Down
29 changes: 19 additions & 10 deletions src/main/java/net/sigmalab/maven/plugin/jira/formats/Generator.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ public abstract class Generator {
private JiraRestClient restClient;
protected IssueRestClient issueClient;
private Iterable<Issue> issues;
private String jiraUrl;
private String beforeText;
private String afterText;

public Generator(JiraRestClient r, Iterable<Issue> i, String b, String a) {
public Generator(JiraRestClient r, Iterable<Issue> i, String u, String b, String a) {
this.restClient = r;
this.issues = i;
this.issueClient = restClient.getIssueClient();
this.setBeforeText(b);
this.setAfterText(a);
this.jiraUrl = u;
this.beforeText = b;
this.afterText = a;
}

public abstract String addHeader();
Expand Down Expand Up @@ -60,15 +62,22 @@ public String getBeforeText() {
return beforeText;
}

public void setBeforeText(String beforeText) {
this.beforeText = beforeText;
}

public String getAfterText() {
return afterText;
}

public void setAfterText(String afterText) {
this.afterText = afterText;

protected String computeIssueUrl(Issue i) {
// Use the jiraUrl as the basis for the URL of the issue passed to the method.
// Do this by stripping back the URL to just .../browse/ ending and then append
// the issue key.
int position = jiraUrl.lastIndexOf("/browse/");

// If we haven't found /browse/ in the Jira URL then just return the issue key.
if ( position < 0 ) {
return i.getKey();
}

// Otherwise return the issue key appended to the substring of the Jira URL.
return jiraUrl.substring(0, position) + "/browse/" + i.getKey();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ public class HtmlGenerator extends Generator {
static final String ISSUETEMPLATE = "<td>[<a href=\"{0}\">{1}</a>]</td><td>{2}</td>";
static final String HORIZONTAL_RULE = "<hr/>";

public HtmlGenerator(JiraRestClient r, Iterable<Issue> i, String b, String a) {
super(r, i, b, a);
public HtmlGenerator(JiraRestClient r, Iterable<Issue> i, String u, String b, String a) {
super(r, i, u, b, a);
}

@Override
public String addHeader() {
return "<html><body>";
}

@Override
public String addRow(Issue i) {
return "<tr>" +
format(ISSUETEMPLATE, i.getSelf(), i.getKey(), i.getSummary()) +
format(ISSUETEMPLATE, this.computeIssueUrl(i), i.getKey(), i.getSummary()) +
"</tr>";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ public class MarkDownGenerator extends Generator {
static final String ISSUETEMPLATE = "| [{0}]({1}) | {2} |";
static final String HORIZONTAL_RULE = "---";

public MarkDownGenerator(JiraRestClient r, Iterable<Issue> i, String b, String a) {
super(r, i, b, a);
public MarkDownGenerator(JiraRestClient r, Iterable<Issue> i, String u, String b, String a) {
super(r, i, u, b, a);
}

@Override
Expand All @@ -20,7 +20,7 @@ public String addHeader() {

@Override
public String addRow(Issue i) {
return format(ISSUETEMPLATE, i.getKey(), i.getSelf(), i.getSummary());
return format(ISSUETEMPLATE, i.getKey(), this.computeIssueUrl(i), i.getSummary());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public class PlainTextGenerator extends Generator {
static final String HORIZONTAL_RULE = "==============================";


public PlainTextGenerator(JiraRestClient r, Iterable<Issue> i, String b, String a) {
super(r, i, b, a);
public PlainTextGenerator(JiraRestClient r, Iterable<Issue> i, String u, String b, String a) {
super(r, i, u, b, a);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public void setUp() throws Exception {
releaseNoteMojo.setJiraUser("user");
releaseNoteMojo.setJiraPassword("password");
releaseNoteMojo.setJiraProjectKey("DUMMY");
releaseNoteMojo.setJiraURL("https://dummy.jira.server/browse/KEY");
releaseNoteMojo.setBeforeText("This is BEFORE TEXT");
releaseNoteMojo.setAfterText("This is AFTER TEXT");
releaseNoteMojo.setJiraProjectKey("KEY");
Expand Down
8 changes: 4 additions & 4 deletions src/test/resources/expectedReleaseNotes.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
<tr><th>Key</th><th>Summary</th></tr>
</thead>
<tbody>
<tr><td>[<a href="null">DUMMY-1</a>]</td><td>Dummy Issue</td></tr>
<tr><td>[<a href="null">DUMMY-4</a>]</td><td>Dummy Issue</td></tr>
<tr><td>[<a href="null">DUMMY-3</a>]</td><td>Dummy Issue</td></tr>
<tr><td>[<a href="null">DUMMY-2</a>]</td><td>Dummy Issue</td></tr>
<tr><td>[<a href="https://dummy.jira.server/browse/DUMMY-1">DUMMY-1</a>]</td><td>Dummy Issue</td></tr>
<tr><td>[<a href="https://dummy.jira.server/browse/DUMMY-4">DUMMY-4</a>]</td><td>Dummy Issue</td></tr>
<tr><td>[<a href="https://dummy.jira.server/browse/DUMMY-3">DUMMY-3</a>]</td><td>Dummy Issue</td></tr>
<tr><td>[<a href="https://dummy.jira.server/browse/DUMMY-2">DUMMY-2</a>]</td><td>Dummy Issue</td></tr>
</tbody>
</table>
<hr/>
Expand Down
8 changes: 4 additions & 4 deletions src/test/resources/expectedReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ This is BEFORE TEXT
---
| ISSUE KEY | SUMMARY |
|-----------|---------|
| [DUMMY-1](null) | Dummy Issue |
| [DUMMY-4](null) | Dummy Issue |
| [DUMMY-3](null) | Dummy Issue |
| [DUMMY-2](null) | Dummy Issue |
| [DUMMY-1](https://dummy.jira.server/browse/DUMMY-1) | Dummy Issue |
| [DUMMY-4](https://dummy.jira.server/browse/DUMMY-4) | Dummy Issue |
| [DUMMY-3](https://dummy.jira.server/browse/DUMMY-3) | Dummy Issue |
| [DUMMY-2](https://dummy.jira.server/browse/DUMMY-2) | Dummy Issue |
---
This is AFTER TEXT

0 comments on commit fae88d9

Please sign in to comment.