LCOV - code coverage report
Current view: top level - server/change - ReviewerOp.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 21 22 95.5 %
Date: 2022-11-19 15:00:39 Functions: 10 11 90.9 %

          Line data    Source code
       1             : // Copyright (C) 2021 The Android Open Source Project
       2             : //
       3             : // Licensed under the Apache License, Version 2.0 (the "License");
       4             : // you may not use this file except in compliance with the License.
       5             : // You may obtain a copy of the License at
       6             : //
       7             : // http://www.apache.org/licenses/LICENSE-2.0
       8             : //
       9             : // Unless required by applicable law or agreed to in writing, software
      10             : // distributed under the License is distributed on an "AS IS" BASIS,
      11             : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      12             : // See the License for the specific language governing permissions and
      13             : // limitations under the License.
      14             : 
      15             : package com.google.gerrit.server.change;
      16             : 
      17             : import static com.google.common.base.Preconditions.checkState;
      18             : import static java.util.Objects.requireNonNull;
      19             : 
      20             : import com.google.auto.value.AutoValue;
      21             : import com.google.common.collect.ImmutableList;
      22             : import com.google.gerrit.entities.Account;
      23             : import com.google.gerrit.entities.Address;
      24             : import com.google.gerrit.entities.PatchSet;
      25             : import com.google.gerrit.entities.PatchSetApproval;
      26             : import com.google.gerrit.extensions.restapi.RestApiException;
      27             : import com.google.gerrit.server.permissions.PermissionBackendException;
      28             : import com.google.gerrit.server.update.BatchUpdateOp;
      29             : import com.google.gerrit.server.update.ChangeContext;
      30             : import java.io.IOException;
      31             : import java.util.Optional;
      32             : 
      33          48 : public class ReviewerOp implements BatchUpdateOp {
      34          48 :   protected boolean sendEmail = true;
      35          48 :   protected boolean sendEvent = true;
      36          48 :   protected Runnable eventSender = () -> {};
      37             :   protected PatchSet patchSet;
      38             :   protected Result opResult;
      39             : 
      40             :   // TODO(dborowitz): This mutable setter is ugly, but a) it's less ugly than adding boolean args
      41             :   // all the way through the constructor stack, and b) this class is slated to be completely
      42             :   // rewritten.
      43             :   public void suppressEmail() {
      44          37 :     this.sendEmail = false;
      45          37 :   }
      46             : 
      47             :   public void suppressEvent() {
      48          24 :     this.sendEvent = false;
      49          24 :   }
      50             : 
      51             :   public void sendEvent() {
      52          34 :     eventSender.run();
      53          34 :   }
      54             : 
      55             :   void setPatchSet(PatchSet patchSet) {
      56          28 :     this.patchSet = requireNonNull(patchSet);
      57          28 :   }
      58             : 
      59             :   @AutoValue
      60          48 :   public abstract static class Result {
      61             :     public abstract ImmutableList<PatchSetApproval> addedReviewers();
      62             : 
      63             :     public abstract ImmutableList<Address> addedReviewersByEmail();
      64             : 
      65             :     public abstract ImmutableList<Account.Id> addedCCs();
      66             : 
      67             :     public abstract ImmutableList<Address> addedCCsByEmail();
      68             : 
      69             :     public abstract Optional<Account.Id> deletedReviewer();
      70             : 
      71             :     public abstract Optional<Address> deletedReviewerByEmail();
      72             : 
      73             :     static Builder builder() {
      74          48 :       return new AutoValue_ReviewerOp_Result.Builder()
      75          48 :           .setAddedReviewers(ImmutableList.of())
      76          48 :           .setAddedReviewersByEmail(ImmutableList.of())
      77          48 :           .setAddedCCs(ImmutableList.of())
      78          48 :           .setAddedCCsByEmail(ImmutableList.of());
      79             :     }
      80             : 
      81             :     @AutoValue.Builder
      82          48 :     abstract static class Builder {
      83             :       abstract Builder setAddedReviewers(Iterable<PatchSetApproval> addedReviewers);
      84             : 
      85             :       abstract Builder setAddedReviewersByEmail(Iterable<Address> addedReviewersByEmail);
      86             : 
      87             :       abstract Builder setAddedCCs(Iterable<Account.Id> addedCCs);
      88             : 
      89             :       abstract Builder setAddedCCsByEmail(Iterable<Address> addedCCsByEmail);
      90             : 
      91             :       abstract Builder setDeletedReviewerByEmail(Address deletedReviewerByEmail);
      92             : 
      93             :       abstract Builder setDeletedReviewer(Account.Id deletedReviewer);
      94             : 
      95             :       abstract Result build();
      96             :     }
      97             :   }
      98             : 
      99             :   public Result getResult() {
     100          39 :     checkState(opResult != null, "Batch update wasn't executed yet");
     101          39 :     return opResult;
     102             :   }
     103             : 
     104             :   @Override
     105             :   public boolean updateChange(ChangeContext ctx)
     106             :       throws RestApiException, IOException, PermissionBackendException {
     107           0 :     return false;
     108             :   }
     109             : }

Generated by: LCOV version 1.16+git.20220603.dfeb750