如何在链接的 Jira 问题之间复制评论?

How to copy comments between linked Jira issues?

我需要让 Jira 将父问题的评论复制到链接的问题。为此,我正在尝试编写自定义侦听器。但我无法弄清楚如何找到这些相关的问题。我还将事件类型添加到 "Issue Commented".

我的听众:

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.event.issue.AbstractIssueEventListener;
import com.atlassian.jira.event.issue.IssueEvent;

import com.atlassian.jira.issue.link.IssueLinkType;
import com.atlassian.jira.bc.issue.link.IssueLinkService;

public class CopyComments extends AbstractIssueEventListener {

        @Override
        void workflowEvent(IssueEvent event) {

            def commentManager = ComponentAccessor.getCommentManager();
            def issueManager = ComponentAccessor.getIssueManager();
            def comment = event.getComment();

            ArrayList<String> linkedIssues = getLinkedEvents(event); 

            for (def i = 0; i < linkedIssues.size(); i++) {
                def targetIssue = issueManager.getIssueObject(linkedIssues[i]);
                commentManager.create(targetIssue, comment.authorApplicationUser, comment.body, true);

            }
        }

        ArrayList<String> getLinkedEvents(IssueEvent event) {

        }
    }

所以问题是我如何在项目中找到这些关联的问题?

其中一种方法是获取链接名称,然后创建 jql 查询。

Collection<IssueLinkType> links = issueLinkService.getIssueLinkTypes();
List<String> linksNames= links.stream().map(IssueLinkType::getName).collect(Collectors.toList());

然后使用所有链接,选择其中几个或只选择一个并将其放入 jql(那里需要源问题密钥):

String jql = "issue in linkedIssues('" + <source_Issue_Key> + "'," + <link_name_from_linksNames> + ")";

并最终获得 List 个链接的“问题”:

Query query = jqlQueryParser.parseQuery(jql);
List<Issue> linkedIssues = searchProvider.search(query, jiraAuthenticationContext.getLoggedInUser(), PagerFilter.newPageAlignedFilter(0, 1000)).getIssues();

1000 是返回问题的最大数量(您可以更改它)。

如果你想 issues 从特定项目添加到 jql and project = <your_project_key>