Created
May 2, 2012 11:13
-
-
Save jechlin/2575893 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.atlassian.crowd.embedded.api.User | |
import com.atlassian.jira.ComponentManager | |
import com.atlassian.jira.issue.Issue | |
import com.atlassian.jira.issue.search.SearchRequest | |
import com.atlassian.jira.jql.builder.JqlQueryBuilder | |
import com.atlassian.jira.project.Project | |
import com.atlassian.jira.security.roles.ProjectRoleManager | |
import com.atlassian.jira.web.bean.PagerFilter | |
import com.atlassian.query.Query | |
def projectKey = "JRA" | |
def roleName = "Developers" | |
def jqlQueryBuilder = JqlQueryBuilder.newBuilder() | |
def componentManager = ComponentManager.getInstance() | |
def searchProvider = componentManager.getSearchProvider() | |
def watcherManager = componentManager.getWatcherManager() | |
def issueManager = componentManager.getIssueManager() | |
ProjectRoleManager projectRoleManager = (ProjectRoleManager) componentManager.getComponentInstanceOfType(ProjectRoleManager.class); | |
Project project = componentManager.getProjectManager().getProjectObjByKey(projectKey) | |
def anyOldAdminUser = componentManager.getUserUtil().getJiraAdministrators().toList().first() as User | |
def role = projectRoleManager.getProjectRole(roleName) | |
Query query = jqlQueryBuilder.where().project(projectKey).and().issueTypeIsStandard().and().status().notEq("Closed").buildQuery() | |
def sr = new SearchRequest(query) | |
def roleMembers = projectRoleManager.getProjectRoleActors(role, project).getRoleActors()*.getUsers().flatten() | |
def results = searchProvider.search(sr.getQuery(), anyOldAdminUser, PagerFilter.getUnlimitedFilter()) | |
results.issues.each {Issue docIssue -> | |
def issue = issueManager.getIssueObject(docIssue.id) | |
log.debug("Looking at issue: ${issue.key}") | |
if (issue) { | |
if (issue.subTaskObjects.any {it.summary == "HelpTylerHesNotSmart"}) { // todo: update this | |
roleMembers.each {user -> | |
log.debug("Add user ${user.name} to ${issue.key}") | |
watcherManager.startWatching(user, issue.genericValue) | |
} | |
} | |
else { | |
roleMembers.each {user -> | |
if (watcherManager.isWatching(user as User, issue.genericValue)) { | |
log.debug("Remove user ${user.name} from ${issue.key}") | |
watcherManager.stopWatching(user, issue.genericValue) | |
} | |
} | |
} | |
} | |
else { | |
log.warn ("No issue found for indexed issue ${docIssue}") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Jamie,
Could this script be easily modified to just add watchers in a specific (or same) security group on Jira ticket creation? I have been dying for this and would gladly spike the charts on Karma for a working solution.