Search in sources :

Example 1 with NotifyConfig

use of com.google.gerrit.server.git.NotifyConfig in project gerrit by GerritCodeReview.

the class ProjectWatchIT method noNotificationForDraftPatchSetsForWatchersInNotifyConfig.

@Test
public void noNotificationForDraftPatchSetsForWatchersInNotifyConfig() throws Exception {
    Address addr = new Address("Watcher", "watcher@example.com");
    NotifyConfig nc = new NotifyConfig();
    nc.addEmail(addr);
    nc.setName("team");
    nc.setHeader(NotifyConfig.Header.TO);
    nc.setTypes(EnumSet.of(NotifyType.NEW_PATCHSETS, NotifyType.ALL_COMMENTS));
    ProjectConfig cfg = projectCache.checkedGet(project).getConfig();
    cfg.putNotifyConfig("team", nc);
    saveProjectConfig(project, cfg);
    PushOneCommit.Result r = pushFactory.create(db, admin.getIdent(), testRepo, "subject", "a", "a1").to("refs/for/master");
    r.assertOkStatus();
    sender.clear();
    r = pushFactory.create(db, admin.getIdent(), testRepo, "subject", "a", "a2", r.getChangeId()).to("refs/for/master%draft");
    r.assertOkStatus();
    assertThat(sender.getMessages()).isEmpty();
    setApiUser(admin);
    ReviewInput in = new ReviewInput();
    in.message = "comment";
    gApi.changes().id(r.getChangeId()).current().review(in);
    assertThat(sender.getMessages()).isEmpty();
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig) Address(com.google.gerrit.server.mail.Address) NotifyConfig(com.google.gerrit.server.git.NotifyConfig) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 2 with NotifyConfig

use of com.google.gerrit.server.git.NotifyConfig in project gerrit by GerritCodeReview.

the class ProjectWatchIT method noNotificationForDraftChangesForWatchersInNotifyConfig.

@Test
public void noNotificationForDraftChangesForWatchersInNotifyConfig() throws Exception {
    Address addr = new Address("Watcher", "watcher@example.com");
    NotifyConfig nc = new NotifyConfig();
    nc.addEmail(addr);
    nc.setName("team");
    nc.setHeader(NotifyConfig.Header.TO);
    nc.setTypes(EnumSet.of(NotifyType.NEW_CHANGES, NotifyType.ALL_COMMENTS));
    ProjectConfig cfg = projectCache.checkedGet(project).getConfig();
    cfg.putNotifyConfig("team", nc);
    saveProjectConfig(project, cfg);
    PushOneCommit.Result r = pushFactory.create(db, admin.getIdent(), testRepo, "draft change", "a", "a1").to("refs/for/master%draft");
    r.assertOkStatus();
    assertThat(sender.getMessages()).isEmpty();
    setApiUser(admin);
    ReviewInput in = new ReviewInput();
    in.message = "comment";
    gApi.changes().id(r.getChangeId()).current().review(in);
    assertThat(sender.getMessages()).isEmpty();
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig) Address(com.google.gerrit.server.mail.Address) NotifyConfig(com.google.gerrit.server.git.NotifyConfig) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 3 with NotifyConfig

use of com.google.gerrit.server.git.NotifyConfig in project gerrit by GerritCodeReview.

the class ProjectWatch method getWatchers.

/** Returns all watchers that are relevant */
public final Watchers getWatchers(NotifyType type, boolean includeWatchersFromNotifyConfig) throws OrmException {
    Watchers matching = new Watchers();
    Set<Account.Id> projectWatchers = new HashSet<>();
    for (AccountState a : args.accountQueryProvider.get().byWatchedProject(project)) {
        Account.Id accountId = a.getAccount().getId();
        for (Map.Entry<ProjectWatchKey, Set<NotifyType>> e : a.getProjectWatches().entrySet()) {
            if (project.equals(e.getKey().project()) && add(matching, accountId, e.getKey(), e.getValue(), type)) {
                // We only want to prevent matching All-Projects if this filter hits
                projectWatchers.add(accountId);
            }
        }
    }
    for (AccountState a : args.accountQueryProvider.get().byWatchedProject(args.allProjectsName)) {
        for (Map.Entry<ProjectWatchKey, Set<NotifyType>> e : a.getProjectWatches().entrySet()) {
            if (args.allProjectsName.equals(e.getKey().project())) {
                Account.Id accountId = a.getAccount().getId();
                if (!projectWatchers.contains(accountId)) {
                    add(matching, accountId, e.getKey(), e.getValue(), type);
                }
            }
        }
    }
    if (!includeWatchersFromNotifyConfig) {
        return matching;
    }
    for (ProjectState state : projectState.tree()) {
        for (NotifyConfig nc : state.getConfig().getNotifyConfigs()) {
            if (nc.isNotify(type)) {
                try {
                    add(matching, nc);
                } catch (QueryParseException e) {
                    log.warn("Project {} has invalid notify {} filter \"{}\": {}", state.getProject().getName(), nc.getName(), nc.getFilter(), e.getMessage());
                }
            }
        }
    }
    return matching;
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) HashSet(java.util.HashSet) Set(java.util.Set) ProjectWatchKey(com.google.gerrit.server.account.WatchConfig.ProjectWatchKey) AccountState(com.google.gerrit.server.account.AccountState) QueryParseException(com.google.gerrit.server.query.QueryParseException) ProjectState(com.google.gerrit.server.project.ProjectState) NotifyConfig(com.google.gerrit.server.git.NotifyConfig) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

NotifyConfig (com.google.gerrit.server.git.NotifyConfig)3 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)2 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)2 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)2 ProjectConfig (com.google.gerrit.server.git.ProjectConfig)2 Address (com.google.gerrit.server.mail.Address)2 Test (org.junit.Test)2 Account (com.google.gerrit.reviewdb.client.Account)1 AccountState (com.google.gerrit.server.account.AccountState)1 ProjectWatchKey (com.google.gerrit.server.account.WatchConfig.ProjectWatchKey)1 ProjectState (com.google.gerrit.server.project.ProjectState)1 QueryParseException (com.google.gerrit.server.query.QueryParseException)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1