-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EPMRPP-92666 || Impossible to Post issue with "Linked Issues" field (#56
- Loading branch information
1 parent
3a2bf17
commit 11bd62b
Showing
3 changed files
with
30 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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; | ||
|
@@ -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> | ||
|
@@ -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, | ||
|
@@ -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, | ||
|
@@ -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) { | ||
|
@@ -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(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters