Skip to content

Commit

Permalink
Release 5.12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
APiankouski authored Sep 23, 2024
2 parents 9207a8b + 270a8fd commit 0b72877
Show file tree
Hide file tree
Showing 7 changed files with 841 additions and 773 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ on:

env:
GH_USER_NAME: github.actor
SCRIPTS_VERSION: 5.10.0
BOM_VERSION: 5.11.2
SCRIPTS_VERSION: 5.12.0
BOM_VERSION: 5.12.1
REPOSITORY_URL: 'https://maven.pkg.github.com/'

jobs:
Expand Down
13 changes: 8 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ repositories {

dependencyManagement {
imports {
mavenBom(releaseMode ? 'com.epam.reportportal:commons-bom:' + getProperty('bom.version') : 'com.epam.reportportal:commons-bom:5.11.2')
mavenBom(releaseMode ? 'com.epam.reportportal:commons-bom:' + getProperty('bom.version') : 'com.epam.reportportal:commons-bom:5.12.1')
}
}

Expand All @@ -39,18 +39,21 @@ targetCompatibility = JavaVersion.VERSION_11

dependencies {
if (releaseMode) {
implementation 'com.epam.reportportal:commons-dao'
implementation 'com.epam.reportportal:plugin-api'
annotationProcessor 'com.epam.reportportal:plugin-api'
} else {
implementation 'com.epam.reportportal:plugin-api'
annotationProcessor 'com.epam.reportportal:plugin-api'
implementation 'com.github.reportportal:commons-dao:acf1ec7'
implementation 'com.github.reportportal:plugin-api:188792e'
annotationProcessor 'com.github.reportportal:plugin-api:188792e'
}
implementation 'org.hibernate:hibernate-core:5.6.15.Final'

compile 'ch.qos.logback:logback-classic:1.2.3'
compile 'org.slf4j:slf4j-api:1.7.25'

compile 'io.atlassian.fugue:fugue:4.7.2'
compile('com.atlassian.jira:jira-rest-java-client-core:5.2.4')
compile 'com.atlassian.jira:jira-rest-java-client-core:5.2.4'

compile 'net.oauth.core:oauth:20090617'
compile 'net.oauth.core:oauth-httpclient4:20090913'
Expand Down Expand Up @@ -131,4 +134,4 @@ task assemblePlugin(type: Copy) {

task assemblePlugins(type: Copy) {
dependsOn subprojects.assemblePlugin
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version=5.11.1
version=5.12.0
description=EPAM Report portal. Jira Integration Plugin
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,21 @@

package com.epam.reportportal.extension.bugtracking.jira;

import static com.epam.ta.reportportal.commons.EntityUtils.INSTANT_TO_LDT;
import static java.util.Optional.ofNullable;

import com.epam.reportportal.model.externalsystem.PostTicketRQ;
import com.epam.reportportal.rules.exception.ErrorType;
import com.epam.reportportal.rules.exception.ReportPortalException;
import com.epam.ta.reportportal.dao.LogRepository;
import com.epam.ta.reportportal.dao.TestItemRepository;
import com.epam.ta.reportportal.entity.attachment.Attachment;
import com.epam.ta.reportportal.entity.item.TestItem;
import com.epam.ta.reportportal.entity.log.Log;
import com.epam.ta.reportportal.exception.ReportPortalException;
import com.epam.ta.reportportal.ws.model.ErrorType;
import com.epam.ta.reportportal.ws.model.externalsystem.PostTicketRQ;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Collections;
import java.util.List;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
Expand All @@ -39,144 +46,144 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.List;

import static com.epam.ta.reportportal.commons.EntityUtils.TO_DATE;
import static java.util.Optional.ofNullable;

/**
* Provide functionality for building jira's ticket description
*
* @author Aliaksei_Makayed
* @author Dzmitry_Kavalets
*/
public class JIRATicketDescriptionService {
public static final String JIRA_MARKUP_LINE_BREAK = "\\\\ ";
public static final String BACK_LINK_HEADER = "h3.*Back link to Report Portal:*";
public static final String BACK_LINK_PATTERN = "[Link to defect|%s]%n";
public static final String COMMENTS_HEADER = "h3.*Test Item comments:*";
public static final String CODE = "{code}";
private static final Logger LOGGER = LoggerFactory.getLogger(JIRATicketDescriptionService.class);
private static final String IMAGE_CONTENT = "image";
private static final String IMAGE_HEIGHT_TEMPLATE = "|height=366!";

private final LogRepository logRepository;
private final TestItemRepository itemRepository;
private final DateFormat dateFormat;
private final MimeTypes mimeRepository;

public JIRATicketDescriptionService(LogRepository logRepository, TestItemRepository itemRepository) {
this.dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
this.logRepository = logRepository;
this.itemRepository = itemRepository;
this.mimeRepository = TikaConfig.getDefaultConfig().getMimeRepository();
}

/**
* Generate ticket description using logs of specified test item.
*
* @param ticketRQ
* @return
*/
public String getDescription(PostTicketRQ ticketRQ) {
if (MapUtils.isEmpty(ticketRQ.getBackLinks())) {
return "";
}
StringBuilder descriptionBuilder = new StringBuilder();

TestItem item = itemRepository.findById(ticketRQ.getTestItemId())
.orElseThrow(() -> new ReportPortalException(ErrorType.TEST_ITEM_NOT_FOUND, ticketRQ.getTestItemId()));

ticketRQ.getBackLinks().keySet().forEach(backLinkId -> updateDescriptionBuilder(descriptionBuilder, ticketRQ, backLinkId, item));

return descriptionBuilder.toString();
}

private void updateDescriptionBuilder(StringBuilder descriptionBuilder, PostTicketRQ ticketRQ, Long backLinkId, TestItem item) {
if (StringUtils.isNotBlank(ticketRQ.getBackLinks().get(backLinkId))) {
descriptionBuilder.append(BACK_LINK_HEADER)
.append("\n")
.append(" - ")
.append(String.format(BACK_LINK_PATTERN, ticketRQ.getBackLinks().get(backLinkId)))
.append("\n");
}
// For single test-item only
// TODO add multiple test-items backlinks
if (ticketRQ.getIsIncludeComments()) {
if (StringUtils.isNotBlank(ticketRQ.getBackLinks().get(backLinkId))) {
// If test-item contains any comments, then add it for JIRA
// comments section
ofNullable(item.getItemResults()).flatMap(result -> ofNullable(result.getIssue())).ifPresent(issue -> {
if (StringUtils.isNotBlank(issue.getIssueDescription())) {
descriptionBuilder.append(COMMENTS_HEADER).append("\n").append(issue.getIssueDescription()).append("\n");
}
});
}
}
updateWithLogsInfo(descriptionBuilder, backLinkId, ticketRQ);
}

private StringBuilder updateWithLogsInfo(StringBuilder descriptionBuilder, Long backLinkId, PostTicketRQ ticketRQ) {
itemRepository.findById(backLinkId).ifPresent(item -> ofNullable(item.getLaunchId()).ifPresent(launchId -> {
List<Log> logs = logRepository.findAllUnderTestItemByLaunchIdAndTestItemIdsWithLimit(launchId,
Collections.singletonList(item.getItemId()),
ticketRQ.getNumberOfLogs()
);
if (CollectionUtils.isNotEmpty(logs) && (ticketRQ.getIsIncludeLogs() || ticketRQ.getIsIncludeScreenshots())) {
descriptionBuilder.append("h3.*Test execution log:*\n")
.append("{panel:title=Test execution log|borderStyle=solid|borderColor=#ccc|titleColor=#34302D|titleBGColor=#6DB33F}");
logs.forEach(log -> updateWithLog(descriptionBuilder,
log,
ticketRQ.getIsIncludeLogs(),
ticketRQ.getIsIncludeScreenshots()
));
descriptionBuilder.append("{panel}\n");
}
}));
return descriptionBuilder;
}

private void updateWithLog(StringBuilder descriptionBuilder, Log log, boolean includeLog, boolean includeScreenshot) {
if (includeLog) {
descriptionBuilder.append(CODE).append(getFormattedMessage(log)).append(CODE);
}

if (includeScreenshot) {
ofNullable(log.getAttachment()).ifPresent(attachment -> addAttachment(descriptionBuilder, attachment));
}
}

private String getFormattedMessage(Log log) {
StringBuilder messageBuilder = new StringBuilder();
ofNullable(log.getLogTime()).ifPresent(logTime -> messageBuilder.append(" Time: ")
.append(dateFormat.format(TO_DATE.apply(logTime)))
.append(", "));
ofNullable(log.getLogLevel()).ifPresent(logLevel -> messageBuilder.append("Level: ").append(logLevel).append(", "));
messageBuilder.append("Log: ").append(log.getLogMessage()).append("\n");
return messageBuilder.toString();
}

private void addAttachment(StringBuilder descriptionBuilder, Attachment attachment) {
if (StringUtils.isNotBlank(attachment.getContentType()) && StringUtils.isNotBlank(attachment.getFileId())) {
try {
MimeType mimeType = mimeRepository.forName(attachment.getContentType());
if (attachment.getContentType().contains(IMAGE_CONTENT)) {
descriptionBuilder.append("!")
.append(attachment.getFileId())
.append(mimeType.getExtension())
.append(IMAGE_HEIGHT_TEMPLATE);
} else {
descriptionBuilder.append("[^").append(attachment.getFileId()).append(mimeType.getExtension()).append("]");
}
descriptionBuilder.append(JIRA_MARKUP_LINE_BREAK);
} catch (MimeTypeException e) {
descriptionBuilder.append(JIRA_MARKUP_LINE_BREAK);
LOGGER.error("JIRATicketDescriptionService error: " + e.getMessage(), e);
}

}
}
}
public static final String JIRA_MARKUP_LINE_BREAK = "\\\\ ";
public static final String BACK_LINK_HEADER = "h3.*Back link to Report Portal:*";
public static final String BACK_LINK_PATTERN = "[Link to defect|%s]%n";
public static final String COMMENTS_HEADER = "h3.*Test Item comments:*";
public static final String CODE = "{code}";
private static final Logger LOGGER = LoggerFactory.getLogger(JIRATicketDescriptionService.class);
private static final String IMAGE_CONTENT = "image";
private static final String IMAGE_HEIGHT_TEMPLATE = "|height=366!";

private final LogRepository logRepository;
private final TestItemRepository itemRepository;
private static final DateTimeFormatter JIRA_DATETIME_FORMATTER =
DateTimeFormatter.ofPattern("MM/dd/yyyy HH:mm:ss").withZone(ZoneId.of("UTC"));
private final MimeTypes mimeRepository;

public JIRATicketDescriptionService(LogRepository logRepository,
TestItemRepository itemRepository) {
this.logRepository = logRepository;
this.itemRepository = itemRepository;
this.mimeRepository = TikaConfig.getDefaultConfig().getMimeRepository();
}

/**
* Generate ticket description using logs of specified test item.
*
* @param ticketRQ
* @return
*/
public String getDescription(PostTicketRQ ticketRQ) {
if (MapUtils.isEmpty(ticketRQ.getBackLinks())) {
return "";
}
StringBuilder descriptionBuilder = new StringBuilder();

TestItem item = itemRepository.findById(ticketRQ.getTestItemId()).orElseThrow(
() -> new ReportPortalException(ErrorType.TEST_ITEM_NOT_FOUND, ticketRQ.getTestItemId()));

ticketRQ.getBackLinks().keySet().forEach(
backLinkId -> updateDescriptionBuilder(descriptionBuilder, ticketRQ, backLinkId, item));

return descriptionBuilder.toString();
}

private void updateDescriptionBuilder(StringBuilder descriptionBuilder, PostTicketRQ ticketRQ,
Long backLinkId, TestItem item) {
if (StringUtils.isNotBlank(ticketRQ.getBackLinks().get(backLinkId))) {
descriptionBuilder.append(BACK_LINK_HEADER).append("\n").append(" - ")
.append(String.format(BACK_LINK_PATTERN, ticketRQ.getBackLinks().get(backLinkId)))
.append("\n");
}
// For single test-item only
// TODO add multiple test-items backlinks
if (ticketRQ.getIsIncludeComments()) {
if (StringUtils.isNotBlank(ticketRQ.getBackLinks().get(backLinkId))) {
// If test-item contains any comments, then add it for JIRA
// comments section
ofNullable(item.getItemResults()).flatMap(result -> ofNullable(result.getIssue()))
.ifPresent(issue -> {
if (StringUtils.isNotBlank(issue.getIssueDescription())) {
descriptionBuilder.append(COMMENTS_HEADER).append("\n")
.append(issue.getIssueDescription()).append("\n");
}
});
}
}
updateWithLogsInfo(descriptionBuilder, backLinkId, ticketRQ);
}

private StringBuilder updateWithLogsInfo(StringBuilder descriptionBuilder, Long backLinkId,
PostTicketRQ ticketRQ) {
itemRepository.findById(backLinkId)
.ifPresent(item -> ofNullable(item.getLaunchId()).ifPresent(launchId -> {
List<Log> logs =
logRepository.findAllUnderTestItemByLaunchIdAndTestItemIdsWithLimit(launchId,
Collections.singletonList(item.getItemId()), ticketRQ.getNumberOfLogs()
);
if (CollectionUtils.isNotEmpty(logs) && (ticketRQ.getIsIncludeLogs()
|| ticketRQ.getIsIncludeScreenshots())) {
descriptionBuilder.append("h3.*Test execution log:*\n").append(
"{panel:title=Test execution log|borderStyle=solid|borderColor=#ccc|titleColor=#34302D|titleBGColor=#6DB33F}");
logs.forEach(log -> updateWithLog(descriptionBuilder, log, ticketRQ.getIsIncludeLogs(),
ticketRQ.getIsIncludeScreenshots()
));
descriptionBuilder.append("{panel}\n");
}
}));
return descriptionBuilder;
}

private void updateWithLog(StringBuilder descriptionBuilder, Log log, boolean includeLog,
boolean includeScreenshot) {
if (includeLog) {
descriptionBuilder.append(CODE).append(getFormattedMessage(log)).append(CODE);
}

if (includeScreenshot) {
ofNullable(log.getAttachment()).ifPresent(
attachment -> addAttachment(descriptionBuilder, attachment));
}
}

private String getFormattedMessage(Log log) {
StringBuilder messageBuilder = new StringBuilder();
ofNullable(log.getLogTime())
.ifPresent(logTime -> messageBuilder.append(" Time: ")
.append(INSTANT_TO_LDT.apply(logTime).format(JIRA_DATETIME_FORMATTER))
.append(", "));
ofNullable(log.getLogLevel()).ifPresent(
logLevel -> messageBuilder.append("Level: ").append(logLevel).append(", "));
messageBuilder.append("Log: ").append(log.getLogMessage()).append("\n");
return messageBuilder.toString();
}

private void addAttachment(StringBuilder descriptionBuilder, Attachment attachment) {
if (StringUtils.isNotBlank(attachment.getContentType()) && StringUtils.isNotBlank(
attachment.getFileId())) {
try {
MimeType mimeType = mimeRepository.forName(attachment.getContentType());
if (attachment.getContentType().contains(IMAGE_CONTENT)) {
descriptionBuilder.append("!").append(attachment.getFileId())
.append(mimeType.getExtension()).append(IMAGE_HEIGHT_TEMPLATE);
} else {
descriptionBuilder.append("[^").append(attachment.getFileId())
.append(mimeType.getExtension()).append("]");
}
descriptionBuilder.append(JIRA_MARKUP_LINE_BREAK);
} catch (MimeTypeException e) {
descriptionBuilder.append(JIRA_MARKUP_LINE_BREAK);
LOGGER.error("JIRATicketDescriptionService error: " + e.getMessage(), e);
}

}
}
}
Loading

0 comments on commit 0b72877

Please sign in to comment.