-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Redmine issue tracker support added
- Loading branch information
Hakan Uygun
committed
Nov 14, 2021
1 parent
336dae0
commit afb929c
Showing
20 changed files
with
556 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/main/java/se/bjurr/gitchangelog/internal/integrations/redmine/DefaultRedmineClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package se.bjurr.gitchangelog.internal.integrations.redmine; | ||
|
||
import java.io.UnsupportedEncodingException; | ||
import java.util.Base64; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import se.bjurr.gitchangelog.api.exceptions.GitChangelogIntegrationException; | ||
import se.bjurr.gitchangelog.internal.integrations.rest.RestClient; | ||
|
||
public class DefaultRedmineClient extends RedmineClient { | ||
|
||
private RestClient client; | ||
|
||
public DefaultRedmineClient(final String api) { | ||
super(api); | ||
this.client = new RestClient(); | ||
} | ||
|
||
@Override | ||
public RedmineClient withBasicCredentials(final String username, final String password) { | ||
this.client = this.client.withBasicAuthCredentials(username, password); | ||
return this; | ||
} | ||
|
||
@Override | ||
public RedmineClient withTokenCredentials(final String token) { | ||
String authToken; | ||
try { | ||
authToken = Base64.getEncoder().encodeToString((token + ":changelog" ).getBytes("UTF-8")); | ||
} catch (final UnsupportedEncodingException e) { | ||
throw new RuntimeException(e); | ||
} | ||
this.client = this.client.withTokenAuthCredentials(authToken); | ||
return this; | ||
} | ||
|
||
@Override | ||
public RedmineClient withHeaders(final Map<String, String> headers) { | ||
this.client = this.client.withHeaders(headers); | ||
return this; | ||
} | ||
|
||
@Override | ||
public Optional<RedmineIssue> getIssue(final String issue) throws GitChangelogIntegrationException { | ||
final String endpoint = this.getEndpoint(issue); | ||
final Optional<String> json = this.client.get(endpoint); | ||
if (json.isPresent()) { | ||
final String jsonString = json.get(); | ||
try { | ||
final RedmineIssue redmineIssue = this.toRedmineIssue(issue, jsonString); | ||
return Optional.of(redmineIssue); | ||
} catch (final Exception e) { | ||
throw new GitChangelogIntegrationException("Unable to parse:\n" + jsonString, e); | ||
} | ||
} | ||
return Optional.empty(); | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/se/bjurr/gitchangelog/internal/integrations/redmine/RedmineClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package se.bjurr.gitchangelog.internal.integrations.redmine; | ||
|
||
import static com.jayway.jsonpath.JsonPath.read; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
import se.bjurr.gitchangelog.api.exceptions.GitChangelogIntegrationException; | ||
|
||
public abstract class RedmineClient { | ||
private final String api; | ||
|
||
public RedmineClient(final String api) { | ||
if (api.endsWith("/")) { | ||
this.api = api.substring(0, api.length() - 1); | ||
} else { | ||
this.api = api; | ||
} | ||
} | ||
|
||
public String getApi() { | ||
return this.api; | ||
} | ||
|
||
protected String getEndpoint(final String issue) { | ||
final String issueNo = getIssueNumber(issue); | ||
final String endpoint = this.api + "/issues/" + issueNo + ".json"; | ||
return endpoint; | ||
} | ||
|
||
protected RedmineIssue toRedmineIssue(final String issue, final String json) { | ||
final String issueNo = getIssueNumber(issue); | ||
final String title = read(json, "$.issue.subject"); | ||
final String description = read(json, "$.issue.description"); | ||
final String type = read(json, "$.issue.tracker.name"); | ||
final String link = this.api + "/issues/" + issueNo; | ||
|
||
final RedmineIssue redmineIssue = new RedmineIssue(title, description, link, issue, type); | ||
return redmineIssue; | ||
} | ||
|
||
protected String getIssueNumber( String issue ){ | ||
return issue.startsWith("#") ? issue.substring(1) : issue; | ||
} | ||
|
||
public abstract RedmineClient withBasicCredentials(String username, String password); | ||
|
||
public abstract RedmineClient withTokenCredentials(String token); | ||
|
||
public abstract RedmineClient withHeaders(Map<String, String> headers); | ||
|
||
public abstract Optional<RedmineIssue> getIssue(String matched) throws GitChangelogIntegrationException; | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/se/bjurr/gitchangelog/internal/integrations/redmine/RedmineClientFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package se.bjurr.gitchangelog.internal.integrations.redmine; | ||
|
||
public class RedmineClientFactory { | ||
|
||
private static RedmineClient redmineClient; | ||
|
||
public static void reset() { | ||
redmineClient = null; | ||
} | ||
|
||
/** | ||
* The Bitbucket Server plugin uses this method to inject the Atlassian Client. | ||
*/ | ||
public static void setRedmineClient(final RedmineClient redmineClient) { | ||
RedmineClientFactory.redmineClient = redmineClient; | ||
} | ||
|
||
public static RedmineClient createRedmineClient(final String apiUrl) { | ||
if (redmineClient != null) { | ||
return redmineClient; | ||
} | ||
return new DefaultRedmineClient(apiUrl); | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/se/bjurr/gitchangelog/internal/integrations/redmine/RedmineIssue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package se.bjurr.gitchangelog.internal.integrations.redmine; | ||
|
||
public class RedmineIssue { | ||
private final String title; | ||
private final String link; | ||
private final String issue; | ||
private final String issueType; | ||
private final String description; | ||
|
||
|
||
public RedmineIssue(String title, String description, String link, String issue, String issueType ) { | ||
this.title = title; | ||
this.link = link; | ||
this.issue = issue; | ||
this.issueType = issueType; | ||
this.description = description; | ||
} | ||
|
||
public String getIssue() { | ||
return issue; | ||
} | ||
|
||
public String getLink() { | ||
return link; | ||
} | ||
|
||
public String getTitle() { | ||
return title; | ||
} | ||
|
||
public String getIssueType() { | ||
return issueType; | ||
} | ||
|
||
public String getDescription() { | ||
|
||
return description; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "RedmineIssue [title=" + title + ", link=" + link + ", issue=" + issue + ", issueType=" + issueType + "]"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.