Skip to content

Commit

Permalink
Add task text to issue descriptoin, fix URLs in case of duplicated sl…
Browse files Browse the repository at this point in the history
…ashes
  • Loading branch information
pfaller committed Nov 14, 2019
1 parent 11fa8ab commit 5072329
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class TasksToJiraSettings {
private static final String TEAMSCALE_USER = "teamscaleUser";
private static final String TEAMSCALE_URL = "teamscaleUrl";
private static final String TEAMSCALE_PROJECT = "teamscaleProject";
private static final String TASK_LINK_TEXT = "taskLinkText";
private static final String ADDITIONAL_JIRA_FIELD_PREFIX = "jiraField.";

public final String teamscaleProject;
Expand All @@ -41,21 +42,23 @@ public class TasksToJiraSettings {
public final Long jiraIssueType;
public final String jiraEpicKey;
public final String jiraEpicLinkFieldName;
public final String taskLinkText;
public final Map<String, Object> jiraAddtionalFields;

public TasksToJiraSettings(File propertiesFile) throws IOException {
Properties properties = FileSystemUtils.readPropertiesFile(propertiesFile);
teamscaleProject = readValue(properties, TEAMSCALE_PROJECT);
teamscaleUrl = readValue(properties, TEAMSCALE_URL);
teamscaleUrl = StringUtils.stripSuffix(readValue(properties, TEAMSCALE_URL), "/");
teamscaleApiKey = readValue(properties, TEAMSCALE_API_KEY);
teamscaleUser = readValue(properties, TEAMSCALE_USER);
jiraUrl = readValue(properties, JIRA_URL);
jiraUrl = StringUtils.stripSuffix(readValue(properties, JIRA_URL), "/");
jiraUser = readValue(properties, JIRA_USER);
jiraProject = readValue(properties, JIRA_PROJECT);
jiraEpicKey = readValue(properties, JIRA_EPIC_KEY);
jiraEpicLinkFieldName = readValue(properties, JIRA_EPIC_LINK_FIELD_NAME);
jiraIssueType = Long.parseLong(readValue(properties, JIRA_ISSUE_TYPE));
jiraPassword = readPassword(properties, JIRA_PASSWORD);
taskLinkText = readValue(properties, TASK_LINK_TEXT);
jiraAddtionalFields = buildJiraAddtionalFieldsMap(properties);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package eu.cqse.qcs.jiratasks.jiraclient;

import java.io.IOException;
import java.net.URI;

import org.conqat.lib.commons.net.UrlUtils;

import eu.cqse.qcs.jiratasks.JiraTaskException;
import eu.cqse.qcs.jiratasks.RestClientBase;
Expand Down Expand Up @@ -53,13 +56,24 @@ private void addLinkToTask(Task task, String issueId) throws IOException {
* Creates a new Jira issue from the given {@link Task}
*/
private IssueResponse createNewIssue(Task task) throws IOException {
Issue issue = new Issue(settings.jiraProject, task.getSubject(),
JiraTaskCreatorUtils.convertMarkdownToJira(task.getDescription()), settings.jiraIssueType);
Issue issue = new Issue(settings.jiraProject, task.getSubject(), buildIssueDescription(task),
settings.jiraIssueType);
issue.setAdditionalField(settings.jiraEpicLinkFieldName, settings.jiraEpicKey);
issue.setAddtionalFields(settings.jiraAddtionalFields);
Response<IssueResponse> response = jiraAPI.createIssue(issue).execute();
throwErrorOnUnsuccessfulResponse(response);
return response.body();
}

/**
* Builds the descriptoin Text for the issue
*/
private String buildIssueDescription(Task task) {
String taskLink = "[Task #" + task.getId() + "|" + JiraTaskCreatorUtils.buildUrlForTask(settings, task) + "]";

return JiraTaskCreatorUtils.convertMarkdownToJira(task.getDescription()) + "\n\n"
+ settings.taskLinkText.replace("{task}", taskLink);

}

}

0 comments on commit 5072329

Please sign in to comment.