Skip to content

Commit

Permalink
EPMRPP-92666 || Impossible to Post issue with "Linked Issues" field (#57
Browse files Browse the repository at this point in the history
)
  • Loading branch information
APiankouski authored Jul 23, 2024
1 parent 64f336c commit 70c78b2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.atlassian.jira.rest.client.api.domain.*;
import com.atlassian.jira.rest.client.api.domain.input.AttachmentInput;
import com.atlassian.jira.rest.client.api.domain.input.IssueInput;
import com.atlassian.jira.rest.client.api.domain.input.LinkIssuesInput;
import com.epam.reportportal.extension.ProjectMemberCommand;
import com.epam.reportportal.extension.jira.command.utils.CloudJiraClientProvider;
import com.epam.reportportal.extension.jira.command.utils.CloudJiraProperties;
Expand All @@ -43,6 +44,8 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.StreamSupport;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import static com.epam.reportportal.extension.util.CommandParamUtils.ENTITY_PARAM;
import static com.epam.ta.reportportal.commons.Predicates.*;
Expand All @@ -64,6 +67,8 @@ public class PostTicketCommand extends ProjectMemberCommand<Ticket> {

private final DataStoreService dataStoreService;

private static final String LINKED_ISSUE_TYPE = "Relates";

public PostTicketCommand(ProjectRepository projectRepository, RequestEntityConverter requestEntityConverter,
CloudJiraClientProvider cloudJiraClientProvider, JIRATicketDescriptionService descriptionService,
DataStoreService dataStoreService) {
Expand All @@ -86,13 +91,17 @@ protected Ticket invokeCommand(Integration integration, Map<String, Object> para
// ticket type and/or components in JIRA.
PostFormField issueType = new PostFormField();
PostFormField components = new PostFormField();
PostFormField linkedIssue = null;
for (PostFormField object : fields) {
if ("issuetype".equalsIgnoreCase(object.getId())) {
issueType = object;
}
if ("components".equalsIgnoreCase(object.getId())) {
components = object;
}
if ("issuelinks".equalsIgnoreCase(object.getId())) {
linkedIssue = object;
}
}

expect(issueType.getValue().size(), equalTo(1)).verify(UNABLE_INTERACT_WITH_INTEGRATION,
Expand Down Expand Up @@ -153,6 +162,9 @@ protected Ticket invokeCommand(Integration integration, Map<String, Object> para
if (counter != 0) {
client.getIssueClient().addAttachments(issue.getAttachmentsUri(), Arrays.copyOf(attachmentInputs, counter)).claim();
}
if (linkedIssue != null) {
linkIssues(client, issue, linkedIssue);
}
return getTicket(createdIssue.getKey(), integration.getParams(), client).orElse(null);

} catch (ReportPortalException e) {
Expand Down Expand Up @@ -209,4 +221,15 @@ private Optional<Ticket> getTicket(String id, IntegrationParams details, JiraRes
private SearchResult findIssue(String id, JiraRestClient jiraRestClient) {
return jiraRestClient.getSearchClient().searchJql("issue = " + id).claim();
}

private void linkIssues(JiraRestClient jiraRestClient, Issue issue, PostFormField field) {
String value = CollectionUtils.isNotEmpty(field.getValue()) ? field.getValue().get(0) : "";
if (StringUtils.isNotEmpty(value)) {
String[] s = value.split(" ");
for (String v : s) {
LinkIssuesInput linkIssuesInput = new LinkIssuesInput(issue.getKey(), v, LINKED_ISSUE_TYPE);
jiraRestClient.getIssueClient().linkIssue(linkIssuesInput).claim();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ public static IssueInput toIssueInput(JiraRestClient client, Project jiraProject
issueInputBuilder.setFixVersionsNames(one.getValue());
continue;
}
if (one.getId().equalsIgnoreCase(IssueFieldId.LINKS_FIELD.id)) {
continue;
}

// Arrays and fields with 'allowedValues' handler
if (null != cimFieldInfo.getAllowedValues()) {
Expand Down

0 comments on commit 70c78b2

Please sign in to comment.