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();
}
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;
}));
}
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");
}
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();
}
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>");
}
Aggregations