Skip to content
Permalink
Browse files
JENKINS-30682 - Fix NPE on empty Component list in JIRA project. #nom…
…erge - this was already changed in master.
  • Loading branch information
Radosław Antoniuk committed Oct 26, 2015
1 parent 344fd75 commit 23ee171d68e52c2f6634f11405c9620411a5c543
Showing 3 changed files with 20 additions and 12 deletions.
@@ -153,6 +153,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
private Issue createJiraIssue(AbstractBuild<?, ?> build, String filename) throws IOException, InterruptedException {

EnvVars vars = build.getEnvironment(TaskListener.NULL);
JiraSession session = getJiraSession(build);

String buildName = getBuildName(vars);
String summary = String.format("Build %s failed", buildName);
@@ -162,9 +163,8 @@ private Issue createJiraIssue(AbstractBuild<?, ?> build, String filename) throws
buildName,
getBuildDetailsString(vars)
);
List<BasicComponent> components = getJiraComponents(build, this.component);
Iterable<String> components = Splitter.on(",").trimResults().omitEmptyStrings().split(component);

JiraSession session = getJiraSession(build);
Issue issue = session.createIssue(projectKey, description, assignee, components, summary);

writeInFile(filename, issue);
@@ -24,6 +24,7 @@
import com.atlassian.jira.rest.client.api.domain.input.VersionInput;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang.StringUtils;
@@ -212,18 +213,25 @@ public void releaseVersion(String projectKey, Version version) {
}
}

public BasicIssue createIssue(String projectKey, String description, String assignee, Iterable<BasicComponent> components, String summary) {
final IssueInput issueInput = new IssueInputBuilder().setProjectKey(projectKey)
.setDescription(description)
.setAssigneeName(assignee)
.setComponents(components)
.setIssueTypeId(1L) // BUG
.setSummary(summary)
.build();
public BasicIssue createIssue(String projectKey, String description, String assignee, Iterable<String> components, String summary) {
IssueInputBuilder builder = new IssueInputBuilder();
builder.setProjectKey(projectKey)
.setDescription(description)
.setIssueTypeId(1L) // BUG
.setSummary(summary);

if (!assignee.equals(""))
builder.setAssigneeName(assignee);
if (Iterators.size(components.iterator()) > 0){
builder.setComponentsNames(components);
}

final IssueInput issueInput = builder.build();

try {
return jiraRestClient.getIssueClient().createIssue(issueInput).get(10, TimeUnit.SECONDS);
} catch (Exception e) {
LOGGER.warning("jira rest client create issue error. cause: " + e.getMessage());
LOGGER.warning("JIRA REST createIssue error: " + e.getMessage());
return null;
}
}
@@ -300,7 +300,7 @@ private HashMap<Long, String> getKnownStatuses() {
* @param summary
* @return The issue id
*/
public Issue createIssue(String projectKey, String description, String assignee, List<BasicComponent> components, String summary) {
public Issue createIssue(String projectKey, String description, String assignee, Iterable<String> components, String summary) {
final BasicIssue basicIssue = service.createIssue(projectKey, description, assignee, components, summary);
return service.getIssue(basicIssue.getKey());
}

0 comments on commit 23ee171

Please sign in to comment.