Search in sources :

Example 1 with User

use of sonia.scm.user.User in project scm-review-plugin by scm-manager.

the class PullRequestRootResource method create.

@POST
@Path("{namespace}/{name}")
@Consumes(PullRequestMediaType.PULL_REQUEST)
@Operation(summary = "Create pull request", description = "Creates a new pull request.", tags = "Pull Request", operationId = "review_create_pull_request")
@ApiResponse(responseCode = "201", description = "create success")
@ApiResponse(responseCode = "401", description = "not authenticated / invalid credentials")
@ApiResponse(responseCode = "403", description = "not authorized, the current user does not have the \"createPullRequest\" privilege")
@ApiResponse(responseCode = "409", description = "conflict, a similar pull request for these branches already exists")
@ApiResponse(responseCode = "500", description = "internal server error", content = @Content(mediaType = VndMediaType.ERROR_TYPE, schema = @Schema(implementation = ErrorDto.class)))
public Response create(@Context UriInfo uriInfo, @PathParam("namespace") String namespace, @PathParam("name") String name, @NotNull @Valid PullRequestDto pullRequestDto) {
    Repository repository = service.getRepository(namespace, name);
    PermissionCheck.checkCreate(repository);
    String source = pullRequestDto.getSource();
    String target = pullRequestDto.getTarget();
    service.get(repository, source, target, PullRequestStatus.OPEN).ifPresent(pullRequest -> {
        throw alreadyExists(entity(repository).in("pull request", pullRequest.getId()).in(repository));
    });
    service.checkBranch(repository, source);
    service.checkBranch(repository, target);
    verifyBranchesDiffer(source, target);
    User user = CurrentUserResolver.getCurrentUser();
    pullRequestDto.setStatus(PullRequestStatus.OPEN);
    PullRequest pullRequest = mapper.using(uriInfo).map(pullRequestDto);
    pullRequest.setAuthor(user.getId());
    String id = service.add(repository, pullRequest);
    URI location = uriInfo.getAbsolutePathBuilder().path(id).build();
    return Response.created(location).build();
}
Also used : Repository(sonia.scm.repository.Repository) User(sonia.scm.user.User) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) URI(java.net.URI) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse)

Example 2 with User

use of sonia.scm.user.User in project scm-review-plugin by scm-manager.

the class HitEnricherTest method shouldEnrichHitWithDisplayUser.

@Test
void shouldEnrichHitWithDisplayUser() {
    mockHit(ImmutableMap.of("author", new Hit.ValueField("trillian"), "pullRequestId", new Hit.ValueField("1")));
    when(userDisplayManager.get("trillian")).thenReturn(Optional.of(DisplayUser.from(new User("trillian", "Tricia McMillan", "trillian@hitchhiker.org"))));
    enricher.enrich(context, appender);
    verify(appender, times(1)).appendEmbedded(eq("user"), (DisplayedUserDto) argThat(user -> {
        assertThat(((DisplayedUserDto) user).getDisplayName()).isEqualTo("Tricia McMillan");
        return true;
    }));
}
Also used : User(sonia.scm.user.User) DisplayUser(sonia.scm.user.DisplayUser) DisplayedUserDto(com.cloudogu.scm.review.pullrequest.dto.DisplayedUserDto) Test(org.junit.jupiter.api.Test)

Example 3 with User

use of sonia.scm.user.User in project scm-review-plugin by scm-manager.

the class MergeResourceTest method shouldGetRebaseMergeStrategyInfo.

@Test
void shouldGetRebaseMergeStrategyInfo() throws URISyntaxException, UnsupportedEncodingException {
    CommitDefaults commitDefaults = new CommitDefaults("happy days", DisplayUser.from(new User("Arthur Dent")));
    when(mergeService.createCommitDefaults(any(), any(), eq(REBASE))).thenReturn(commitDefaults);
    when(mergeService.isCommitMessageDisabled(REBASE)).thenReturn(true);
    when(mergeService.createMergeCommitMessageHint(REBASE)).thenReturn(null);
    MockHttpRequest request = createHttpGetRequest(MERGE_URL + "/merge-strategy-info/?strategy=REBASE");
    MockHttpResponse response = new MockHttpResponse();
    dispatcher.invoke(request, response);
    assertThat(response.getStatus()).isEqualTo(200);
    assertThat(response.getContentAsString()).contains("happy days").contains("true").doesNotContain("commitMessageHint");
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) DisplayUser(sonia.scm.user.DisplayUser) User(sonia.scm.user.User) CommitDefaults(com.cloudogu.scm.review.pullrequest.service.MergeService.CommitDefaults) MockHttpResponse(org.jboss.resteasy.mock.MockHttpResponse) JsonMockHttpResponse(sonia.scm.web.JsonMockHttpResponse) Test(org.junit.jupiter.api.Test)

Example 4 with User

use of sonia.scm.user.User in project scm-review-plugin by scm-manager.

the class MergeResourceTest method shouldGetSquashMergeStrategyInfoWithoutMail.

@Test
void shouldGetSquashMergeStrategyInfoWithoutMail() throws URISyntaxException {
    when(mergeService.createCommitDefaults(any(), any(), eq(SQUASH))).thenReturn(new CommitDefaults("happy days", DisplayUser.from(new User("Arthur Dent"))));
    when(mergeService.isCommitMessageDisabled(SQUASH)).thenReturn(true);
    when(mergeService.createMergeCommitMessageHint(SQUASH)).thenReturn(null);
    MockHttpRequest request = createHttpGetRequest(MERGE_URL + "/merge-strategy-info/?strategy=SQUASH");
    JsonMockHttpResponse response = new JsonMockHttpResponse();
    dispatcher.invoke(request, response);
    assertThat(response.getStatus()).isEqualTo(200);
    JsonNode jsonResponse = response.getContentAsJson();
    assertThat(jsonResponse.get("commitMessageDisabled").asBoolean()).isTrue();
    assertThat(jsonResponse.get("defaultCommitMessage").asText()).isEqualTo("happy days");
    assertThat(jsonResponse.get("commitAuthor").asText()).isEqualTo("Arthur Dent");
    assertThat(jsonResponse.get("commitMessageHint")).isNull();
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) DisplayUser(sonia.scm.user.DisplayUser) User(sonia.scm.user.User) JsonMockHttpResponse(sonia.scm.web.JsonMockHttpResponse) JsonNode(com.fasterxml.jackson.databind.JsonNode) CommitDefaults(com.cloudogu.scm.review.pullrequest.service.MergeService.CommitDefaults) Test(org.junit.jupiter.api.Test)

Example 5 with User

use of sonia.scm.user.User in project scm-review-plugin by scm-manager.

the class MergeResourceTest method shouldGetSquashMergeStrategyInfoWithMail.

@Test
void shouldGetSquashMergeStrategyInfoWithMail() throws URISyntaxException {
    when(mergeService.createCommitDefaults(any(), any(), eq(SQUASH))).thenReturn(new CommitDefaults("happy days", DisplayUser.from(new User("dent", "Arthur Dent", "arthur@hitchhiker.com"))));
    MockHttpRequest request = createHttpGetRequest(MERGE_URL + "/merge-strategy-info/?strategy=SQUASH");
    JsonMockHttpResponse response = new JsonMockHttpResponse();
    dispatcher.invoke(request, response);
    JsonNode jsonResponse = response.getContentAsJson();
    assertThat(jsonResponse.get("commitAuthor").asText()).isEqualTo("Arthur Dent <arthur@hitchhiker.com>");
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) DisplayUser(sonia.scm.user.DisplayUser) User(sonia.scm.user.User) JsonMockHttpResponse(sonia.scm.web.JsonMockHttpResponse) JsonNode(com.fasterxml.jackson.databind.JsonNode) CommitDefaults(com.cloudogu.scm.review.pullrequest.service.MergeService.CommitDefaults) Test(org.junit.jupiter.api.Test)

Aggregations

User (sonia.scm.user.User)27 DisplayUser (sonia.scm.user.DisplayUser)23 MockHttpRequest (org.jboss.resteasy.mock.MockHttpRequest)15 Test (org.junit.Test)11 PullRequest (com.cloudogu.scm.review.pullrequest.service.PullRequest)9 TestData.createPullRequest (com.cloudogu.scm.review.TestData.createPullRequest)8 Test (org.junit.jupiter.api.Test)8 JsonNode (com.fasterxml.jackson.databind.JsonNode)7 CommitDefaults (com.cloudogu.scm.review.pullrequest.service.MergeService.CommitDefaults)6 SubjectAware (com.github.sdorra.shiro.SubjectAware)6 Changeset (sonia.scm.repository.Changeset)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 PrincipalCollection (org.apache.shiro.subject.PrincipalCollection)3 MockHttpResponse (org.jboss.resteasy.mock.MockHttpResponse)3 ChangesetPagingResult (sonia.scm.repository.ChangesetPagingResult)3 JsonMockHttpResponse (sonia.scm.web.JsonMockHttpResponse)3 DefaultPullRequestService (com.cloudogu.scm.review.pullrequest.service.DefaultPullRequestService)2 ReviewMark (com.cloudogu.scm.review.pullrequest.service.ReviewMark)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 Person (sonia.scm.repository.Person)2