Monday, July 26, 2010

Jira and SOAP: Part III

The saga of using Perl code to communicate via Jira's SOAP API. See part I and part II here. In part I, we logged and updated issues. In part II, we were able to get status information about an issue. In our final part, we'll actually reopen the issue:

#####################################################################
# Reopen a Jira issue
#
# @param params{issue} The issue key (e.g., PERMA-12345)
# @param params{assignee} The intended assignee
#
# @return The jira issue number
##
sub reopenIssue {
my ($self, %params) = assertMinArgs(1, @_);
$params{issue } ||= '';
my %issue;
$issue{issueKey} = SOAP::Data->type(string => $params{issue});
$issue{assignee} = $params{assignee};
$issue{summary} = $self->_getIssueSummary(issue => $params{issue});
$issue{newStatus} = SOAP::Data->type(string => "3"); #reopened
my $result = $self->_request('progressWorkflowAction', 1, \%issue);
return $result;
}

It's pretty simple, in the end. We're using the progressWorkflowAction call, which changes an issue from one status to another. We simply create our issue object with all the required attributes (in our case, summary, assignee, the new status, and the issue key) and then call progressWorkflowAction. This call will fail if the user doesn't have permission to make that transition, or if the transition doesn't apply (e.g., attempting to close a closed issue).

And that ends the Jira and SOAP tutorial, at least for now. Good luck!

No comments:

Post a Comment