Search in sources :

Example 26 with Repository

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

the class EventListenerTest method createPullRequestEvent.

private PullRequestEvent createPullRequestEvent() {
    Repository repository = RepositoryTestData.createHeartOfGold();
    PullRequest pullRequest = TestData.createPullRequest();
    mockChannel(repository, pullRequest);
    return new PullRequestEvent(repository, pullRequest, null, HandlerEventType.CREATE);
}
Also used : BasicPullRequestEvent(com.cloudogu.scm.review.pullrequest.service.BasicPullRequestEvent) PullRequestEvent(com.cloudogu.scm.review.pullrequest.service.PullRequestEvent) Repository(sonia.scm.repository.Repository) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest)

Example 27 with Repository

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

the class EventListenerTest method createCommentEvent.

private CommentEvent createCommentEvent() {
    Repository repository = RepositoryTestData.createHeartOfGold();
    PullRequest pullRequest = TestData.createPullRequest();
    mockChannel(repository, pullRequest);
    Comment comment = new Comment();
    comment.setId("c42");
    return new CommentEvent(repository, pullRequest, null, comment, HandlerEventType.DELETE);
}
Also used : Comment(com.cloudogu.scm.review.comment.service.Comment) CommentEvent(com.cloudogu.scm.review.comment.service.CommentEvent) Repository(sonia.scm.repository.Repository) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest)

Example 28 with Repository

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

the class PullRequestRootResourceTest method init.

@Before
public void init() {
    when(repository.getId()).thenReturn(REPOSITORY_ID);
    when(repository.getName()).thenReturn(REPOSITORY_NAME);
    when(repository.getNamespace()).thenReturn(REPOSITORY_NAMESPACE);
    when(repository.getNamespaceAndName()).thenReturn(new NamespaceAndName(REPOSITORY_NAMESPACE, REPOSITORY_NAME));
    when(repositoryResolver.resolve(any())).thenReturn(repository);
    when(pullRequestService.getRepository(repository.getNamespace(), repository.getName())).thenReturn(repository);
    DefaultPullRequestService service = new DefaultPullRequestService(repositoryResolver, branchResolver, storeFactory, eventBus, repositoryServiceFactory);
    pullRequestRootResource = new PullRequestRootResource(mapper, service, repositoryServiceFactory, Providers.of(new PullRequestResource(mapper, service, null, null, channelRegistry)));
    when(storeFactory.create(null)).thenReturn(store);
    when(storeFactory.create(any())).thenReturn(store);
    when(store.add(pullRequestStoreCaptor.capture())).thenReturn("1");
    when(branchLinkProvider.get(any(NamespaceAndName.class), anyString())).thenReturn("");
    dispatcher = new RestDispatcher();
    dispatcher.addSingletonResource(pullRequestRootResource);
    lenient().when(repositoryServiceFactory.create(any(Repository.class))).thenReturn(repositoryService);
    lenient().when(userDisplayManager.get("reviewer")).thenReturn(Optional.of(DisplayUser.from(new User("reviewer", "reviewer", ""))));
}
Also used : Repository(sonia.scm.repository.Repository) DefaultPullRequestService(com.cloudogu.scm.review.pullrequest.service.DefaultPullRequestService) DisplayUser(sonia.scm.user.DisplayUser) User(sonia.scm.user.User) NamespaceAndName(sonia.scm.repository.NamespaceAndName) RestDispatcher(sonia.scm.web.RestDispatcher) Before(org.junit.Before)

Example 29 with Repository

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

the class BranchProtectionHook method onEvent.

@Subscribe(async = false)
public void onEvent(PreReceiveRepositoryHookEvent event) {
    HookContext context = event.getContext();
    Repository repository = event.getRepository();
    if (ignoreHook(context, repository)) {
        return;
    }
    if (!service.isEnabled(repository)) {
        log.trace("branch protection is disabled.");
        return;
    }
    log.trace("received hook for repository {}", repository.getName());
    for (String branch : context.getBranchProvider().getCreatedOrModified()) {
        if (service.isBranchProtected(repository, branch)) {
            context.getChangesetProvider().getChangesets().forEach(changeset -> {
                if (changeset.getBranches().contains(branch) && !changeset.getParents().isEmpty()) {
                    throw new BranchOnlyWritableByMergeException(repository, branch);
                }
            });
        }
    }
    for (String branch : context.getBranchProvider().getDeletedOrClosed()) {
        if (service.isBranchProtected(repository, branch)) {
            throw new BranchOnlyWritableByMergeException(repository, branch);
        }
    }
}
Also used : Repository(sonia.scm.repository.Repository) HookContext(sonia.scm.repository.api.HookContext) Subscribe(com.github.legman.Subscribe)

Example 30 with Repository

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

the class MergeObstacleCheckHook method checkForObstacles.

@Subscribe(async = false)
public void checkForObstacles(PreReceiveRepositoryHookEvent event) {
    HookContext context = event.getContext();
    Repository repository = event.getRepository();
    if (ignoreHook(context, repository)) {
        return;
    }
    List<PullRequest> pullRequests = pullRequestService.getAll(repository.getNamespace(), repository.getName());
    new Worker(event).process(pullRequests);
}
Also used : Repository(sonia.scm.repository.Repository) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) HookContext(sonia.scm.repository.api.HookContext) Subscribe(com.github.legman.Subscribe)

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