Skip to content

Instantly share code, notes, and snippets.

Created May 1, 2012 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/2569617 to your computer and use it in GitHub Desktop.
Save anonymous/2569617 to your computer and use it in GitHub Desktop.
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 = "XXX";
def roleName = "Administrators";
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.subTaskObjects.any {it.summary == "YYYYYY"}) {
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)
}
}
}
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment