Skip to content

Commit

Permalink
EPMRPP-92666 || Impossible to Post issue with "Linked Issues" field (#56
Browse files Browse the repository at this point in the history
)
  • Loading branch information
APiankouski authored Jul 19, 2024
1 parent 3a2bf17 commit 11bd62b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ dependencies {
implementation 'com.epam.reportportal:plugin-api'
annotationProcessor 'com.epam.reportportal:plugin-api'
} else {
implementation 'com.github.reportportal:commons-dao:0703b75'
implementation 'com.github.reportportal:plugin-api:3ecb915657'
annotationProcessor 'com.github.reportportal:plugin-api:3ecb915657'
implementation 'com.github.reportportal:commons-dao:823f284'
implementation 'com.github.reportportal:plugin-api:a23eec0'
annotationProcessor 'com.github.reportportal:plugin-api:a23eec0'
}
implementation 'org.hibernate:hibernate-core:5.6.15.Final'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.atlassian.jira.rest.client.api.domain.SearchResult;
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 @@ -46,12 +47,12 @@
import com.epam.reportportal.model.externalsystem.PostFormField;
import com.epam.reportportal.model.externalsystem.PostTicketRQ;
import com.epam.reportportal.model.externalsystem.Ticket;
import com.epam.reportportal.rules.exception.ReportPortalException;
import com.epam.ta.reportportal.binary.DataStoreService;
import com.epam.ta.reportportal.commons.Preconditions;
import com.epam.ta.reportportal.dao.ProjectRepository;
import com.epam.ta.reportportal.entity.integration.Integration;
import com.epam.ta.reportportal.entity.integration.IntegrationParams;
import com.epam.reportportal.rules.exception.ReportPortalException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.HashMap;
Expand All @@ -62,6 +63,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.StreamSupport;
import org.apache.commons.lang3.StringUtils;

/**
* @author <a href="mailto:[email protected]">Pavel Bortnik</a>
Expand All @@ -76,6 +78,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,
Expand All @@ -101,13 +105,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 @@ -174,6 +182,10 @@ protected Ticket invokeCommand(Integration integration, Map<String, Object> para
.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 @@ -232,4 +244,15 @@ private Optional<Ticket> getTicket(String id, IntegrationParams details,
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 = 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 @@ -151,6 +151,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 11bd62b

Please sign in to comment.