Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mark issue status as resolved option #3

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ target
*.ipr
*.iws
work
.idea
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# mantis-plugin

Forked to add some additional functionality for my daily development.

Currently implemented:
* Change issue status to RESOVLED.
7 changes: 4 additions & 3 deletions src/main/java/hudson/plugins/mantis/MantisIssueRegister.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@
import hudson.tasks.BuildStepMonitor;
import hudson.tasks.Publisher;
import hudson.tasks.Recorder;

import java.io.IOException;


import java.io.PrintStream;
import java.util.logging.Logger;

import org.kohsuke.stapler.DataBoundConstructor;

/**
*
* @author Seiji Sogabe
*/
public final class MantisIssueRegister extends Recorder {
Expand Down Expand Up @@ -108,7 +109,7 @@ private String getIssueURL(MantisSite site, int no) {
return site.getIssueLink(no);
}

private MantisIssue createIssue(AbstractBuild<?, ?> build, BuildListener listener)
private MantisIssue createIssue(AbstractBuild<?, ?> build, BuildListener listener)
throws IOException, InterruptedException {
MantisProjectProperty mpp = MantisProjectProperty.get(build);
int projectId = mpp.getProjectId();
Expand All @@ -128,7 +129,7 @@ private MantisIssue createIssue(AbstractBuild<?, ?> build, BuildListener listene
} else {
viewState = MantisViewState.PRIVATE;
}
return new MantisIssue(project, category, summary, description, viewState);
return new MantisIssue(0, project, category, summary, description, viewState, null, null);
}

private String summary(AbstractBuild<?, ?> build) {
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/hudson/plugins/mantis/MantisIssueUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ public final class MantisIssueUpdater extends Recorder {
private final boolean keepNotePrivate;

private final boolean recordChangelog;


private final boolean setStatusResolved;

@DataBoundConstructor
public MantisIssueUpdater(final boolean keepNotePrivate, final boolean recordChangelog) {
public MantisIssueUpdater(final boolean keepNotePrivate, final boolean recordChangelog, final boolean setStatusResolved) {
this.keepNotePrivate = keepNotePrivate;
this.recordChangelog = recordChangelog;
this.setStatusResolved = setStatusResolved;
}

public boolean isKeepNotePrivate() {
Expand All @@ -42,6 +45,10 @@ public boolean isRecordChangelog() {
return recordChangelog;
}

public boolean isSetStatusResolved() {
return setStatusResolved;
}

@Override
public BuildStepMonitor getRequiredMonitorService() {
return BuildStepMonitor.NONE;
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/hudson/plugins/mantis/MantisSite.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public MantisSite(final URL url, final String version, final String userName,
public String getIssueLink(int issueNo) {
String u = getUrl().toExternalForm();
return String.format("%sview.php?id=%d", u, issueNo);
}
}

public boolean isConnect() {
final String urlString = url.toExternalForm();
Expand All @@ -176,7 +176,7 @@ public MantisIssue getIssue(final int id) throws MantisHandlingException {
return session.getIssue(id);
}

public void updateIssue(final int id, final String text, final boolean keepNotePrivate)
public void addNote(final int id, final String text, final boolean keepNotePrivate)
throws MantisHandlingException {

MantisViewState viewState;
Expand Down Expand Up @@ -205,6 +205,11 @@ public int addIssue(MantisIssue issue) throws MantisHandlingException {
final MantisSession session = createSession();
return session.addIssue(issue);
}

public void updateIssue(MantisIssue issue) throws MantisHandlingException {
final MantisSession session = createSession();
session.updateIssue(issue);
}

private MantisSession createSession() throws MantisHandlingException {
return MantisSessionFactory.getSession(this);
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/hudson/plugins/mantis/Updater.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import hudson.plugins.mantis.changeset.ChangeSet;
import hudson.plugins.mantis.changeset.ChangeSetFactory;
import hudson.plugins.mantis.model.MantisIssue;
import hudson.plugins.mantis.model.MantisIssueResolution;
import hudson.plugins.mantis.model.MantisIssueStatus;
import hudson.scm.ChangeLogSet.Entry;

import java.io.PrintStream;
Expand Down Expand Up @@ -69,8 +71,15 @@ boolean perform(final AbstractBuild<?, ?> build, final BuildListener listener) {
try {
final MantisIssue issue = site.getIssue(changeSet.getId());
if (update) {

final String text = createUpdateText(build, changeSet, rootUrl);
site.updateIssue(changeSet.getId(), text, property.isKeepNotePrivate());
site.addNote(changeSet.getId(), text, property.isKeepNotePrivate());

if (property.isSetStatusResolved() && issue.getStatus() != MantisIssueStatus.RESOLVED) {
MantisIssue resolvedIssue = createResolvedIssue(issue);
site.updateIssue(resolvedIssue);
}

Utility.log(logger, Messages.Updater_Updating(changeSet.getId()));
}
issues.add(issue);
Expand All @@ -88,6 +97,11 @@ boolean perform(final AbstractBuild<?, ?> build, final BuildListener listener) {
return true;
}

private MantisIssue createResolvedIssue(MantisIssue issue) {
return new MantisIssue(issue.getId(), issue.getProject(), issue.getCategory(), issue.getDescription(),
issue.getDescription(), issue.getViewState(), MantisIssueStatus.RESOLVED, MantisIssueResolution.FIXED);
}

private String createUpdateText(final AbstractBuild<?, ?> build, final ChangeSet changeSet, final String rootUrl) {
final String prjName = build.getProject().getName();
final int prjNumber = build.getNumber();
Expand Down
25 changes: 19 additions & 6 deletions src/main/java/hudson/plugins/mantis/model/MantisIssue.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*
* @author Seiji Sogabe
*/

import java.io.Serializable;

public final class MantisIssue implements Serializable {
Expand All @@ -20,9 +21,13 @@ public final class MantisIssue implements Serializable {
private MantisProject project;

private MantisCategory category;

private MantisViewState viewState;

private MantisIssueStatus status;

private MantisIssueResolution resolution;

public int getId() {
return id;
}
Expand All @@ -43,21 +48,29 @@ public MantisProject getProject() {
return project;
}

public MantisIssue(final int id, final String summary) {
this.id = id;
this.summary = summary;
public MantisIssueStatus getStatus() {
return status;
}

public MantisViewState getViewState() {
return viewState;
}

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

public MantisIssue(final int id, MantisProject project, MantisCategory category, String summary,
String description, MantisViewState viewState, MantisIssueStatus status, MantisIssueResolution resolution) {
this.id = id;
this.summary = summary;
this.description = description;
this.project = project;
this.category = category;
this.viewState = viewState;
this.status = status;
this.resolution = resolution;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package hudson.plugins.mantis.model;

/**
* View State for Issue and Note.
*
* @author Seiji Sogabe
*/
public enum MantisIssueResolution {

FIXED(20);

private int code;

MantisIssueResolution(final int code) {
this.code = code;
}

public static MantisIssueResolution fromCode(int code) {
switch (code) {
case 20:
return FIXED;
default:
return null;
}
}

public int getCode() {
return code;
}
}
42 changes: 42 additions & 0 deletions src/main/java/hudson/plugins/mantis/model/MantisIssueStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package hudson.plugins.mantis.model;

public enum MantisIssueStatus {


FEEDBACK(20),
ACKNOWLEDGED(30),
CONFIRMED(40),
ASSIGNED(50),
RESOLVED(80),
CLOSED(90);

private int code;

MantisIssueStatus(final int code) {
this.code = code;
}


public static MantisIssueStatus fromCode(int code) {
switch (code) {
case 20:
return FEEDBACK;
case 30:
return ACKNOWLEDGED;
case 40:
return CONFIRMED;
case 50:
return ASSIGNED;
case 80:
return RESOLVED;
case 90:
return CLOSED;
default:
return null;
}
}

public int getCode() {
return code;
}
}
13 changes: 12 additions & 1 deletion src/main/java/hudson/plugins/mantis/model/MantisViewState.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,21 @@ public enum MantisViewState {

private int code;

private MantisViewState(final int code) {
MantisViewState(final int code) {
this.code = code;
}

public static MantisViewState fromCode(int code) {
switch (code) {
case 10:
return PUBLIC;
case 50:
return PRIVATE;
default:
return null;
}
}

public int getCode() {
return code;
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/hudson/plugins/mantis/soap/MantisSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ public interface MantisSession {
List<MantisCategory> getCategories(int projectId) throws MantisHandlingException;

int addIssue(MantisIssue issue) throws MantisHandlingException;

void updateIssue(MantisIssue issue) throws MantisHandlingException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

import hudson.plugins.mantis.MantisHandlingException;
import hudson.plugins.mantis.MantisSite;
import hudson.plugins.mantis.model.MantisCategory;
import hudson.plugins.mantis.model.MantisIssue;
import hudson.plugins.mantis.model.MantisNote;
import hudson.plugins.mantis.model.MantisProject;
import hudson.plugins.mantis.model.*;
import hudson.plugins.mantis.soap.AbstractMantisSession;

import java.math.BigInteger;
import java.net.MalformedURLException;
import java.net.URL;
Expand All @@ -15,6 +13,7 @@
import java.util.List;
import java.util.logging.Logger;
import javax.xml.rpc.ServiceException;

import org.apache.axis.AxisProperties;
import org.apache.axis.EngineConfiguration;
import org.apache.axis.client.AxisClient;
Expand Down Expand Up @@ -65,7 +64,11 @@ public MantisIssue getIssue(final int id) throws MantisHandlingException {
throw new MantisHandlingException(e);
}

return new MantisIssue(id, data.getSummary());
return new MantisIssue(id, new MantisProject(data.getProject().getId().intValue(), data.getProject().getName()),
new MantisCategory(data.getCategory()), data.getSummary(), data.getDescription(),
MantisViewState.fromCode(data.getView_state().getId().intValue()),
MantisIssueStatus.fromCode(data.getStatus().getId().intValue()),
MantisIssueResolution.fromCode(data.getStatus().getId().intValue()));
}

public void addNote(final int id, final MantisNote note)
Expand Down Expand Up @@ -164,5 +167,41 @@ public int addIssue(MantisIssue issue) throws MantisHandlingException {
return addedIssueNo.intValue();
}

@Override
public void updateIssue(MantisIssue issue) throws MantisHandlingException {
if (issue == null) {
throw new MantisHandlingException("issue should not be null.");
}
IssueData data = new IssueData();

MantisProject project = issue.getProject();
if (project == null) {
throw new MantisHandlingException("project is missing.");
}
MantisCategory category = issue.getCategory();
if (category == null) {
throw new MantisHandlingException("category is missing.");
}

data.setId(BigInteger.valueOf(issue.getId()));
ObjectRef pRef = new ObjectRef(BigInteger.valueOf(project.getId()), project.getName());
data.setProject(pRef);
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);
ObjectRef statusRef = new ObjectRef(BigInteger.valueOf(issue.getStatus().getCode()), null);
data.setStatus(statusRef);
ObjectRef resolutionRef = new ObjectRef(BigInteger.valueOf(issue.getResolution().getCode()), null);
data.setResolution(resolutionRef);

try {
portType.mc_issue_update(site.getUserName(), site.getPlainPassword(), BigInteger.valueOf(issue.getId()), data);
} catch (RemoteException e) {
throw new MantisHandlingException(e);
}
}

private static final Logger LOGGER = Logger.getLogger(MantisSessionImpl.class.getName());
}
Loading