Skip to content

Instantly share code, notes, and snippets.

@jechlin
Created December 15, 2015 11:39
Show Gist options
  • Save jechlin/b76a603d142d4705fa6d to your computer and use it in GitHub Desktop.
Save jechlin/b76a603d142d4705fa6d to your computer and use it in GitHub Desktop.
package examples.docs
import com.atlassian.greenhopper.service.rapid.view.RapidViewService
import com.atlassian.greenhopper.service.sprint.SprintIssueService
import com.atlassian.greenhopper.service.sprint.SprintManager
import com.atlassian.greenhopper.service.sprint.SprintService
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
SprintService sprintService
@JiraAgileBean
SprintIssueService sprintIssueService
@JiraAgileBean
SprintManager sprintManager
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
}
return view
def sprints = sprintManager.getSprintsForView(view).getValue()
return sprints
def activeSprint = sprints.find { it.active }
if (activeSprint) {
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