Skip to content

Commit

Permalink
JENKINS-30682 - Fix NPE on empty Component list in JIRA project. #nom…
Browse files Browse the repository at this point in the history
…erge - this was already changed in master.
  • Loading branch information
Radosław Antoniuk committed Oct 26, 2015
1 parent 344fd75 commit 23ee171
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
26 changes: 17 additions & 9 deletions src/main/java/hudson/plugins/jira/JiraRestService.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/hudson/plugins/jira/JiraSession.java
Expand Up @@ -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());
}
Expand Down

0 comments on commit 23ee171

Please sign in to comment.