Skip to content

Commit

Permalink
Add support for generic fields
Browse files Browse the repository at this point in the history
  • Loading branch information
pfaller committed Nov 14, 2019
1 parent 53a3849 commit 11fa8ab
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 17 deletions.
2 changes: 2 additions & 0 deletions eu.cqse.qcs.jiratasks/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,7 @@ dependencies {
testImplementation 'junit:junit:4.12'
}



// Define the main class for the application
mainClassName = 'eu.cqse.qcs.jiratasks.JiraTaskCreator'
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import java.io.Console;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;

import org.conqat.lib.commons.filesystem.FileSystemUtils;
Expand All @@ -25,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 ADDITIONAL_JIRA_FIELD_PREFIX = "jiraField.";

public final String teamscaleProject;
public final String teamscaleUrl;
Expand All @@ -37,6 +41,7 @@ public class TasksToJiraSettings {
public final Long jiraIssueType;
public final String jiraEpicKey;
public final String jiraEpicLinkFieldName;
public final Map<String, Object> jiraAddtionalFields;

public TasksToJiraSettings(File propertiesFile) throws IOException {
Properties properties = FileSystemUtils.readPropertiesFile(propertiesFile);
Expand All @@ -51,6 +56,19 @@ public TasksToJiraSettings(File propertiesFile) throws IOException {
jiraEpicLinkFieldName = readValue(properties, JIRA_EPIC_LINK_FIELD_NAME);
jiraIssueType = Long.parseLong(readValue(properties, JIRA_ISSUE_TYPE));
jiraPassword = readPassword(properties, JIRA_PASSWORD);
jiraAddtionalFields = buildJiraAddtionalFieldsMap(properties);
}

private static Map<String, Object> buildJiraAddtionalFieldsMap(Properties properties) {
Map<String, Object> additionalFields = new HashMap<>();
for (Entry<Object, Object> entry : properties.entrySet()) {
String key = (String) entry.getKey();
if (!key.startsWith(ADDITIONAL_JIRA_FIELD_PREFIX)) {
continue;
}
additionalFields.put(StringUtils.stripPrefix(key, ADDITIONAL_JIRA_FIELD_PREFIX), entry.getValue());
}
return additionalFields;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ public void setAdditionalField(String fieldId, Object value) {
fields.put(fieldId, value);
}

/**
* Sets additional field values from the given map.
*/
public void setAddtionalFields(Map<String, Object> additionalFieldsMap) {
fields.putAll(additionalFieldsMap);
}

public Map<String, Object> getFields() {
return fields;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package eu.cqse.qcs.jiratasks.jiraclient;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
* Response data after creating an issue.
*/
@JsonIgnoreProperties({ "self" })
public class IssueResponse {

/** Jira JSON field name */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ private IssueResponse createNewIssue(Task task) throws IOException {
Issue issue = new Issue(settings.jiraProject, task.getSubject(),
JiraTaskCreatorUtils.convertMarkdownToJira(task.getDescription()), settings.jiraIssueType);
issue.setAdditionalField(settings.jiraEpicLinkFieldName, settings.jiraEpicKey);
issue.setAddtionalFields(settings.jiraAddtionalFields);
Response<IssueResponse> response = jiraAPI.createIssue(issue).execute();
throwErrorOnUnsuccessfulResponse(response);
return response.body();
Expand Down
3 changes: 2 additions & 1 deletion eu.cqse.qcs.jiratasks/src/main/resources/settings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ teamscaleApiKey=demo
## Project configuration
jiraProject=JIR
jiraEpicKey=JIR-2
teamscaleProject=demo
teamscaleProject=demo
jiraField.customfield_10000=foo
1 change: 1 addition & 0 deletions eu.cqse.qcs.jiratasks/src/test/resources/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/settings.properties
16 changes: 0 additions & 16 deletions eu.cqse.qcs.jiratasks/src/test/resources/settings.properties

This file was deleted.

0 comments on commit 11fa8ab

Please sign in to comment.