Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
id "com.github.node-gradle.node" version "7.1.0"
id 'com.gradleup.shadow' version '9.3.1'
id "org.jooq.jooq-codegen-gradle" version "3.19.18"
id("io.freefair.lombok") version "9.5.0"
}

apply from: 'project-properties.gradle'
Expand Down Expand Up @@ -31,15 +32,10 @@ dependencies {
implementation 'com.epam.reportportal:service-api'
annotationProcessor 'com.epam.reportportal:service-api'
} else {
implementation 'com.github.reportportal:service-api:e81b4f6'
annotationProcessor 'com.github.reportportal:service-api:e81b4f6'
implementation 'com.github.reportportal:service-api:82fa7c7'
annotationProcessor 'com.github.reportportal:service-api:82fa7c7'
}

// add lombok support
compileOnly "org.projectlombok:lombok:${lombokVersion}"
annotationProcessor "org.projectlombok:lombok:${lombokVersion}"
testCompileOnly "org.projectlombok:lombok:${lombokVersion}"
testAnnotationProcessor "org.projectlombok:lombok:${lombokVersion}"
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}

Expand Down
1 change: 0 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ description=EPAM Report Portal. GitLab plugin.
pluginId = GitLab

springBootVersion=3.5.9
lombokVersion=1.18.42
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.epam.reportportal.extension.NamedPluginCommand;
import com.epam.reportportal.extension.PluginCommand;
import com.epam.reportportal.extension.ReportPortalExtensionPoint;
import com.epam.reportportal.extension.command.ExtensionCommand;
import com.epam.reportportal.extension.common.IntegrationTypeProperties;
import com.epam.reportportal.base.core.events.domain.PluginUploadedEvent;
import com.epam.reportportal.extension.gitlab.client.GitlabClientProvider;
Expand Down Expand Up @@ -77,16 +78,16 @@ public class GitlabExtension implements ReportPortalExtensionPoint, DisposableBe
@Autowired
private OrganizationRepositoryCustom organizationRepository;

private final Supplier<Map<String, PluginCommand<?>>> pluginCommandMapping = new MemoizingSupplier<>(
this::getCommands);
private final Supplier<Map<String, ExtensionCommand<?>>> pluginCommandMapping = new MemoizingSupplier<>(
this::getIntegrationExtensionCommands);
private final Supplier<Map<String, ExtensionCommand<?>>> commonCommandMapping = new MemoizingSupplier<>(
this::getCommonExtensionCommands);
@Autowired
private LogRepository logRepository;
@Autowired
private TestItemRepository testItemRepository;
@Autowired
private BasicTextEncryptor textEncryptor;
private final Supplier<Map<String, CommonPluginCommand<?>>> commonPluginCommandMapping = new MemoizingSupplier<>(
this::getCommonCommands);
@Autowired
@Qualifier("attachmentDataStoreService")
private DataStoreService dataStoreService;
Expand All @@ -113,18 +114,18 @@ public GitlabExtension(Map<String, Object> initParams) {
Map<String, Object> params = new HashMap<>();
params.put(ALLOWED_COMMANDS, new ArrayList<>(pluginCommandMapping.get().keySet()));
params.put(DOCUMENTATION_LINK_FIELD, DOCUMENTATION_LINK);
params.put(COMMON_COMMANDS, new ArrayList<>(commonPluginCommandMapping.get().keySet()));
params.put(COMMON_COMMANDS, new ArrayList<>(commonCommandMapping.get().keySet()));
return params;
}

@Override
public PluginCommand<?> getIntegrationCommand(String commandName) {
return pluginCommandMapping.get().get(commandName);
return null;
}

@Override
public CommonPluginCommand<?> getCommonCommand(String commandName) {
return commonPluginCommandMapping.get().get(commandName);
return null;
}

@Override
Expand Down Expand Up @@ -158,22 +159,24 @@ private void removeListeners() {
applicationEventMulticaster.removeApplicationListener(pluginLoadedListenerSupplier.get());
}

private Map<String, CommonPluginCommand<?>> getCommonCommands() {
List<CommonPluginCommand<?>> commands = new ArrayList<>();
commands.add(new RetrieveCreationParamsCommand(textEncryptor));
commands.add(new RetrieveUpdateParamsCommand(textEncryptor));
commands.add(new GetIssueCommand(gitlabClientProviderSupplier.get(), integrationRepository));
@Override
public Map<String, ExtensionCommand<?>> getCommonExtensionCommands() {
List<ExtensionCommand<?>> commands = new ArrayList<>();
commands.add(new RetrieveCreationParamsCommand(textEncryptor, projectRepository, organizationRepository));
commands.add(new RetrieveUpdateParamsCommand(textEncryptor, projectRepository, organizationRepository));
commands.add(new GetIssueCommand(gitlabClientProviderSupplier.get(), integrationRepository, projectRepository, organizationRepository));
return commands.stream().collect(Collectors.toMap(NamedPluginCommand::getName, it -> it));
}

private Map<String, PluginCommand<?>> getCommands() {
List<PluginCommand<?>> commands = new ArrayList<>();
commands.add(new TestConnectionCommand(gitlabClientProviderSupplier.get()));
commands.add(new GetIssuesCommand(gitlabClientProviderSupplier.get()));
commands.add(new SearchUsersCommand(gitlabClientProviderSupplier.get()));
commands.add(new SearchMilestonesCommand(gitlabClientProviderSupplier.get()));
commands.add(new SearchEpicsCommand(gitlabClientProviderSupplier.get()));
commands.add(new SearchLabelsCommand(gitlabClientProviderSupplier.get()));
@Override
public Map<String, ExtensionCommand<?>> getIntegrationExtensionCommands() {
List<ExtensionCommand<?>> commands = new ArrayList<>();
commands.add(new TestConnectionCommand(gitlabClientProviderSupplier.get(), projectRepository, organizationRepository));
commands.add(new GetIssuesCommand(gitlabClientProviderSupplier.get(), projectRepository, organizationRepository));
commands.add(new SearchUsersCommand(gitlabClientProviderSupplier.get(), projectRepository, organizationRepository));
commands.add(new SearchMilestonesCommand(gitlabClientProviderSupplier.get(), projectRepository, organizationRepository));
commands.add(new SearchEpicsCommand(gitlabClientProviderSupplier.get(), projectRepository, organizationRepository));
commands.add(new SearchLabelsCommand(gitlabClientProviderSupplier.get(), projectRepository, organizationRepository));
commands.add(new GetIssueTypesCommand(projectRepository, organizationRepository));
commands.add(new GetIssueFieldsCommand(projectRepository, organizationRepository));
commands.add(new PostTicketCommand(projectRepository, gitlabClientProviderSupplier.get(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
import java.util.Map;
import java.util.Objects;
import org.jooq.tools.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.ContentDisposition;
import org.springframework.http.HttpEntity;
Expand All @@ -42,10 +41,9 @@
/**
* @author Zsolt Nagyaghy
*/
@Slf4j
public class GitlabClient {

private static final Logger logger = LoggerFactory.getLogger(GitlabClient.class);

private static final Integer DEFAULT_PAGE_SIZE = 100;
private static final Integer FIRST_PAGE = 1;
private static final String QUERY_PAGE = "page";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,21 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.tika.config.TikaConfig;
import org.apache.tika.mime.MimeTypes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;

/**
* Provide functionality for building ticket description
*
* @author Aliaksei_Makayed
* @author Dzmitry_Kavalets
*/
@Slf4j
public class DescriptionBuilderService {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,44 @@

package com.epam.reportportal.extension.gitlab.command;

import static java.util.Optional.ofNullable;

import com.epam.reportportal.extension.CommonPluginCommand;
import com.epam.reportportal.extension.gitlab.client.GitlabClientProvider;
import com.epam.reportportal.extension.gitlab.utils.TicketMapper;
import com.epam.reportportal.api.model.PluginCommandRQ;
import com.epam.reportportal.base.infrastructure.model.externalsystem.Ticket;
import com.epam.reportportal.base.infrastructure.persistence.dao.IntegrationRepository;
import com.epam.reportportal.base.infrastructure.persistence.dao.ProjectRepository;
import com.epam.reportportal.base.infrastructure.persistence.dao.organization.OrganizationRepositoryCustom;
import com.epam.reportportal.base.infrastructure.persistence.entity.integration.Integration;
import com.epam.reportportal.base.infrastructure.rules.exception.ErrorType;
import com.epam.reportportal.base.infrastructure.rules.exception.ReportPortalException;
import java.util.Map;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.epam.reportportal.extension.command.AbstractExtensionCommand;
import com.epam.reportportal.extension.gitlab.client.GitlabClientProvider;
import com.epam.reportportal.extension.gitlab.utils.TicketMapper;
import lombok.extern.slf4j.Slf4j;

/**
* @author <a href="mailto:andrei_piankouski@epam.com">Andrei Piankouski</a>
*/
public class GetIssueCommand implements CommonPluginCommand<Ticket> {

private static final Logger LOGGER = LoggerFactory.getLogger(GetIssueCommand.class);

@Slf4j
public class GetIssueCommand extends AbstractExtensionCommand<Ticket> {

private static final String PROJECT_ID = "projectId";

private final GitlabClientProvider gitlabClientProvider;

private final IntegrationRepository integrationRepository;

public GetIssueCommand(GitlabClientProvider gitlabClientProvider,
IntegrationRepository integrationRepository) {
IntegrationRepository integrationRepository, ProjectRepository projectRepository,
OrganizationRepositoryCustom organizationRepository) {
super(projectRepository, organizationRepository);
this.gitlabClientProvider = gitlabClientProvider;
this.integrationRepository = integrationRepository;
}

@Override
public Ticket executeCommand(Map<String, Object> params) {
final Long projectId = (Long) Optional.ofNullable(params.get(PROJECT_ID)).orElseThrow(
public Ticket executeCommand(PluginCommandRQ pluginCommandRq) {
var params = pluginCommandRq.getArguments();
final Long projectId = (Long) ofNullable(params.get(PROJECT_ID)).orElseThrow(
() -> new ReportPortalException(ErrorType.BAD_REQUEST_ERROR,
PROJECT_ID + " must be provided"
));
Expand Down Expand Up @@ -80,7 +81,7 @@ public Ticket executeCommand(Map<String, Object> params) {
return TicketMapper.toTicket(
gitlabClientProvider.get(integration.getParams()).getIssue(issueId, btsProject));
} catch (Exception e) {
LOGGER.error("Issue not found: {}", e.getMessage(), e);
log.error("Issue not found: {}", e.getMessage(), e);
throw new ReportPortalException(ErrorType.UNABLE_INTERACT_WITH_INTEGRATION,
"Failed to retrieve the Gitlab ticket");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,23 @@
import static com.epam.reportportal.extension.gitlab.command.PredefinedFieldTypes.CREATABLE_MULTI_AUTOCOMPLETE;
import static com.epam.reportportal.extension.gitlab.command.PredefinedFieldTypes.MULTI_AUTOCOMPLETE;

import com.epam.reportportal.extension.ProjectMemberCommand;
import com.epam.reportportal.api.model.PluginCommandRQ;
import com.epam.reportportal.base.infrastructure.model.externalsystem.AllowedValue;
import com.epam.reportportal.base.infrastructure.model.externalsystem.PostFormField;
import com.epam.reportportal.base.infrastructure.persistence.dao.ProjectRepository;
import com.epam.reportportal.base.infrastructure.persistence.dao.organization.OrganizationRepositoryCustom;
import com.epam.reportportal.base.infrastructure.persistence.entity.integration.Integration;
import com.epam.reportportal.base.infrastructure.rules.exception.ErrorType;
import com.epam.reportportal.base.infrastructure.rules.exception.ReportPortalException;
import com.epam.reportportal.extension.command.AbstractExtensionCommand;
import com.google.common.collect.Lists;
import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
* @author <a href="mailto:pavel_bortnik@epam.com">Pavel Bortnik</a>
*/
public class GetIssueFieldsCommand extends ProjectMemberCommand<List<PostFormField>> {
public class GetIssueFieldsCommand extends AbstractExtensionCommand<List<PostFormField>> {

public static final String ISSUE_TYPE = "issue_type";
public static final String ISSUE_TYPE_PARAM = "issueType";
Expand All @@ -53,14 +53,17 @@ public GetIssueFieldsCommand(ProjectRepository projectRepository,
}

@Override
protected List<PostFormField> invokeCommand(Integration integration, Map<String, Object> params) {
String issueTypeParam = Optional.ofNullable(params.get(ISSUE_TYPE_PARAM)).map(it -> (String) it)
protected List<PostFormField> invokeCommand(Integration integration,
PluginCommandRQ pluginCommandRq) {
String issueTypeParam = Optional.ofNullable(pluginCommandRq.getArguments().get(ISSUE_TYPE_PARAM))
.map(it -> (String) it)
.orElseThrow(() -> new ReportPortalException(ErrorType.BAD_REQUEST_ERROR,
"Issue type is not provided"
));
List<PostFormField> result = Lists.newArrayList(
PostFormField.builder().id("title").fieldName("Title").fieldType("string").isRequired(true)
.build(), PostFormField.builder().id("description").fieldName("Description")
.build(),
PostFormField.builder().id("description").fieldName("Description")
.fieldType("multilineText").build(),
PostFormField.builder().id(ISSUE_TYPE).fieldName("Issue type").fieldType("issuetype")
.isRequired(true).definedValues(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.epam.reportportal.extension.gitlab.command;

import com.epam.reportportal.extension.ProjectMemberCommand;
import com.epam.reportportal.api.model.PluginCommandRQ;
import com.epam.reportportal.base.infrastructure.persistence.dao.ProjectRepository;
import com.epam.reportportal.base.infrastructure.persistence.dao.organization.OrganizationRepositoryCustom;
import com.epam.reportportal.base.infrastructure.persistence.entity.integration.Integration;
import com.epam.reportportal.extension.command.AbstractExtensionCommand;
import java.util.List;
import java.util.Map;

/**
* @author <a href="mailto:pavel_bortnik@epam.com">Pavel Bortnik</a>
*/
public class GetIssueTypesCommand extends ProjectMemberCommand<List<String>> {
public class GetIssueTypesCommand extends AbstractExtensionCommand<List<String>> {

public static final String ISSUE = "Issue";
public static final String INCIDENT = "Incident";
Expand All @@ -41,7 +42,7 @@ public String getName() {
}

@Override
protected List<String> invokeCommand(Integration integration, Map<String, Object> params) {
protected List<String> invokeCommand(Integration integration, PluginCommandRQ pluginCommandRq) {
return List.of(ISSUE, INCIDENT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,31 @@

import static java.util.Optional.ofNullable;

import com.epam.reportportal.extension.PluginCommand;
import com.epam.reportportal.extension.gitlab.client.GitlabClient;
import com.epam.reportportal.extension.gitlab.client.GitlabClientProvider;
import com.epam.reportportal.extension.gitlab.dto.IssueDto;
import com.epam.reportportal.api.model.PluginCommandRQ;
import com.epam.reportportal.base.infrastructure.persistence.dao.ProjectRepository;
import com.epam.reportportal.base.infrastructure.persistence.dao.organization.OrganizationRepositoryCustom;
import com.epam.reportportal.base.infrastructure.persistence.entity.integration.Integration;
import com.epam.reportportal.base.infrastructure.persistence.entity.integration.IntegrationParams;
import com.epam.reportportal.base.infrastructure.rules.exception.ErrorType;
import com.epam.reportportal.base.infrastructure.rules.exception.ReportPortalException;
import com.epam.reportportal.extension.command.AbstractExtensionCommand;
import com.epam.reportportal.extension.gitlab.client.GitlabClient;
import com.epam.reportportal.extension.gitlab.client.GitlabClientProvider;
import com.epam.reportportal.extension.gitlab.dto.IssueDto;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;

/**
* @author Zsolt Nagyaghy
*/
public class GetIssuesCommand implements PluginCommand<List<IssueDto>> {

private static final Logger LOGGER = LoggerFactory.getLogger(GetIssuesCommand.class);
@Slf4j
public class GetIssuesCommand extends AbstractExtensionCommand<List<IssueDto>> {

private final GitlabClientProvider gitlabClientProvider;

public GetIssuesCommand(GitlabClientProvider gitlabClientProvider) {
public GetIssuesCommand(GitlabClientProvider gitlabClientProvider,
ProjectRepository projectRepository, OrganizationRepositoryCustom organizationRepository) {
super(projectRepository, organizationRepository);
this.gitlabClientProvider = gitlabClientProvider;
}

Expand All @@ -50,7 +52,7 @@ public String getName() {
}

@Override
public List<IssueDto> executeCommand(Integration integration, Map<String, Object> params) {
protected List<IssueDto> invokeCommand(Integration integration, PluginCommandRQ pluginCommandRq) {
IntegrationParams integrationParams = ofNullable(integration.getParams()).orElseThrow(
() -> new ReportPortalException(ErrorType.UNABLE_INTERACT_WITH_INTEGRATION,
"Integration params are not specified."
Expand All @@ -65,7 +67,7 @@ public List<IssueDto> executeCommand(Integration integration, Map<String, Object
GitlabClient restClient = gitlabClientProvider.get(integrationParams);
return restClient.getIssues(project);
} catch (Exception e) {
LOGGER.error("Issues not found: {}", e.getMessage(), e);
log.error("Issues not found: {}", e.getMessage(), e);
throw new ReportPortalException(ErrorType.UNABLE_INTERACT_WITH_INTEGRATION,
"Failed to retrieve the Gitlab tickets");
}
Expand Down
Loading
Loading