Search in sources :

Example 1 with RepoView

use of com.google.gerrit.server.update.RepoView in project gerrit by GerritCodeReview.

the class PublishCommentsOp method postUpdate.

@Override
public void postUpdate(PostUpdateContext ctx) {
    if (Strings.isNullOrEmpty(mailMessage) || comments.isEmpty()) {
        return;
    }
    ChangeNotes changeNotes = changeNotesFactory.createChecked(projectNameKey, psId.changeId());
    PatchSet ps = psUtil.get(changeNotes, psId);
    NotifyResolver.Result notify = ctx.getNotify(changeNotes.getChangeId());
    if (notify.shouldNotify()) {
        RepoView repoView;
        try {
            repoView = ctx.getRepoView();
        } catch (IOException ex) {
            throw new StorageException(String.format("Repository %s not found", ctx.getProject().get()), ex);
        }
        email.create(notify, changeNotes, ps, user, mailMessage, ctx.getWhen(), comments, null, labelDelta, repoView).sendAsync();
    }
    commentAdded.fire(ctx.getChangeData(changeNotes), ps, ctx.getAccount(), mailMessage, ImmutableMap.of(), ImmutableMap.of(), ctx.getWhen());
}
Also used : NotifyResolver(com.google.gerrit.server.change.NotifyResolver) PatchSet(com.google.gerrit.entities.PatchSet) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) IOException(java.io.IOException) StorageException(com.google.gerrit.exceptions.StorageException) RepoView(com.google.gerrit.server.update.RepoView)

Example 2 with RepoView

use of com.google.gerrit.server.update.RepoView in project gerrit by GerritCodeReview.

the class WorkInProgressOp method postUpdate.

@Override
public void postUpdate(PostUpdateContext ctx) {
    stateChanged.fire(ctx.getChangeData(change), ps, ctx.getAccount(), ctx.getWhen());
    NotifyResolver.Result notify = ctx.getNotify(change.getId());
    if (workInProgress || notify.handling().compareTo(NotifyHandling.OWNER_REVIEWERS) < 0 || !sendEmail) {
        return;
    }
    RepoView repoView;
    try {
        repoView = ctx.getRepoView();
    } catch (IOException ex) {
        throw new StorageException(String.format("Repository %s not found", ctx.getProject().get()), ex);
    }
    email.create(notify, notes, ps, ctx.getIdentifiedUser(), mailMessage, ctx.getWhen(), ImmutableList.of(), mailMessage, ImmutableList.of(), repoView).sendAsync();
}
Also used : IOException(java.io.IOException) StorageException(com.google.gerrit.exceptions.StorageException) RepoView(com.google.gerrit.server.update.RepoView)

Example 3 with RepoView

use of com.google.gerrit.server.update.RepoView in project gerrit by GerritCodeReview.

the class MessageIdGenerator method fromChangeUpdateAndReason.

public MessageId fromChangeUpdateAndReason(RepoView repoView, PatchSet.Id patchsetId, @Nullable String reason) {
    String suffix = (reason != null) ? ("-" + reason) : "";
    String metaRef = patchsetId.changeId().toRefPrefix() + "meta";
    Optional<ObjectId> metaSha1;
    try {
        metaSha1 = repoView.getRef(metaRef);
    } catch (IOException ex) {
        throw new StorageException("unable to extract info for Message-Id", ex);
    }
    return metaSha1.map(optional -> new AutoValue_MessageIdGenerator_MessageId(optional.getName() + suffix)).orElseThrow(() -> new IllegalStateException(metaRef + " doesn't exist"));
}
Also used : AllUsersName(com.google.gerrit.server.config.AllUsersName) MailMessage(com.google.gerrit.mail.MailMessage) StorageException(com.google.gerrit.exceptions.StorageException) Inject(com.google.inject.Inject) Account(com.google.gerrit.entities.Account) IOException(java.io.IOException) Instant(java.time.Instant) Preconditions.checkState(com.google.common.base.Preconditions.checkState) ObjectId(org.eclipse.jgit.lib.ObjectId) Nullable(com.google.gerrit.common.Nullable) GitRepositoryManager(com.google.gerrit.server.git.GitRepositoryManager) Ref(org.eclipse.jgit.lib.Ref) AutoValue(com.google.auto.value.AutoValue) Project(com.google.gerrit.entities.Project) RefNames(com.google.gerrit.entities.RefNames) Optional(java.util.Optional) PatchSet(com.google.gerrit.entities.PatchSet) RepoView(com.google.gerrit.server.update.RepoView) Repository(org.eclipse.jgit.lib.Repository) ObjectId(org.eclipse.jgit.lib.ObjectId) IOException(java.io.IOException) StorageException(com.google.gerrit.exceptions.StorageException)

Aggregations

StorageException (com.google.gerrit.exceptions.StorageException)3 RepoView (com.google.gerrit.server.update.RepoView)3 IOException (java.io.IOException)3 PatchSet (com.google.gerrit.entities.PatchSet)2 AutoValue (com.google.auto.value.AutoValue)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Nullable (com.google.gerrit.common.Nullable)1 Account (com.google.gerrit.entities.Account)1 Project (com.google.gerrit.entities.Project)1 RefNames (com.google.gerrit.entities.RefNames)1 MailMessage (com.google.gerrit.mail.MailMessage)1 NotifyResolver (com.google.gerrit.server.change.NotifyResolver)1 AllUsersName (com.google.gerrit.server.config.AllUsersName)1 GitRepositoryManager (com.google.gerrit.server.git.GitRepositoryManager)1 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)1 Inject (com.google.inject.Inject)1 Instant (java.time.Instant)1 Optional (java.util.Optional)1 ObjectId (org.eclipse.jgit.lib.ObjectId)1 Ref (org.eclipse.jgit.lib.Ref)1