VolodymyrH
VolodymyrH

Reputation: 2019

How to copy comments between linked Jira issues?

I need to make Jira copy comments from parent issue to linked ones. To do it I'm trying to write custom listener. But I can't figure out how to find these linked issues. I also added events type to "Issue Commented".

My listener:

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

        }
    }

So the question is how can I find these linked issues within the project?

Upvotes: 1

Views: 1138

Answers (1)

barmi
barmi

Reputation: 665

One of the ways is to get names of links and then create jql query.

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

then use all links, choose a few of them or just one and put it in jql (source issue key is needed there):

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

and finally get List of linked `Issues":

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

1000 is the maximum number of returned issues (you are able to change it).

If you want issues from specific project add to jql and project = <your_project_key>

Upvotes: 1

Related Questions