Greenhopper - Howto put an issue into sprint using groovy?

I would like to put an issue into a sprint via a scriptrunner post-action.

My problem is that I cannot access the SprintIssueService. The following code will return sprintIssueService not found:

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.plugin.PluginAccessor

// get user and issue
def jiraAuthenticationContext = ComponentAccessor.getJiraAuthenticationContext()
def user = jiraAuthenticationContext.getUser()
Issue issue = ComponentAccessor.getIssueManager().getIssueObject("ABC-123")

// access greenhopper
PluginAccessor pluginAccessor = ComponentAccessor.getPluginAccessor();
Class greenHopperClass = pluginAccessor.getClassLoader().findClass("com.pyxis.greenhopper.GreenHopper");
def greenHopper = componentManager.getOSGiComponentInstanceOfType(greenHopperClass);

if (! greenHopper ) {
  return "greeenHopper not found"
}

// access SprintIssueService
Class sprintIssueServiceClass = pluginAccessor.getClassLoader().findClass("com.atlassian.greenhopper.service.sprint.SprintIssueService")
def sprintIssueService = componentManager.getOSGiComponentInstanceOfType(sprintIssueServiceClass);
 

if (! sprintIssueService ) {
  return "sprintIssueService not found"
} else { 
  return sprintIssueService.getSprintsForIssue(user, issue)
}

Can someone help?

3 answers

1 accepted

0 votes
Accepted answer

As one can only access the sprints via REST api, one has to use some HTTPClient (e.g. org.apache.commons.httpclient.HttpClient) to get it done.

The last post of the following shows a code example of that:

https://answers.atlassian.com/questions/49588/how-can-i-access-the-list-of-gh-sprints-programmatically-from-workflow-post-functions

That's sad but I think you are right. The sprintIssueService is not public/exposed and the only way to access it is via REST. So I have to rethink my idea with a post-action :-/

From my experience most of the Service objects from GreenHopper are not exposed to other plugins. You'd be best attempting to do it via the REST interface. Not that GH has a published REST interface but you can discover it fine using the Developer Tools plugin and REST browser in that.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted 7 hours ago in Canada

Happy New Year - First AUG of the year - great success

Hi Everyone, Hope everyone had a great holiday season and is ready for an exciting 2019.  We had our first AUG last night featuring Tempo Timesheets.  A great presentation and lots of int...

10 views 0 1
View post

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you