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