Autowatch on Time Logged

Tanner Wortham
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 13, 2013

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?

3 answers

1 accepted

2 votes
Answer accepted
Tanner Wortham
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 14, 2013

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 ----------------")
    }
}

Jamie Echlin March 14, 2013

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)

Tanner Wortham
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 14, 2013

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.)

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 14, 2013

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...

1 vote
Ivan Tse
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 14, 2013

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.

Tanner Wortham
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 14, 2013

thanks, ivan. i voted up the issue, and i'm going to add a few of my thoughts.

0 votes
Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 13, 2013

Without custom code, it is not possible.

Tanner Wortham
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 14, 2013

how many times do i have to tell you to stop giving me bad news, jobin? ;)

Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 14, 2013

lol........

Suggest an answer

Log in or Sign up to answer