use of sonia.scm.NotFoundException in project scm-review-plugin by scm-manager.
the class CommentService method modifyComment.
public void modifyComment(String namespace, String name, String pullRequestId, String commentId, Comment changedComment) {
Repository repository = repositoryResolver.resolve(new NamespaceAndName(namespace, name));
PullRequest pullRequest = pullRequestService.get(repository, pullRequestId);
Comment rootComment = findRootComment(repository, pullRequestId, commentId).<NotFoundException>orElseThrow(() -> {
throw notFound(entity(BasicComment.class, String.valueOf(changedComment.getId())).in(PullRequest.class, pullRequestId).in(repository.getNamespaceAndName()));
});
PermissionCheck.checkModifyComment(repository, rootComment);
Comment clone = rootComment.clone();
rootComment.setComment(changedComment.getComment());
handleMentions(repository, pullRequest, rootComment, clone);
rootComment.addTransition(new ExecutedTransition<>(keyGenerator.createKey(), CHANGE_TEXT, System.currentTimeMillis(), getCurrentUserId()));
getCommentStore(repository).update(pullRequestId, rootComment);
eventBus.post(new CommentEvent(repository, pullRequest, rootComment, clone, HandlerEventType.MODIFY));
}
use of sonia.scm.NotFoundException in project scm-review-plugin by scm-manager.
the class CommentService method markAsOutdated.
public void markAsOutdated(String namespace, String name, String pullRequestId, String commentId) {
Repository repository = repositoryResolver.resolve(new NamespaceAndName(namespace, name));
Comment rootComment = findRootComment(repository, pullRequestId, commentId).<NotFoundException>orElseThrow(() -> {
throw notFound(entity(BasicComment.class, commentId).in(PullRequest.class, pullRequestId).in(repository.getNamespaceAndName()));
});
if (!rootComment.isOutdated()) {
rootComment.setOutdated(true);
getCommentStore(repository).update(pullRequestId, rootComment);
}
}
use of sonia.scm.NotFoundException in project scm-review-plugin by scm-manager.
the class RepositoryResolverTest method testResolveRepositoryNotFound.
@Test
public void testResolveRepositoryNotFound() {
NotFoundException exception = assertThrows(NotFoundException.class, () -> resolver.resolve(namespaceAndName));
ContextEntry contextEntry = exception.getContext().get(0);
assertThat(contextEntry.getType()).isEqualTo("Repository");
assertThat(contextEntry.getId()).isEqualTo("hitchhiker/heartOfGold");
}
use of sonia.scm.NotFoundException in project scm-review-plugin by scm-manager.
the class PullRequestRootResourceTest method shouldFailOnUpdatingNonExistingPullRequest.
@Test
@SubjectAware(username = "slarti")
public void shouldFailOnUpdatingNonExistingPullRequest() throws URISyntaxException, IOException {
initRepoWithPRs("ns", "repo");
when(store.get("opened_1")).thenThrow(new NotFoundException("x", "y"));
MockHttpRequest request = MockHttpRequest.put("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/ns/repo/opened_1").content("{\"title\": \"new Title\", \"description\": \"new description\"}".getBytes()).contentType(PullRequestMediaType.PULL_REQUEST);
dispatcher.invoke(request, response);
assertThat(response.getContentAsString()).containsPattern("could not find.*");
verify(store, never()).update(any());
}
use of sonia.scm.NotFoundException in project scm-review-plugin by scm-manager.
the class PullRequestRootResourceTest method shouldHandleMissingRepository.
@Test
@SubjectAware(username = "trillian")
public void shouldHandleMissingRepository() throws URISyntaxException, IOException {
when(repositoryResolver.resolve(new NamespaceAndName("space", "X"))).thenThrow(new NotFoundException("x", "y"));
byte[] pullRequestJson = loadJson("com/cloudogu/scm/review/pullRequest.json");
MockHttpRequest request = MockHttpRequest.post("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/space/X").content(pullRequestJson).contentType(PullRequestMediaType.PULL_REQUEST);
dispatcher.invoke(request, response);
assertThat(response.getContentAsString()).containsPattern("could not find.*");
}
Aggregations