Skip to content

Commit

Permalink
[FIXED JENKINS-18038] keep ticket private
Browse files Browse the repository at this point in the history
  • Loading branch information
ssogabe committed May 22, 2013
1 parent 4210c1d commit fb80db9
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 12 deletions.
18 changes: 16 additions & 2 deletions src/main/java/hudson/plugins/mantis/MantisIssueRegister.java
Expand Up @@ -11,6 +11,7 @@
import hudson.plugins.mantis.model.MantisCategory;
import hudson.plugins.mantis.model.MantisIssue;
import hudson.plugins.mantis.model.MantisProject;
import hudson.plugins.mantis.model.MantisViewState;
import hudson.plugins.mantis.scripts.JellyScriptContent;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.BuildStepMonitor;
Expand All @@ -31,18 +32,25 @@ public final class MantisIssueRegister extends Recorder {

private String threshold;

private boolean keepTicketPrivate;

public static final String FAILURE = "failure";

public static final String FAILUREORUNSTABL = "failureOrUnstable";

@DataBoundConstructor
public MantisIssueRegister(String threshold) {
public MantisIssueRegister(String threshold, boolean keepTicketPrivate) {
this.threshold = Util.fixEmptyAndTrim(threshold);
this.keepTicketPrivate = keepTicketPrivate;
}

public String getThreshold() {
return threshold;
}

public boolean isKeepTicketPrivate() {
return keepTicketPrivate;
}

public BuildStepMonitor getRequiredMonitorService() {
return BuildStepMonitor.NONE;
Expand Down Expand Up @@ -113,7 +121,13 @@ private MantisIssue createIssue(AbstractBuild<?, ?> build, BuildListener listene
MantisCategory category = new MantisCategory(categoryName);
String summary = summary(build);
String description = new JellyScriptContent().getContent(build, build.getResult());
return new MantisIssue(project, category, summary, description);
MantisViewState viewState;
if (isKeepTicketPrivate()) {
viewState = MantisViewState.PUBLIC;
} else {
viewState = MantisViewState.PRIVATE;
}
return new MantisIssue(project, category, summary, description, viewState);
}

private String summary(AbstractBuild<?, ?> build) {
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/hudson/plugins/mantis/model/MantisIssue.java
Expand Up @@ -20,6 +20,8 @@ public final class MantisIssue implements Serializable {
private MantisProject project;

private MantisCategory category;

private MantisViewState viewState;

public int getId() {
return id;
Expand All @@ -46,10 +48,16 @@ public MantisIssue(final int id, final String summary) {
this.summary = summary;
}

public MantisIssue(MantisProject project, MantisCategory category, String summary, String description) {
public MantisViewState getViewState() {
return viewState;
}

public MantisIssue(MantisProject project, MantisCategory category, String summary,
String description, MantisViewState viewState) {
this.summary = summary;
this.description = description;
this.project = project;
this.category = category;
this.viewState = viewState;
}
}
Expand Up @@ -151,7 +151,9 @@ public int addIssue(MantisIssue issue) throws MantisHandlingException {
data.setCategory(category.getName());
data.setSummary(issue.getSummary());
data.setDescription(issue.getDescription());

ObjectRef viewStateRef = new ObjectRef(BigInteger.valueOf(issue.getViewState().getCode()), null);
data.setView_state(viewStateRef);

BigInteger addedIssueNo = null;
try {
addedIssueNo = portType.mc_issue_add(site.getUserName(), site.getPassword(), data);
Expand Down
Expand Up @@ -150,7 +150,9 @@ public int addIssue(MantisIssue issue) throws MantisHandlingException {
data.setCategory(category.getName());
data.setSummary(issue.getSummary());
data.setDescription(issue.getDescription());

ObjectRef viewStateRef = new ObjectRef(BigInteger.valueOf(issue.getViewState().getCode()), null);
data.setView_state(viewStateRef);

BigInteger addedIssueNo = null;
try {
addedIssueNo = portType.mc_issue_add(site.getUserName(), site.getPassword(), data);
Expand Down
@@ -1,7 +1,7 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<f:entry title="${%Build status}" >
<label>
<f:entry title="${%Build status}">
<label>
<f:radio name="mantis.threshold" value="failure"
checked="${instance.threshold==null || instance.threshold=='failure'}" />
${%failure}
Expand All @@ -11,5 +11,10 @@
checked="${instance.threshold=='failureOrUnstable'}" />
${%failure or unstable}
</label>
</f:entry>
</f:entry>
<f:entry title="" field="keepTicketPrivate">
<label>
<f:checkbox />${%Keep ticket private}
</label>
</f:entry>
</j:jelly>
@@ -1,3 +1,4 @@
Build\ status=\u30d3\u30eb\u30c9\u306e\u72b6\u614b
failure=\u5931\u6557
failure\ or\ unstable=\u5931\u6557\u304b\u4e0d\u5b89\u5b9a
failure\ or\ unstable=\u5931\u6557\u304b\u4e0d\u5b89\u5b9a
Keep\ ticket\ private=\u30c1\u30b1\u30c3\u30c8\u3092\u975e\u516c\u958b\u306b\u3059\u308b
17 changes: 14 additions & 3 deletions src/test/java/hudson/plugins/mantis/MantisSiteTest.java
Expand Up @@ -3,6 +3,7 @@
import hudson.plugins.mantis.model.MantisCategory;
import hudson.plugins.mantis.model.MantisIssue;
import hudson.plugins.mantis.model.MantisProject;
import hudson.plugins.mantis.model.MantisViewState;
import java.net.MalformedURLException;
import java.net.URL;
import org.junit.After;
Expand Down Expand Up @@ -80,14 +81,24 @@ public void updateIssue() throws MantisHandlingException {
@Test
public void addIssue() throws MantisHandlingException {
target = createMantisSite();
String summary = "Build failed";
String summary = "Build failed(Public)";
String description = "Added by Jenkins Mantis Plugin.";
MantisProject project = new MantisProject(2, "Jenkins Project");
MantisCategory category = new MantisCategory("plugin");
MantisIssue issue = new MantisIssue(project, category, summary, description);
MantisIssue issue = new MantisIssue(project, category, summary, description, MantisViewState.PUBLIC);
target.addIssue(issue);
}


@Test
public void addIssue_private() throws MantisHandlingException {
target = createMantisSite();
String summary = "Build failed(Private)";
String description = "Added by Jenkins Mantis Plugin.";
MantisProject project = new MantisProject(2, "Jenkins Project");
MantisCategory category = new MantisCategory("plugin");
MantisIssue issue = new MantisIssue(project, category, summary, description, MantisViewState.PRIVATE);
target.addIssue(issue);
}
private MantisSite createMantisSite() {
return new MantisSite(mantisUrl, "V120", "jenkinsci", "jenkinsci", null, null);
}
Expand Down

0 comments on commit fb80db9

Please sign in to comment.