Skip to content

Instantly share code, notes, and snippets.

@jechlin
Created December 15, 2015 12:11
Show Gist options
  • Save jechlin/1ab8f6cf336c05ebfdce to your computer and use it in GitHub Desktop.
Save jechlin/1ab8f6cf336c05ebfdce to your computer and use it in GitHub Desktop.
package examples.docs
import com.atlassian.fugue.Pair
import com.atlassian.greenhopper.service.ServiceOutcome
import com.atlassian.greenhopper.service.rapid.RapidViewQueryService
import com.atlassian.greenhopper.service.rapid.view.RapidViewService
import com.atlassian.greenhopper.service.sprint.Sprint
import com.atlassian.greenhopper.service.sprint.SprintIssueService
import com.atlassian.greenhopper.service.sprint.SprintManager
import com.atlassian.greenhopper.service.sprint.SprintUtils
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.onresolve.scriptrunner.runner.customisers.JiraAgileBean
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
log.warn (" Post-function running **********************************************************************")
/**
Configurable section
*/
// Enter the name of the board to which you want to add the issue to the first active sprint
def rapidBoardId = 4
@WithPlugin("com.pyxis.greenhopper.jira")
@JiraAgileBean
RapidViewService rapidViewService
@JiraAgileBean
SprintIssueService sprintIssueService
@JiraAgileBean
SprintManager sprintManager
@JiraAgileBean
RapidViewQueryService rapidViewQueryService
Issue issue = issue // provided in binding
def loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getUser()
def view = rapidViewService.getRapidView(loggedInUser, rapidBoardId).getValue()
if (!view) {
log.warn("No view with this ID found")
log.warn (" Post-function finishing **********************************************************************")
return
}
def activeSprintsEnum = EnumSet.of(Sprint.State.ACTIVE)
def sprints = sprintManager.getSprintsForView(rapidBoardId as Long, activeSprintsEnum).getValue()
ServiceOutcome<Pair<List<Sprint>, Set<Long>>> sprintsAndBacklogProjects = rapidViewQueryService.getOpenSprintsAndBacklogProjects(loggedInUser, view)
List<Sprint> activeSprints = SprintUtils.getFilteredAndSortedSprints(activeSprintsEnum, sprintsAndBacklogProjects.getValue().left(), sprints)
if (activeSprints) {
def activeSprint = activeSprints.first()
log.warn ("Adding issue to sprint: " + activeSprint.id)
sprintIssueService.addIssuesToSprint(loggedInUser, activeSprint, [issue])
} else {
log.warn ("No active sprint found for board: " + rapidBoardId)
}
log.warn (" Post-function finishing **********************************************************************")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment