Search in sources :

Example 1 with Subscribe

use of com.github.legman.Subscribe in project scm-review-plugin by scm-manager.

the class CommentIndexer method handleEvent.

@Subscribe
public void handleEvent(CommentEvent event) {
    Comment comment = event.getItem();
    PullRequest pullRequest = event.getPullRequest();
    Repository repository = event.getRepository();
    if (event.getEventType() == HandlerEventType.CREATE || event.getEventType() == HandlerEventType.MODIFY) {
        updateIndexedComment(repository, pullRequest, IndexedComment.transform(pullRequest.getId(), comment));
    } else if (event.getEventType() == HandlerEventType.DELETE) {
        Comment deletedComment = event.getOldItem();
        searchEngine.forType(IndexedComment.class).update(index -> index.delete().byId(createCommentId(deletedComment.getId(), pullRequest.getId(), repository.getId())));
    }
}
Also used : Index(sonia.scm.search.Index) RepositoryImportEvent(sonia.scm.repository.RepositoryImportEvent) RepositoryPermissions(sonia.scm.repository.RepositoryPermissions) IndexLog(sonia.scm.search.IndexLog) Subscribe(com.github.legman.Subscribe) Extension(sonia.scm.plugin.Extension) IndexTask(sonia.scm.search.IndexTask) Repository(sonia.scm.repository.Repository) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) Inject(javax.inject.Inject) HandlerEventType(sonia.scm.HandlerEventType) SearchEngine(sonia.scm.search.SearchEngine) RepositoryManager(sonia.scm.repository.RepositoryManager) ServletContextEvent(javax.servlet.ServletContextEvent) SerializableIndexTask(sonia.scm.search.SerializableIndexTask) Optional(java.util.Optional) PermissionCheck(com.cloudogu.scm.review.PermissionCheck) PullRequestService(com.cloudogu.scm.review.pullrequest.service.PullRequestService) Id(sonia.scm.search.Id) IndexLogStore(sonia.scm.search.IndexLogStore) ServletContextListener(javax.servlet.ServletContextListener) Repository(sonia.scm.repository.Repository) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) Subscribe(com.github.legman.Subscribe)

Example 2 with Subscribe

use of com.github.legman.Subscribe in project scm-review-plugin by scm-manager.

the class CommentIndexer method handleEvent.

@Subscribe
public void handleEvent(ReplyEvent event) {
    Reply comment = event.getItem();
    PullRequest pullRequest = event.getPullRequest();
    Repository repository = event.getRepository();
    if (event.getEventType() == HandlerEventType.CREATE || event.getEventType() == HandlerEventType.MODIFY) {
        updateIndexedComment(repository, pullRequest, IndexedComment.transform(pullRequest.getId(), comment));
    } else if (event.getEventType() == HandlerEventType.DELETE) {
        Reply deletedReply = event.getOldItem();
        searchEngine.forType(IndexedComment.class).update(index -> index.delete().byId(createCommentId(deletedReply.getId(), pullRequest.getId(), repository.getId())));
    }
}
Also used : Index(sonia.scm.search.Index) RepositoryImportEvent(sonia.scm.repository.RepositoryImportEvent) RepositoryPermissions(sonia.scm.repository.RepositoryPermissions) IndexLog(sonia.scm.search.IndexLog) Subscribe(com.github.legman.Subscribe) Extension(sonia.scm.plugin.Extension) IndexTask(sonia.scm.search.IndexTask) Repository(sonia.scm.repository.Repository) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) Inject(javax.inject.Inject) HandlerEventType(sonia.scm.HandlerEventType) SearchEngine(sonia.scm.search.SearchEngine) RepositoryManager(sonia.scm.repository.RepositoryManager) ServletContextEvent(javax.servlet.ServletContextEvent) SerializableIndexTask(sonia.scm.search.SerializableIndexTask) Optional(java.util.Optional) PermissionCheck(com.cloudogu.scm.review.PermissionCheck) PullRequestService(com.cloudogu.scm.review.pullrequest.service.PullRequestService) Id(sonia.scm.search.Id) IndexLogStore(sonia.scm.search.IndexLogStore) ServletContextListener(javax.servlet.ServletContextListener) Repository(sonia.scm.repository.Repository) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) Subscribe(com.github.legman.Subscribe)

Example 3 with Subscribe

use of com.github.legman.Subscribe in project scm-review-plugin by scm-manager.

the class EmailNotificationHook method handleCommentEvents.

@Subscribe
public void handleCommentEvents(CommentEvent event) {
    if (!isSystemComment(event)) {
        PullRequest pullRequest = event.getPullRequest();
        handleEvent(event, new CommentEventMailTextResolver(event), pullRequest, getSubscribersWithoutCurrentUser(pullRequest));
    }
}
Also used : PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) Subscribe(com.github.legman.Subscribe)

Example 4 with Subscribe

use of com.github.legman.Subscribe in project scm-review-plugin by scm-manager.

the class EventListener method handle.

@Subscribe
public void handle(BasicPullRequestEvent event) {
    Channel channel = channel(event);
    channel.broadcast(message(event));
}
Also used : Channel(sonia.scm.sse.Channel) Subscribe(com.github.legman.Subscribe)

Example 5 with Subscribe

use of com.github.legman.Subscribe 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)

Aggregations

Subscribe (com.github.legman.Subscribe)14 PullRequest (com.cloudogu.scm.review.pullrequest.service.PullRequest)12 Repository (sonia.scm.repository.Repository)5 PermissionCheck (com.cloudogu.scm.review.PermissionCheck)2 PullRequestService (com.cloudogu.scm.review.pullrequest.service.PullRequestService)2 Optional (java.util.Optional)2 Inject (javax.inject.Inject)2 ServletContextEvent (javax.servlet.ServletContextEvent)2 ServletContextListener (javax.servlet.ServletContextListener)2 HandlerEventType (sonia.scm.HandlerEventType)2 Extension (sonia.scm.plugin.Extension)2 RepositoryImportEvent (sonia.scm.repository.RepositoryImportEvent)2 RepositoryManager (sonia.scm.repository.RepositoryManager)2 RepositoryPermissions (sonia.scm.repository.RepositoryPermissions)2 HookContext (sonia.scm.repository.api.HookContext)2 Id (sonia.scm.search.Id)2 Index (sonia.scm.search.Index)2 IndexLog (sonia.scm.search.IndexLog)2 IndexLogStore (sonia.scm.search.IndexLogStore)2 IndexTask (sonia.scm.search.IndexTask)2