Skip to content
Permalink
Browse files
Merge pull request #65 from jenkinsci/jira-2.0.3
JENKINS-30682 - Fix NPE on empty Component list in JIRA project.
  • Loading branch information
Radosław Antoniuk committed Oct 26, 2015
2 parents 1a17705 + 43f5439 commit c3c8ca670a38913a2a9398a85662a0bbb8301638
Showing 3 changed files with 34 additions and 22 deletions.
@@ -2,11 +2,16 @@

import com.atlassian.jira.rest.client.api.domain.Component;
import com.atlassian.jira.rest.client.api.domain.Issue;
import com.google.common.base.Splitter;
import hudson.EnvVars;
import hudson.Extension;
import hudson.Launcher;
import hudson.Util;
import hudson.model.*;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.BuildListener;
import hudson.model.Result;
import hudson.model.TaskListener;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.BuildStepMonitor;
import hudson.tasks.Notifier;
@@ -18,7 +23,12 @@
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;

import java.io.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -145,11 +155,11 @@ private Issue createJiraIssue(AbstractBuild<?, ?> build, String filename) throws
String description = String.format("The test %s has failed. \n\n%s\n\n* First failed run : [%s|%s]\n** [console log|%s]",
jobName, checkDescription, buildNumber, buildURL, buildURL.concat("console"));

List<Component> components = getJiraComponents(build, this.component);

JiraSession session = getJiraSession(build);
String summary = "Test " + jobName + " failure - " + jenkinsURL;

JiraSession session = getJiraSession(build);
Iterable<String> components = Splitter.on(",").trimResults().omitEmptyStrings().split(component);

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

//writing the issue-id to the file, which is present in job's directory.
@@ -23,6 +23,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;
@@ -211,18 +212,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;
}
}
@@ -299,14 +299,8 @@ private HashMap<Long, String> getKnownStatuses() {
* @param summary
* @return The issue id
*/
public Issue createIssue(String projectKey, String description, String assignee, List<Component> components, String summary) {

final List<BasicComponent> basicComponents = new ArrayList<BasicComponent>();
for (final Component component : components) {
basicComponents.add(component);
}

final BasicIssue basicIssue = service.createIssue(projectKey, description, assignee, basicComponents, 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 c3c8ca6

Please sign in to comment.