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 <jcentkowski@collab.net>
This commit is contained in:

committed by
David Pursehouse

parent
533b6c19a2
commit
36d3521623
@@ -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.
|
||||
|
@@ -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> accountPatchReviewStore;
|
||||
|
||||
@Inject
|
||||
BatchAbandon(AbandonOp.Factory abandonOpFactory) {
|
||||
BatchAbandon(
|
||||
AbandonOp.Factory abandonOpFactory,
|
||||
ChangeCleanupConfig cfg,
|
||||
PluginItemContext<AccountPatchReviewStore> 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<ChangeData> changes) {
|
||||
for (ChangeData change : changes) {
|
||||
accountPatchReviewStore.run(s -> s.clearReviewed(change.getId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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> 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("");
|
||||
|
Reference in New Issue
Block a user