From 36d3521623cb4824ddabeb0ba29462da51a0a803 Mon Sep 17 00:00:00 2001 From: Jacek Centkowski Date: Mon, 13 May 2019 14:32:00 +0200 Subject: [PATCH] Remove AccountPatchReview data when change gets auto-abandoned Add 'changeCleanup.cleanupAccountPatchReview' parameter (by default 'false') to wipe out AccountPatchReview data when change gets auto-abandoned. Change-Id: Ie7ac0a6c70284ba20c8bd674b82bfa3f01bf35aa Signed-off-by: Jacek Centkowski --- Documentation/config-gerrit.txt | 7 +++++++ .../gerrit/server/change/BatchAbandon.java | 21 ++++++++++++++++++- .../server/config/ChangeCleanupConfig.java | 8 +++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/Documentation/config-gerrit.txt b/Documentation/config-gerrit.txt index d8801eb07b..b28f943b20 100644 --- a/Documentation/config-gerrit.txt +++ b/Documentation/config-gerrit.txt @@ -1364,6 +1364,13 @@ Whether changes which are mergeable should be auto-abandoned. + By default `true`. +[[changeCleanup.cleanupAccountPatchReview]]changeCleanup.cleanupAccountPatchReview:: ++ +Whether accountPatchReview data should be also removed when change +gets auto-abandoned. ++ +By default `false`. + [[changeCleanup.abandonMessage]]changeCleanup.abandonMessage:: + Change message that should be posted when a change is abandoned. diff --git a/java/com/google/gerrit/server/change/BatchAbandon.java b/java/com/google/gerrit/server/change/BatchAbandon.java index 8c675312fe..bc29c5dc54 100644 --- a/java/com/google/gerrit/server/change/BatchAbandon.java +++ b/java/com/google/gerrit/server/change/BatchAbandon.java @@ -19,6 +19,8 @@ import com.google.gerrit.extensions.restapi.RestApiException; import com.google.gerrit.reviewdb.client.Project; import com.google.gerrit.server.CurrentUser; import com.google.gerrit.server.account.AccountState; +import com.google.gerrit.server.config.ChangeCleanupConfig; +import com.google.gerrit.server.plugincontext.PluginItemContext; import com.google.gerrit.server.query.change.ChangeData; import com.google.gerrit.server.update.BatchUpdate; import com.google.gerrit.server.update.UpdateException; @@ -30,10 +32,17 @@ import java.util.Collection; @Singleton public class BatchAbandon { private final AbandonOp.Factory abandonOpFactory; + private final ChangeCleanupConfig cfg; + private final PluginItemContext accountPatchReviewStore; @Inject - BatchAbandon(AbandonOp.Factory abandonOpFactory) { + BatchAbandon( + AbandonOp.Factory abandonOpFactory, + ChangeCleanupConfig cfg, + PluginItemContext accountPatchReviewStore) { this.abandonOpFactory = abandonOpFactory; + this.cfg = cfg; + this.accountPatchReviewStore = accountPatchReviewStore; } /** @@ -67,6 +76,10 @@ public class BatchAbandon { u.addOp(change.getId(), abandonOpFactory.create(accountState, msgTxt)); } u.execute(); + + if (cfg.getCleanupAccountPatchReview()) { + cleanupAccountPatchReview(changes); + } } } @@ -88,4 +101,10 @@ public class BatchAbandon { throws RestApiException, UpdateException { batchAbandon(updateFactory, project, user, changes, "", NotifyResolver.Result.all()); } + + private void cleanupAccountPatchReview(Collection changes) { + for (ChangeData change : changes) { + accountPatchReviewStore.run(s -> s.clearReviewed(change.getId())); + } + } } diff --git a/java/com/google/gerrit/server/config/ChangeCleanupConfig.java b/java/com/google/gerrit/server/config/ChangeCleanupConfig.java index f5c9fc24d8..4d41ed7b1c 100644 --- a/java/com/google/gerrit/server/config/ChangeCleanupConfig.java +++ b/java/com/google/gerrit/server/config/ChangeCleanupConfig.java @@ -29,6 +29,7 @@ public class ChangeCleanupConfig { private static String KEY_ABANDON_AFTER = "abandonAfter"; private static String KEY_ABANDON_IF_MERGEABLE = "abandonIfMergeable"; private static String KEY_ABANDON_MESSAGE = "abandonMessage"; + private static String KEY_CLEANUP_ACCOUNT_PATCH_REVIEW = "cleanupAccountPatchReview"; private static String DEFAULT_ABANDON_MESSAGE = "Auto-Abandoned due to inactivity, see " + "${URL}\n" @@ -39,6 +40,7 @@ public class ChangeCleanupConfig { private final Optional schedule; private final long abandonAfter; private final boolean abandonIfMergeable; + private final boolean cleanupAccountPatchReview; private final String abandonMessage; @Inject @@ -47,6 +49,8 @@ public class ChangeCleanupConfig { schedule = ScheduleConfig.createSchedule(cfg, SECTION); abandonAfter = readAbandonAfter(cfg); abandonIfMergeable = cfg.getBoolean(SECTION, null, KEY_ABANDON_IF_MERGEABLE, true); + cleanupAccountPatchReview = + cfg.getBoolean(SECTION, null, KEY_CLEANUP_ACCOUNT_PATCH_REVIEW, false); abandonMessage = readAbandonMessage(cfg); } @@ -73,6 +77,10 @@ public class ChangeCleanupConfig { return abandonIfMergeable; } + public boolean getCleanupAccountPatchReview() { + return cleanupAccountPatchReview; + } + public String getAbandonMessage() { String docUrl = urlFormatter.get().getDocUrl("user-change-cleanup.html", "auto-abandon").orElse("");