|
From: <lac...@us...> - 2007-10-04 13:13:29
|
Revision: 51
http://td2jira.svn.sourceforge.net/td2jira/?rev=51&view=rev
Author: lacostej
Date: 2007-10-04 06:13:31 -0700 (Thu, 04 Oct 2007)
Log Message:
-----------
Support closing of issues in Jira (only works in XML-RPC connector)
Modified Paths:
--------------
trunk/td2jira/docs/ReleaseNotes.txt
trunk/td2jira/src/td2jira/jira/soap/JIRASoapConnector.java
trunk/td2jira/src/td2jira/jira/xmlrpc/JIRAXmlRpcConnector.java
Modified: trunk/td2jira/docs/ReleaseNotes.txt
===================================================================
--- trunk/td2jira/docs/ReleaseNotes.txt 2007-10-04 12:55:10 UTC (rev 50)
+++ trunk/td2jira/docs/ReleaseNotes.txt 2007-10-04 13:13:31 UTC (rev 51)
@@ -13,5 +13,9 @@
* FEATURE Create JIRA issues with the right assignee
* FEATURE allow to switch TD from read-only to read-write (defaults to read-only).
* WORK-AROUND a failure to retrieve some attachments from TD. May be a TD issue or some sort of jacob/TD combination problem.
+* FEATURE Supports closing of issues in Jira (only works for XML-RPC)
+ TODO document differences between both connectors
Old release
+
+TODO fill
\ No newline at end of file
Modified: trunk/td2jira/src/td2jira/jira/soap/JIRASoapConnector.java
===================================================================
--- trunk/td2jira/src/td2jira/jira/soap/JIRASoapConnector.java 2007-10-04 12:55:10 UTC (rev 50)
+++ trunk/td2jira/src/td2jira/jira/soap/JIRASoapConnector.java 2007-10-04 13:13:31 UTC (rev 51)
@@ -12,11 +12,7 @@
import td2jira.jira.JIRAComment;
import td2jira.jira.JIRAIssue;
-import com.atlassian.jira.rpc.soap.beans.RemoteAttachment;
-import com.atlassian.jira.rpc.soap.beans.RemoteComment;
-import com.atlassian.jira.rpc.soap.beans.RemoteField;
-import com.atlassian.jira.rpc.soap.beans.RemoteFieldValue;
-import com.atlassian.jira.rpc.soap.beans.RemoteIssue;
+import com.atlassian.jira.rpc.soap.beans.*;
import com.atlassian.jira.rpc.soap.jirasoapservice_v2.JiraSoapService;
import com.atlassian.jira.rpc.soap.jirasoapservice_v2.JiraSoapServiceService;
import com.atlassian.jira.rpc.soap.jirasoapservice_v2.JiraSoapServiceServiceLocator;
@@ -55,10 +51,18 @@
try {
final String closedMarker = "(CLOSED@TD)";
String summary = jiraIssue.getSummary();
- if (summary.indexOf(closedMarker) >= 0) return;
- jiraIssue.setSummary(closedMarker + summary);
+ String status = jiraIssue.getStatus();
+ if (status.equals("Closed"))
+ return;
logger.info("marking " + jiraIssue.getKey() + " issue as to be closed");
- updateSummary(jiraIssue);
+ jiraIssue.setStatus("Closed");
+ jiraIssue.setResolution("Fixed");
+ if (summary.indexOf(closedMarker) == -1) {
+ jiraIssue.setSummary(closedMarker + summary);
+ updateSummary(jiraIssue);
+ }
+ progressWorkflowAction(jiraIssue, "2");
+
} catch (Exception ex) {
throw new RuntimeException(ex);
}
@@ -92,7 +96,9 @@
ji.setAssignee(issue.getAssignee());
ji.setDescription(issue.getDescription());
ji.setProjectId(issue.getProject());
- ji.setStatus(issue.getStatus());
+ // ji.setResolution(JIRAIssue.resolutions.get(issue.getResolution()));
+ // ji.setResolution(issue.getResolution());
+ ji.setStatus(JIRAIssue.statuses.get(issue.getStatus()));
ji.setSummary(issue.getSummary());
ji.setId(issue.getId());
tasks.add(ji);
@@ -139,6 +145,16 @@
JiraSoapServiceService jiraSoapServiceGetter = new JiraSoapServiceServiceLocator();
svc = jiraSoapServiceGetter.getJirasoapserviceV2(new URL(url + "/rpc/soap/jirasoapservice-v2"));
token = svc.login(user, password);
+
+ RemoteStatus[] statuses = svc.getStatuses(token);
+ for (RemoteStatus status : statuses) {
+ JIRAIssue.statuses.put(status.getId(), status.getName());
+ }
+
+ RemoteResolution[] resolutions = svc.getResolutions(token);
+ for (RemoteResolution resolution : resolutions) {
+ JIRAIssue.resolutions.put(resolution.getId(), resolution.getName());
+ }
} catch (Exception ex) {
throw new RuntimeException(ex);
}
@@ -148,6 +164,7 @@
try {
svc.logout(token);
} catch (Exception ex) {
+ logger.warn("Couldn't properly logout from JIRA. Ignoring...", ex);
}
token = null;
svc = null;
@@ -176,19 +193,27 @@
private void updateSummary(JIRAIssue jiraIssue) {
try {
- RemoteField[] fields = svc.getFieldsForEdit(token, jiraIssue.getKey());
+ RemoteFieldValue rfvSummary = new RemoteFieldValue();
+ rfvSummary.setId("summary");
+ rfvSummary.setValues(new String[]{jiraIssue.getSummary()});
- RemoteFieldValue rfv = new RemoteFieldValue();
- rfv.setValues(new String[]{jiraIssue.getSummary()});
+ svc.updateIssue(token, jiraIssue.getKey(), new RemoteFieldValue[]{rfvSummary});
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
- for (RemoteField field : fields) {
- if (field.getName().equals("summary")) {
- rfv.setId(field.getId());
- break;
- }
- }
+ private void progressWorkflowAction(JIRAIssue jiraIssue, String actionId) {
+ try {
+ RemoteFieldValue rfvStatus = new RemoteFieldValue();
+ rfvStatus.setId("status");
+ rfvStatus.setValues(new String[]{jiraIssue.getStatus()});
- svc.updateIssue(token, jiraIssue.getKey(), new RemoteFieldValue[]{rfv});
+ RemoteFieldValue rfvAssignee = new RemoteFieldValue();
+ rfvAssignee.setId("assignee");
+ rfvAssignee.setValues(new String[]{jiraIssue.getAssignee()});
+
+ svc.progressWorkflowAction(token, jiraIssue.getKey(), actionId, new RemoteFieldValue[]{rfvStatus, rfvAssignee});
} catch (Exception ex) {
throw new RuntimeException(ex);
}
Modified: trunk/td2jira/src/td2jira/jira/xmlrpc/JIRAXmlRpcConnector.java
===================================================================
--- trunk/td2jira/src/td2jira/jira/xmlrpc/JIRAXmlRpcConnector.java 2007-10-04 12:55:10 UTC (rev 50)
+++ trunk/td2jira/src/td2jira/jira/xmlrpc/JIRAXmlRpcConnector.java 2007-10-04 13:13:31 UTC (rev 51)
@@ -213,6 +213,8 @@
try {
Map issue = (Map) rpcClient.execute("jira1.getIssue", params(token, jiraIssue.getKey()));
issue.put("summary", jiraIssue.getSummary());
+ // status cannot be updated here: http://jira.atlassian.com/browse/CONF-6959
+ // issue.put("status",jiraIssue.getStatus());
Map issue2 = vectorizeValues(issue);
Object o = rpcClient.execute("jira1.updateIssue", params(token, jiraIssue.getKey(), issue2));
} catch (Exception ex) {
@@ -220,6 +222,23 @@
}
}
+ private void progressWorkflowAction(JIRAIssue jiraIssue, String actionId) {
+ // not implemented in XML RPC
+ return;
+ /*
+ // see http://www.nabble.com/-JIRA-user--setting-a-resolution-and-status-when-creating-an-issue-using-SOAP-api-t2921588.html
+ // http://Your_Host:Port/secure/admin/workflows/ViewWorkflowSteps.jspa?workflowName=jira
+ try {
+ Map issue = (Map) rpcClient.execute("jira1.getIssue", params(token,jiraIssue.getKey()));
+ issue.put("status",jiraIssue.getStatus());
+ Map issue2 = vectorizeValues(issue);
+ Object o = rpcClient.execute("jira1.progressWorkflowAction", params(token,jiraIssue.getKey(),actionId,issue2));
+ } catch( Exception ex ) {
+ throw new RuntimeException(ex);
+ }
+ */
+ }
+
@SuppressWarnings("unchecked")
private Map<String, Object>[] convertToMapArray(Object[] objects) {
Map[] ret = new Map[objects.length];
@@ -243,10 +262,18 @@
try {
final String closedMarker = "(CLOSED@TD)";
String summary = jiraIssue.getSummary();
- if (summary.indexOf(closedMarker) >= 0) return;
- jiraIssue.setSummary(closedMarker + summary);
- logger.info("marking JIRA issue as closed: " + jiraIssue.getKey());
- updateSummary(jiraIssue);
+ String status = jiraIssue.getStatus();
+ if (status.equals("Closed"))
+ return;
+ logger.info("marking " + jiraIssue.getKey() + " issue as to be closed");
+ jiraIssue.setStatus("Closed");
+ jiraIssue.setResolution("Fixed");
+ if (summary.indexOf(closedMarker) == -1) {
+ jiraIssue.setSummary(closedMarker + summary);
+ updateSummary(jiraIssue);
+ }
+ progressWorkflowAction(jiraIssue, "2");
+
} catch (Exception ex) {
throw new RuntimeException(ex);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|