Autowatch on Time Logged

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

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)

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

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

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

0 vote

Without custom code, it is not possible.

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

lol........

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,238 views 14 19
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot