I was never a fan of the autowatch on comments. It's a good idea, but creates a bit too much noise for our users. But what I would like is something very similar in that anyone who logs time to an issue is auto-added as a watcher. Without writing custom code, does anyone know a solution?
I crafted this today that adds anyone logging time to the watch list.
package com.custom import com.atlassian.jira.event.issue.AbstractIssueEventListener import com.atlassian.jira.event.issue.IssueEvent import org.apache.log4j.Category import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.watchers.WatcherManager import com.atlassian.jira.security.JiraAuthenticationContext class WorkLoggedListener extends AbstractIssueEventListener { Category log = Category.getInstance(WorkLoggedListener.class) @Override void issueWorkLogged (IssueEvent event) { log.setLevel(org.apache.log4j.Level.WARN) log.debug ("----------- begin WorkLoggedListener --------------") ComponentManager componentManager = ComponentManager.getInstance() WatcherManager watcherManager = componentManager.getWatcherManager() JiraAuthenticationContext jiraAuthenticationContext = componentManager.getJiraAuthenticationContext() watcherManager.startWatching(jiraAuthenticationContext.getLoggedInUser(), event.issue) log.debug ("----------- end WorkLoggedListener ----------------") } }
Upvoted, but I think you are over-complicating this. You can get a WatcherService via:
ComponentAccessor.getComponent(WatcherService.class)
Then you don't need to create one yourself along with all its dependencies. Furthermore I think I would just use
watcherManager.startWatching(watcher, issue)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
watcherManager.startWatching was a *much* cleaner way of doing this so I edited the code above to reflect my changes. Thanks for the tip, Jamie.
(i didn't use ComponentAccessor as you suggested above though. Instead, I stuck with ComponentManager.)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No worries. CA and CM do the same thing under the covers, but CA is @PublicApi, CM is not. One day... probably a very long time in the future, CM might be removed...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That is odd. I would have assumed that the auto watch would have captured that action and added the user who logged time against the ticket to have been added as a watcher. I've made an improvement request for now to review consistency for what actions automatically add a watcher.
https://jira.atlassian.com/browse/JRA-32119
If logging time againast a ticket is one of the actions which adds a user as a watcher then your want to add users once they logged work will fall under the default auto-watch feature.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
thanks, ivan. i voted up the issue, and i'm going to add a few of my thoughts.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Without custom code, it is not possible.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
how many times do i have to tell you to stop giving me bad news, jobin? ;)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
lol........
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.