Search in sources :

Example 1 with MergeCheckResult

use of com.cloudogu.scm.review.pullrequest.service.MergeCheckResult in project scm-review-plugin by scm-manager.

the class MergeResourceTest method shouldHandleFailedDryRun.

@Test
void shouldHandleFailedDryRun() throws IOException, URISyntaxException {
    when(mergeService.checkMerge(any(), any())).thenReturn(new MergeCheckResult(true, emptyList()));
    byte[] mergeCommandJson = loadJson("com/cloudogu/scm/review/mergeCommand.json");
    MockHttpRequest request = createHttpPostRequest(MERGE_URL + "/merge-check", mergeCommandJson);
    MockHttpResponse response = new MockHttpResponse();
    dispatcher.invoke(request, response);
    assertThat(response.getStatus()).isEqualTo(200);
    assertThat(response.getContentAsString()).contains("\"hasConflicts\":true");
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) MergeCheckResult(com.cloudogu.scm.review.pullrequest.service.MergeCheckResult) MockHttpResponse(org.jboss.resteasy.mock.MockHttpResponse) JsonMockHttpResponse(sonia.scm.web.JsonMockHttpResponse) Test(org.junit.jupiter.api.Test)

Example 2 with MergeCheckResult

use of com.cloudogu.scm.review.pullrequest.service.MergeCheckResult in project scm-review-plugin by scm-manager.

the class MergeResource method check.

@POST
@Path("{namespace}/{name}/{pullRequestId}/merge-check")
@Produces(PullRequestMediaType.MERGE_CHECK_RESULT)
@Operation(summary = "Check pull request merge", description = "Checks if the pull request can be merged.", tags = "Pull Request")
@ApiResponse(responseCode = "200", description = "update success", content = @Content(mediaType = PullRequestMediaType.MERGE_CHECK_RESULT, schema = @Schema(implementation = MergeCheckResultDto.class)))
@ApiResponse(responseCode = "401", description = "not authenticated / invalid credentials")
@ApiResponse(responseCode = "403", description = "not authorized, the current user does not have the \"readPullRequest\" privilege")
@ApiResponse(responseCode = "404", description = "not found, no pull request with the specified id is available")
@ApiResponse(responseCode = "500", description = "internal server error", content = @Content(mediaType = VndMediaType.ERROR_TYPE, schema = @Schema(implementation = ErrorDto.class)))
public MergeCheckResultDto check(@PathParam("namespace") String namespace, @PathParam("name") String name, @PathParam("pullRequestId") String pullRequestId, @Context UriInfo uriInfo) {
    NamespaceAndName namespaceAndName = new NamespaceAndName(namespace, name);
    MergeCheckResult mergeCheckResult = service.checkMerge(namespaceAndName, pullRequestId);
    String checkLink = new PullRequestResourceLinks(uriInfo::getBaseUri).mergeLinks().check(namespace, name, pullRequestId);
    return new MergeCheckResultDto(Links.linkingTo().self(checkLink).build(), mergeCheckResult.hasConflicts(), mergeCheckResult.getMergeObstacles());
}
Also used : MergeCheckResultDto(com.cloudogu.scm.review.pullrequest.dto.MergeCheckResultDto) NamespaceAndName(sonia.scm.repository.NamespaceAndName) MergeCheckResult(com.cloudogu.scm.review.pullrequest.service.MergeCheckResult) PullRequestResourceLinks(com.cloudogu.scm.review.PullRequestResourceLinks) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse)

Example 3 with MergeCheckResult

use of com.cloudogu.scm.review.pullrequest.service.MergeCheckResult in project scm-review-plugin by scm-manager.

the class MergeResourceTest method shouldHandleSuccessfulDryRun.

@Test
void shouldHandleSuccessfulDryRun() throws IOException, URISyntaxException {
    when(mergeService.checkMerge(any(), any())).thenReturn(new MergeCheckResult(false, emptyList()));
    byte[] mergeCommandJson = loadJson("com/cloudogu/scm/review/mergeCommand.json");
    MockHttpRequest request = createHttpPostRequest(MERGE_URL + "/merge-check", mergeCommandJson);
    MockHttpResponse response = new MockHttpResponse();
    dispatcher.invoke(request, response);
    assertThat(response.getStatus()).isEqualTo(200);
    assertThat(response.getContentAsString()).contains("\"hasConflicts\":false");
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) MergeCheckResult(com.cloudogu.scm.review.pullrequest.service.MergeCheckResult) MockHttpResponse(org.jboss.resteasy.mock.MockHttpResponse) JsonMockHttpResponse(sonia.scm.web.JsonMockHttpResponse) Test(org.junit.jupiter.api.Test)

Aggregations

MergeCheckResult (com.cloudogu.scm.review.pullrequest.service.MergeCheckResult)3 MockHttpRequest (org.jboss.resteasy.mock.MockHttpRequest)2 MockHttpResponse (org.jboss.resteasy.mock.MockHttpResponse)2 Test (org.junit.jupiter.api.Test)2 JsonMockHttpResponse (sonia.scm.web.JsonMockHttpResponse)2 PullRequestResourceLinks (com.cloudogu.scm.review.PullRequestResourceLinks)1 MergeCheckResultDto (com.cloudogu.scm.review.pullrequest.dto.MergeCheckResultDto)1 Operation (io.swagger.v3.oas.annotations.Operation)1 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 NamespaceAndName (sonia.scm.repository.NamespaceAndName)1