use of com.hp.octane.integrations.dto.scm.PullRequest in project octane-gitlab-service by MicroFocus.
the class PullRequestHelper method convertAndSendMergeRequestToOctane.
public static void convertAndSendMergeRequestToOctane(MergeRequest mergeRequest, List<Commit> mrCommits, Map<String, List<Diff>> mrCommitDiffs, String repoUrl, String destinationWS) {
SCMRepository sourceScmRepository = PullRequestHelper.createGitScmRepository(repoUrl, mergeRequest.getSourceBranch());
SCMRepository targetScmRepository = PullRequestHelper.createGitScmRepository(repoUrl, mergeRequest.getTargetBranch());
List<SCMCommit> pullRequestCommits = convertMergeRequestCommits(mrCommits, mrCommitDiffs);
PullRequest pullRequest = PullRequestHelper.createPullRequest(mergeRequest, sourceScmRepository, targetScmRepository, pullRequestCommits);
sendPullRequestToOctane(repoUrl, pullRequest, destinationWS);
}
use of com.hp.octane.integrations.dto.scm.PullRequest in project octane-ci-java-sdk by MicroFocus.
the class PullRequestAndBranchServiceImpl method sendPullRequests.
@Override
public void sendPullRequests(List<PullRequest> pullRequests, String workspaceId, PullRequestFetchParameters pullRequestFetchParameters, Consumer<String> logConsumer) throws IOException {
Map<String, String> headers = new LinkedHashMap<>();
headers.put(RestService.CONTENT_TYPE_HEADER, ContentType.APPLICATION_JSON.getMimeType());
String url = configurer.octaneConfiguration.getUrl() + RestService.SHARED_SPACE_API_PATH_PART + configurer.octaneConfiguration.getSharedSpace() + "/workspaces/" + workspaceId + RestService.ANALYTICS_CI_PATH_PART + "pull-requests/";
int sentCounter = 0;
List<List<PullRequest>> subSets = ListUtils.partition(pullRequests, 200);
for (List<PullRequest> list : subSets) {
String json = dtoFactory.dtoCollectionToJson(list);
OctaneRequest octaneRequest = dtoFactory.newDTO(OctaneRequest.class).setMethod(HttpMethod.PUT).setUrl(url).setHeaders(headers).setBody(json);
OctaneResponse octaneResponse = restService.obtainOctaneRestClient().execute(octaneRequest);
if (octaneResponse.getStatus() != HttpStatus.SC_OK) {
if (octaneResponse.getStatus() == HttpStatus.SC_NOT_FOUND) {
throw new ResourceNotFoundException("Failed to sendPullRequests : received 404 status. Validate that you use correct workspace id and ALM Octane version is greater than " + PullRequestAndBranchService.BRANCH_COLLECTION_SUPPORTED_VERSION);
} else {
throw new RuntimeException("Failed to sendPullRequests : (" + octaneResponse.getStatus() + ")" + octaneResponse.getBody());
}
} else {
sentCounter += list.size();
logConsumer.accept(String.format("Sent %s/%s pull requests.", sentCounter, pullRequests.size()));
}
}
long lastUpdateTime = pullRequests.stream().map(PullRequest::getUpdatedTime).max(Comparator.naturalOrder()).orElse(0L);
savePullRequestLastUpdateTime(workspaceId, pullRequestFetchParameters.getRepoUrl(), lastUpdateTime);
logConsumer.accept("Last update time set to " + lastUpdateTime);
}
Aggregations