Search in sources :

Example 16 with Repository

use of sonia.scm.repository.Repository in project scm-review-plugin by scm-manager.

the class PullRequestResource method markAsNotReviewed.

@DELETE
@Path("review-mark/{path: .*}")
@Operation(summary = "Unmark as reviewed", description = "Unmarks a diff in a pull request which was before marked as reviewed.", tags = "Pull Request")
@ApiResponse(responseCode = "204", description = "update success")
@ApiResponse(responseCode = "401", description = "not authenticated / invalid credentials")
@ApiResponse(responseCode = "403", description = "not authorized, the current user does not have the \"modifyPullRequest\" 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 void markAsNotReviewed(@Context UriInfo uriInfo, @PathParam("namespace") String namespace, @PathParam("name") String name, @PathParam("pullRequestId") String pullRequestId, @PathParam("path") String path) {
    Repository repository = service.getRepository(namespace, name);
    service.markAsNotReviewed(repository, pullRequestId, path);
}
Also used : Repository(sonia.scm.repository.Repository) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse)

Example 17 with Repository

use of sonia.scm.repository.Repository in project scm-review-plugin by scm-manager.

the class PullRequestResource method markAsReviewed.

@POST
@Path("review-mark/{path: .*}")
@Operation(summary = "Mark as reviewed", description = "Marks a diff in a pull request as reviewed.", tags = "Pull Request")
@ApiResponse(responseCode = "204", description = "update success")
@ApiResponse(responseCode = "401", description = "not authenticated / invalid credentials")
@ApiResponse(responseCode = "403", description = "not authorized, the current user does not have the \"modifyPullRequest\" 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 void markAsReviewed(@Context UriInfo uriInfo, @PathParam("namespace") String namespace, @PathParam("name") String name, @PathParam("pullRequestId") String pullRequestId, @PathParam("path") String path) {
    Repository repository = service.getRepository(namespace, name);
    service.markAsReviewed(repository, pullRequestId, path);
}
Also used : Repository(sonia.scm.repository.Repository) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse)

Example 18 with Repository

use of sonia.scm.repository.Repository in project scm-review-plugin by scm-manager.

the class PullRequestResource method unsubscribe.

@POST
@Path("unsubscribe")
@Operation(summary = "Unsubscribe", description = "Unsubscribes current user from a pull request.", tags = "Pull Request")
@ApiResponse(responseCode = "204", description = "update success")
@ApiResponse(responseCode = "401", description = "not authenticated / invalid credentials")
@ApiResponse(responseCode = "403", description = "not authorized, the current user does not have the \"modifyPullRequest\" privilege")
@ApiResponse(responseCode = "500", description = "internal server error", content = @Content(mediaType = VndMediaType.ERROR_TYPE, schema = @Schema(implementation = ErrorDto.class)))
public void unsubscribe(@Context UriInfo uriInfo, @PathParam("namespace") String namespace, @PathParam("name") String name, @PathParam("pullRequestId") String pullRequestId) {
    Repository repository = service.getRepository(namespace, name);
    PermissionCheck.checkRead(repository);
    service.unsubscribe(repository, pullRequestId);
}
Also used : Repository(sonia.scm.repository.Repository) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse)

Example 19 with Repository

use of sonia.scm.repository.Repository in project scm-review-plugin by scm-manager.

the class MergeService method merge.

public void merge(NamespaceAndName namespaceAndName, String pullRequestId, MergeCommitDto mergeCommitDto, MergeStrategy strategy, boolean emergency) {
    try (RepositoryService repositoryService = serviceFactory.create(namespaceAndName)) {
        PullRequest pullRequest = pullRequestService.get(repositoryService.getRepository(), pullRequestId);
        Collection<MergeObstacle> obstacles = verifyNoObstacles(emergency, repositoryService.getRepository(), pullRequest);
        assertPullRequestIsOpen(repositoryService.getRepository(), pullRequest);
        internalMergeSwitch.runInternalMerge(() -> {
            MergeCommandBuilder mergeCommand = repositoryService.getMergeCommand();
            isAllowedToMerge(repositoryService.getRepository(), mergeCommand, strategy, emergency);
            prepareMergeCommand(repositoryService, mergeCommand, pullRequest, mergeCommitDto, strategy);
            MergeCommandResult mergeCommandResult = mergeCommand.executeMerge();
            if (!mergeCommandResult.isSuccess()) {
                throw new MergeConflictException(namespaceAndName, pullRequest.getSource(), pullRequest.getTarget(), mergeCommandResult);
            }
            pullRequestService.setRevisions(repositoryService.getRepository(), pullRequest.getId(), mergeCommandResult.getTargetRevision(), mergeCommandResult.getRevisionToMerge());
            if (emergency) {
                pullRequestService.setEmergencyMerged(repositoryService.getRepository(), pullRequest.getId(), mergeCommitDto.getOverrideMessage(), getIgnoredMergeObstacles(obstacles));
            } else {
                pullRequestService.setMerged(repositoryService.getRepository(), pullRequest.getId());
            }
            if (repositoryService.isSupported(Command.BRANCH) && mergeCommitDto.isShouldDeleteSourceBranch()) {
                String deletedSourceBranch = pullRequest.getSource();
                Repository repository = repositoryService.getRepository();
                repositoryService.getBranchCommand().delete(deletedSourceBranch);
                rejectPullRequestsForDeletedBranch(repository, pullRequest, deletedSourceBranch);
            }
        });
    }
}
Also used : Repository(sonia.scm.repository.Repository) MergeCommandBuilder(sonia.scm.repository.api.MergeCommandBuilder) MergeCommandResult(sonia.scm.repository.api.MergeCommandResult) RepositoryService(sonia.scm.repository.api.RepositoryService)

Example 20 with Repository

use of sonia.scm.repository.Repository in project scm-review-plugin by scm-manager.

the class CommentCollectorTest method shouldCollectNonOutdatedComments.

@Test
void shouldCollectNonOutdatedComments() {
    Repository repository = RepositoryTestData.createHeartOfGold();
    PullRequest pullRequest = TestData.createPullRequest();
    Comment one = Comment.createSystemComment("hello");
    Comment two = Comment.createSystemComment("hello");
    two.setOutdated(true);
    List<Comment> prcs = ImmutableList.of(one, two);
    when(commentService.getAll(repository.getNamespace(), repository.getName(), pullRequest.getId())).thenReturn(prcs);
    Stream<Comment> comments = collector.collectNonOutdated(repository, pullRequest);
    assertThat(comments).containsOnly(one);
}
Also used : Repository(sonia.scm.repository.Repository) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) Test(org.junit.jupiter.api.Test)

Aggregations

Repository (sonia.scm.repository.Repository)66 PullRequest (com.cloudogu.scm.review.pullrequest.service.PullRequest)25 Operation (io.swagger.v3.oas.annotations.Operation)20 Path (javax.ws.rs.Path)20 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)19 NamespaceAndName (sonia.scm.repository.NamespaceAndName)16 GET (javax.ws.rs.GET)11 Produces (javax.ws.rs.Produces)11 Test (org.junit.jupiter.api.Test)9 Subscribe (com.github.legman.Subscribe)6 SubjectAware (com.github.sdorra.shiro.SubjectAware)6 Consumes (javax.ws.rs.Consumes)6 POST (javax.ws.rs.POST)6 Test (org.junit.Test)6 HalEnricherContext (sonia.scm.api.v2.resources.HalEnricherContext)6 PermissionCheck (com.cloudogu.scm.review.PermissionCheck)5 PullRequestResourceLinks (com.cloudogu.scm.review.PullRequestResourceLinks)5 Comment (com.cloudogu.scm.review.comment.service.Comment)5 PullRequestService (com.cloudogu.scm.review.pullrequest.service.PullRequestService)5 Inject (javax.inject.Inject)5