Skip to content

Instantly share code, notes, and snippets.

@jechlin
Last active March 28, 2020 00:43
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save jechlin/9789183 to your computer and use it in GitHub Desktop.
Save jechlin/9789183 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.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.onresolve.scriptrunner.runner.customisers.JiraAgileBean
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
/**
* Configurable section
*/
// Enter the name of the board to which you want to add the issue to the first active sprint
def rapidBoardId = 2L
@WithPlugin("com.pyxis.greenhopper.jira")
@JiraAgileBean
RapidViewService rapidViewService
@JiraAgileBean
SprintIssueService sprintIssueService
@JiraAgileBean
SprintManager sprintManager
Issue issue = issue // provided in binding
def loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def view = rapidViewService.getRapidView(loggedInUser, rapidBoardId).getValue()
if (! view) {
log.warn("No view with this ID found")
return
}
def sprints = sprintManager.getSprintsForView(view).getValue()
def activeSprint = sprints.find { it.active }
log.debug activeSprint
if (activeSprint) {
log.info "Adding issue $issue to ${activeSprint.name}"
sprintIssueService.moveIssuesToSprint(loggedInUser, activeSprint, [issue] as Collection)
}
else {
log.info ("No active sprints were found for board: ${view.name}")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment