Search in sources :

Example 1 with HookContext

use of sonia.scm.repository.api.HookContext 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 2 with HookContext

use of sonia.scm.repository.api.HookContext 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

Subscribe (com.github.legman.Subscribe)2 Repository (sonia.scm.repository.Repository)2 HookContext (sonia.scm.repository.api.HookContext)2 PullRequest (com.cloudogu.scm.review.pullrequest.service.PullRequest)1