2
1
0

JIRA課題のコメントで課題をウォッチしていないユーザーがメンションされた際、
JIRA Watcher Fieldプラグインを使って、できるだけそのユーザーをウォッチャーを追加するようにしているのですが、時々追加が漏れてしまって、そのユーザーにその後のやり取りが通知されないことがちょこちょこ起こっています。

コメント欄でメンションされたユーザーが自動的にウォッチャーに追加されるようなアドオンがあれば教えてください

    Commentコメントを追加...

    1 回答

    1.  
      3
      2
      1

      製品要望では以下ですかね。

      課題でのアドオンの紹介がなく、私自身「コメント欄でメンションされたユーザーが自動的にウォッチャーに追加されるようなアドオン」そのものの存在については知りませんが…marketplace.atlassian.com とか簡単に確認する限りなさそうですね。


      別の方法を考えてみると、以下QAの通り

      「@メンション」で自分が指定されたコメント・タスクを、JIRA上で素早く把握する方法は無いものでしょうか

      以下のようなJQLでコメントで自分自身がメンションされたものを検索できます。

      comment ~ currentUser()

      このJQLの検索結果の課題を自動Watchできればよいかと思うので…

      上記JQLの検索結果の課題を自動でWatch追加されるような仕組みを各自で設定してもらうとかですかね。

      JQLから自動でWatch追加する機能で検索すると以下のようなアドオンがあります。

      (警告) 必ず期待する動作するか評価してみてください。


      ちなみにそのものを実現しようとすると、既存アドオンがなければアドオンを作ることになるのですが…

      アドオンまでいかないとする ScriptRunner for Jira アドオンの Sciprt Listeners 機能ですかね。

      メンション自体は MentionEventListener  でイベント取得できたはずなので…

      Listeners の Mentionイベントで以下のようなスクリプトを動作するに設定すれば実現できるかもしれません。

      import com.atlassian.jira.component.ComponentAccessor;
      import com.atlassian.jira.notification.NotificationRecipient;
      import com.atlassian.jira.notification.NotificationSchemeManager;
      import com.atlassian.jira.event.type.EventType;
      import com.atlassian.jira.mention.MentionService;
      import com.atlassian.jira.mention.MentionFinder;
      import com.atlassian.jira.security.PermissionManager;
      import com.atlassian.jira.security.Permissions;
      import com.atlassian.jira.user.ApplicationUser;
      import com.atlassian.jira.user.util.UserManager;
      import com.atlassian.jira.issue.watchers.WatcherManager;
      import com.atlassian.jira.issue.Issue;
      import com.atlassian.jira.issue.comments.Comment;
      
      final Long eventTypeId = event.getEventTypeId();
      final ApplicationUser remoteUser = event.getUser();
      MentionService mentionService = ComponentAccessor.getComponent(MentionService.class);
      MentionFinder mentionFinder = ComponentAccessor.getComponent(MentionFinder.class);
      PermissionManager permissionManager = ComponentAccessor.getPermissionManager();
      UserManager userManager = ComponentAccessor.getUserManager();
      WatcherManager watcherManager = ComponentAccessor.getWatcherManager()
      
      
      if (eventTypeId.equals(EventType.ISSUE_COMMENTED_ID) || eventTypeId.equals(EventType.ISSUE_COMMENT_EDITED_ID)) {
         if (mentionService.isUserAbleToMention(remoteUser)) {
      		Comment comment = event.getComment();
      		if (comment == null) {
      			return;
      		}
      		Issue issue = comment.getIssue();
      		String mentionText = comment.getBody();
      
      		final Set<ApplicationUser> mentionedUsers = new LinkedHashSet<ApplicationUser>();
      		Iterable<String> allMentionedUsernames = mentionFinder.getMentionedUsernames(mentionText);
      		for (String username : allMentionedUsernames) {
      		final ApplicationUser user = userManager.getUser(username);
      			if (user != null && permissionManager.hasPermission(Permissions.BROWSE, issue, user)) {
      				mentionedUsers.add(user);
      			} 
      		}
      		for (ApplicationUser mentionedUser : mentionedUsers) {
      			if (watcherManager.isWatching(mentionedUser, issue) == false) {
      				watcherManager.startWatching(mentionedUser, issue)
      			}
      		}
      	}
      }

      (警告) 動作確認してないので、動かなかったらすみません。イメージです。


      1. 蒼龍

        アドオンでよさげなものは無いのですね・・・
        ありがとうございました!

      2. Kengo Ohsaki

        蒼龍-san,

        そうですね。そのものはありませんかね…

        ウオッチャーにこだわらないのであれば、通知スキームでグループピッカーカスタムフィールドを追加するとかもあるかとは思いますが今度は通知範囲が大きくなりすぎますよね。

        ちなみに Component Watcher for Jira といったコンポーネントに関連するWatcherを指定できるアドオンとかもあります。

        公開されているアドオンを組み合わせて工夫することは何かできそうですね。


      Commentコメントを追加...