How to get sprints using greenhopper api?

AKramskoy October 2, 2012

Hello.

I need to get sprint from my class. I tried to use com.atlassian.greenhopper.service.sprint.SprintService, but I coudn't inject it. How can I get spints of project?

Thanks.

3 answers

1 accepted

0 votes
Answer accepted
sclowes
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 3, 2012

Unfortunately there is no public service exported for this.

The only safe way to do this would be to get an issue that has that Sprint in its Sprint field, then query the custom field.

Alternatively you could use reflection to get access to the private SprintService you describe above, but because this is a private service we wouldn't recommend it.

Cheers,
Shaun

AKramskoy October 3, 2012

Hello.

Thank you very much for fast answer!

I am newbie with JIRA and Greenhopper plugins. Could you please assist a bit more. I do not see any trace of "sprint" field in documentation for "issue":

https://developer.atlassian.com/display/JIRADEV/Issue+fields

I am probably missing something and would really appreciate your help.

Thanks.

0 votes
Renjith Pillai
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 3, 2012

Get the custom field values of the issue and Sprint is also a custom field as Shaun said. It should give the id as numeric value.

Getting issues in a sprint can be done using a JQL with Sprint = <<id>>, I guess it is the SearchService that will help you to do this.

https://developer.atlassian.com/display/JIRADEV/Plugin+Tutorial+-+JIRA+Issue+CRUD+and+Search

AKramskoy October 3, 2012

Thanks everyone for help!!!

The final working solution is:

1. Get list of issues for the project(see doc at https://developer.atlassian.com/display/JIRADEV/Plugin+Tutorial+-+JIRA+Issue+CRUD+and+Search)

2. for (Issue issue : issues){
CustomField customField = customFieldManager.getCustomFieldObjectByName( "Sprint" );

// retrieves the custom field value object from the issue
Object customFieldValue = issue.getCustomFieldValue( customField );

// prints value to console
System.out.println( customFieldValue );

}

3. Output prints similar to

* if issue was only in a single sprint:

[com.atlassian.greenhopper.service.sprint.Sprint@1bacc22[name=Sprint 1,closed=true,startDate=2
012-10-02T08:47:07.160-04:00,endDate=2012-10-05T08:47:00.000-04:00,completeDate=2012-10-04T10:04:47.556-04:00,id=1]]

*if issue has been moved from sprint to sprint (not sure if this is an issue or done in purpose by jira):

[com.atlassian.greenhopper.service.sprint.Sprint@1bacc22[name=Sprint 1,closed=true,startDate=2
012-10-02T08:47:07.160-04:00,endDate=2012-10-05T08:47:00.000-04:00,completeDate=2012-10-04T10:04:47.556-04:00,id=1], com.atlassian.greenhopper.service.sprint.Sprint@186cee5[name=Sprint 2, closed=false,startDate=2012-10-04T10:05:37.479-04:00,endDate=
2012-10-18T10:05:37.479-04:00,completeDate=<null>,id=2]]

Terry Jeske November 26, 2012

Thx for posting, I was having the same problem. I have been trying to cast the Sprint object from the custom field value (array of sprints). However, I get a ClassCastException. I made sure the greenhopper jar was added to my plugin, but it still says it cannot cast:

com.atlassian.greenhopper.service.sprint.Sprint to com.atlassian.greenhopper.service.sprint.Sprint

I even tried to get the at the getters using reflection but that failed. Finally as a work around I just parsed the toString output (yuck). Were you ever able to cast the Sprint object?

Terry Jeske November 26, 2012

Nevermind. Looks like the group ID for the greenhopper has changed com.atlassian.plugins

with the artifactID jira-greenhopper-plugin

0 votes
Renjith Pillai
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 3, 2012

The REST api can get you the data, but I am not sure within the plugin how to handle the authentication.

E.g. https://jira.atlassian.com/plugins/servlet/restbrowser#/com-pyxis-greenhopper-jira-greenhopper-rest-filter

Check /sprints/{rapidViewId}

AKramskoy October 3, 2012

Thank you very much - that helped!

/sprints/{rapidViewId} produces something like this:

{"sprints":[{"id":1,"name":"Sprint 1","closed":true},{"id":2,"name":"Sprint 2","closed":false}],"rapidViewId":1}

But the question still remains:
1.What issue field describes which sprint it belongs to?
2.If we know sprint ID - how do we get issues in this sprint?





Suggest an answer

Log in or Sign up to answer