Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EPMRPP-87433 || Add comment, logs, attachment support #16

Merged
merged 29 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b03d59a
EMPRPP-87433 || Add comments and log support in description
pbortnik Nov 24, 2023
5e61544
EPMRPP-87433 || Add description builder sullpier
pbortnik Nov 24, 2023
e972fda
Merge branch 'develop' of https://github.com/reportportal/plugin-bts-…
pbortnik Nov 24, 2023
d1cf10c
EPMRPP-87433 || Add description field id
pbortnik Nov 24, 2023
22e2de5
EPMRPP-87433 || Add logging
pbortnik Nov 24, 2023
0aafda0
EPMRPP-87433 || Replace http call
pbortnik Nov 24, 2023
39ba524
EPMRPP-87433 || Update http headers
pbortnik Nov 24, 2023
3d1b562
EPMRPP-87433 || Variant with different field values
pbortnik Nov 24, 2023
19caad6
EPMRPP-87433 || Update description
pbortnik Nov 24, 2023
5e9dbd5
EPMRPP-87433 || Add more logging
pbortnik Nov 24, 2023
24aa3db
EPMRPP-87433 || Add more logging
pbortnik Nov 24, 2023
63878ee
EPMRPP-87433 || Add more logging
pbortnik Nov 24, 2023
47ec8e3
EPMRPP-87433 || Fix description
pbortnik Nov 24, 2023
0b94213
EPMRPP-87433 || Cleanup description
pbortnik Nov 24, 2023
b83e0b7
EMPRPP-87433 || Test implementation of attachment storing
pbortnik Nov 26, 2023
945d962
EPMRPP-87433 || Remove unused constructors
pbortnik Nov 27, 2023
74185bb
EMPRPP-87433 || Update attachment type
pbortnik Nov 27, 2023
1ee6aa1
Merge remote-tracking branch 'origin/feature/EPMRPP-87433' into featu…
pbortnik Nov 27, 2023
718516b
EMPRPP-87433 || Update attachment type
pbortnik Nov 27, 2023
45523ea
EMPRPP-87433 || Change resource type
pbortnik Nov 27, 2023
6050d14
EMPRPP-87433 || Update upload rest template call
pbortnik Nov 27, 2023
b5614f6
EMPRPP-87433 || Fix path url
pbortnik Nov 27, 2023
8edf8d6
EPMRPP-87433 || Add debug logging
pbortnik Nov 27, 2023
2311bcd
EPMRPP-87433 || Update commons-dao
pbortnik Nov 27, 2023
dc905bd
EPMRPP-87433 || Update markdown
pbortnik Nov 27, 2023
5f04ea7
EPMRPP-87433 || Cleanup markdown
pbortnik Nov 27, 2023
53ec4d1
EPMRPP-87433 || Fix responce type
pbortnik Nov 27, 2023
963d316
EPMRPP-87433 || Update markdown
pbortnik Nov 27, 2023
abd8a47
EPMRPP-87433 || Update plugin api version
pbortnik Nov 27, 2023
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
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ dependencies {
implementation 'com.epam.reportportal:plugin-api'
annotationProcessor 'com.epam.reportportal:plugin-api'
} else {
implementation 'com.github.reportportal:plugin-api:3876fab'
annotationProcessor 'com.github.reportportal:plugin-api:3876fab'
implementation 'com.github.reportportal:plugin-api:b9b5252cf2'
annotationProcessor 'com.github.reportportal:plugin-api:b9b5252cf2'
}

implementation group: 'javax.servlet', name: 'javax.servlet-api', version: '4.0.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.epam.reportportal.extension.event.PluginEvent;
import com.epam.reportportal.extension.event.StartLaunchEvent;
import com.epam.reportportal.extension.gitlab.client.GitlabClientProvider;
import com.epam.reportportal.extension.gitlab.command.DescriptionBuilderService;
import com.epam.reportportal.extension.gitlab.command.GetIssueCommand;
import com.epam.reportportal.extension.gitlab.command.GetIssueFieldsCommand;
import com.epam.reportportal.extension.gitlab.command.GetIssueTypesCommand;
Expand All @@ -28,11 +29,13 @@
import com.epam.reportportal.extension.gitlab.utils.GitlabObjectMapperProvider;
import com.epam.reportportal.extension.gitlab.utils.MemoizingSupplier;
import com.epam.reportportal.extension.util.RequestEntityConverter;
import com.epam.ta.reportportal.binary.DataStoreService;
import com.epam.ta.reportportal.dao.IntegrationRepository;
import com.epam.ta.reportportal.dao.IntegrationTypeRepository;
import com.epam.ta.reportportal.dao.LaunchRepository;
import com.epam.ta.reportportal.dao.LogRepository;
import com.epam.ta.reportportal.dao.ProjectRepository;
import com.epam.ta.reportportal.dao.TestItemRepository;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand All @@ -44,6 +47,7 @@
import org.pf4j.Extension;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ApplicationEventMulticaster;
Expand All @@ -64,8 +68,7 @@ public class GitlabExtension implements ReportPortalExtensionPoint, DisposableBe
private final Supplier<ApplicationListener<PluginEvent>> pluginLoadedListenerSupplier;
private final Supplier<ApplicationListener<StartLaunchEvent>> startLaunchEventListenerSupplier;
private final Supplier<GitlabClientProvider> gitlabClientProviderSupplier;
private final Supplier<Map<String, PluginCommand<?>>> pluginCommandMapping = new MemoizingSupplier<>(
this::getCommands);
private final Supplier<DescriptionBuilderService> descriptionBuilderServiceSupplier;
@Autowired
private ApplicationContext applicationContext;
@Autowired
Expand All @@ -74,14 +77,21 @@ public class GitlabExtension implements ReportPortalExtensionPoint, DisposableBe
private IntegrationRepository integrationRepository;
@Autowired
private ProjectRepository projectRepository;
private final Supplier<Map<String, PluginCommand<?>>> pluginCommandMapping = new MemoizingSupplier<>(
this::getCommands);
@Autowired
private LaunchRepository launchRepository;
@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;

public GitlabExtension(Map<String, Object> initParams) {
resourcesDir = IntegrationTypeProperties.RESOURCES_DIRECTORY.getValue(initParams)
Expand All @@ -100,6 +110,8 @@ public GitlabExtension(Map<String, Object> initParams) {
() -> new GitlabClientProvider(textEncryptor));
requestEntityConverter = new RequestEntityConverter(
new GitlabObjectMapperProvider().getObjectMapper());
descriptionBuilderServiceSupplier = new MemoizingSupplier<>(
() -> new DescriptionBuilderService(logRepository, testItemRepository, dataStoreService));
}

@Override
Expand Down Expand Up @@ -173,7 +185,7 @@ private Map<String, PluginCommand<?>> getCommands() {
commands.add(new GetIssueTypesCommand(projectRepository));
commands.add(new GetIssueFieldsCommand(projectRepository));
commands.add(new PostTicketCommand(projectRepository, gitlabClientProviderSupplier.get(),
requestEntityConverter));
requestEntityConverter, descriptionBuilderServiceSupplier.get()));
return commands.stream().collect(Collectors.toMap(NamedPluginCommand::getName, it -> it));
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package com.epam.reportportal.extension.gitlab.client;


import static org.hibernate.bytecode.BytecodeLogger.LOGGER;

import com.epam.reportportal.extension.gitlab.dto.EpicDto;
import com.epam.reportportal.extension.gitlab.dto.IssueDto;
import com.epam.reportportal.extension.gitlab.dto.LabelDto;
import com.epam.reportportal.extension.gitlab.dto.MilestoneDto;
import com.epam.reportportal.extension.gitlab.dto.ProjectDto;
import com.epam.reportportal.extension.gitlab.dto.UploadsLinkDto;
import com.epam.reportportal.extension.gitlab.dto.UserDto;
import com.epam.reportportal.extension.gitlab.utils.GitlabObjectMapperProvider;
import com.epam.ta.reportportal.entity.attachment.Attachment;
import com.epam.ta.reportportal.exception.ReportPortalException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand All @@ -20,14 +23,18 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import org.jooq.tools.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.ContentDisposition;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;

Expand All @@ -49,6 +56,7 @@ public class GitlabClient {
private static final String USERS_PATH = BASE_PATH + "/users?search=%s";
private static final String MILESTONES_PATH = BASE_PATH + "/milestones?search=%s";
private static final String LABELS_PATH = BASE_PATH + "/labels?search=%s";
private static final String UPLOADS_PATH = BASE_PATH + "/uploads";
private static final String EPICS_PATH = GROUP_BASE_PATH + "/epics?search=%s";
private static final Map<String, List<String>> pageParams = Map.of(QUERY_PER_PAGE,
List.of(DEFAULT_PAGE_SIZE.toString()), QUERY_PAGE, List.of("{page}"));
Expand Down Expand Up @@ -84,10 +92,15 @@ public List<IssueDto> getIssues(String projectId) {
});
}

public IssueDto postIssue(String projectId, Map<String, List<String>> queryParams) {
public IssueDto postIssue(String projectId, Map<String, String> queryParams) {
String pathUrl = String.format(ISSUES_PATH, baseUrl, projectId);
Object singleEntity = singleEntityRequests(pathUrl, queryParams, HttpMethod.POST);
return objectMapper.convertValue(singleEntity, IssueDto.class);
HttpHeaders httpHeaders = getHttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
JSONObject personJsonObject = new JSONObject();
personJsonObject.putAll(queryParams);
HttpEntity<String> request = new HttpEntity<>(personJsonObject.toString(), httpHeaders);
return objectMapper.convertValue(
exchangeRequest(request, new RestTemplate(), pathUrl, HttpMethod.POST), IssueDto.class);
}

public List<UserDto> searchUsers(String projectId, String term) {
Expand Down Expand Up @@ -128,7 +141,6 @@ private <T> T singleEntityRequests(String path, Map<String, List<String>> queryP
HttpEntity<String> entity = new HttpEntity<>(null, headers);
RestTemplate restTemplate = new RestTemplate();
String url = getUrl(path, queryParams);
logger.warn("Post ticker url: " + url);
return exchangeRequest(entity, restTemplate, url, method);
}

Expand Down Expand Up @@ -175,4 +187,44 @@ private HttpHeaders getHttpHeaders() {
return headers;
}

public UploadsLinkDto uploadFile(String projectId, Attachment attachment,
InputStream inputStream) {
String pathUrl = String.format(UPLOADS_PATH, baseUrl, projectId);
HttpHeaders headers = getHttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);

byte[] byteArray;
try {
byteArray = inputStream.readAllBytes();
} catch (IOException e) {
throw new ReportPortalException(e.getMessage());
}
MultiValueMap<String, String> fileMap = new LinkedMultiValueMap<>();

ContentDisposition contentDisposition = ContentDisposition
.builder("form-data")
.name("file")
.filename(attachment.getFileName())
.build();

fileMap.add(HttpHeaders.CONTENT_DISPOSITION, contentDisposition.toString());

HttpEntity<byte[]> fileEntity = new HttpEntity<>(byteArray, fileMap);

MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
body.add("file", fileEntity);

HttpEntity<MultiValueMap<String, Object>> requestEntity =
new HttpEntity<>(body, headers);
try {
ResponseEntity<UploadsLinkDto> response = new RestTemplate().exchange(
pathUrl,
HttpMethod.POST,
requestEntity,
UploadsLinkDto.class);
return response.getBody();
} catch (Exception e) {
throw new ReportPortalException(e.getMessage());
}
}
}
Loading