Allow to configure new changes as private by default
This change makes it possible to configure the 'gerrit.config' so that every change created will be private by default. Change-Id: Ie7cdb6f71471405b0d15c23abc9fe7f36e1e4782
This commit is contained in:
@@ -1152,6 +1152,16 @@ Zero or negative values allow robot comments of unlimited size.
|
|||||||
+
|
+
|
||||||
The default limit is 1024kB.
|
The default limit is 1024kB.
|
||||||
|
|
||||||
|
[[change.privateByDefault]]change.privateByDefault::
|
||||||
|
+
|
||||||
|
If set to true, every change created will be private by default.
|
||||||
|
+
|
||||||
|
Note that the newly created change will be public if the `is_private` field in
|
||||||
|
link:rest-api-changes.html#change-input[ChangeInput] is set to `false` explicitly
|
||||||
|
or the `remove-private` link:user-upload.html#private[PushOption] is used in the push.
|
||||||
|
+
|
||||||
|
The default is false.
|
||||||
|
|
||||||
[[changeCleanup]]
|
[[changeCleanup]]
|
||||||
=== Section changeCleanup
|
=== Section changeCleanup
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
// Copyright (C) 2017 The Android Open Source Project
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package com.google.gerrit.acceptance.rest.change;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||||
|
import com.google.gerrit.acceptance.GerritConfig;
|
||||||
|
import com.google.gerrit.extensions.common.ChangeInfo;
|
||||||
|
import com.google.gerrit.extensions.common.ChangeInput;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class PrivateByDefaultIT extends AbstractDaemonTest {
|
||||||
|
@Test
|
||||||
|
@GerritConfig(name = "change.privateByDefault", value = "true")
|
||||||
|
public void createChangeWithPrivateByDefaultEnabled() throws Exception {
|
||||||
|
ChangeInput input = new ChangeInput(project.get(), "master", "empty change");
|
||||||
|
assertThat(gApi.changes().create(input).get().isPrivate).isEqualTo(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@GerritConfig(name = "change.privateByDefault", value = "true")
|
||||||
|
public void createChangeBypassPrivateByDefaultEnabled() throws Exception {
|
||||||
|
ChangeInput input = new ChangeInput(project.get(), "master", "empty change");
|
||||||
|
input.isPrivate = false;
|
||||||
|
assertThat(gApi.changes().create(input).get().isPrivate).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void createChangeWithPrivateByDefaultDisabled() throws Exception {
|
||||||
|
ChangeInfo info =
|
||||||
|
gApi.changes().create(new ChangeInput(project.get(), "master", "empty change")).get();
|
||||||
|
assertThat(info.isPrivate).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@GerritConfig(name = "change.privateByDefault", value = "true")
|
||||||
|
public void pushWithPrivateByDefaultEnabled() throws Exception {
|
||||||
|
assertThat(createChange().getChange().change().isPrivate()).isEqualTo(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@GerritConfig(name = "change.privateByDefault", value = "true")
|
||||||
|
public void pushBypassPrivateByDefaultEnabled() throws Exception {
|
||||||
|
assertThat(createChange("refs/for/master%remove-private").getChange().change().isPrivate())
|
||||||
|
.isEqualTo(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void pushWithPrivateByDefaultDisabled() throws Exception {
|
||||||
|
assertThat(createChange().getChange().change().isPrivate()).isEqualTo(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -105,6 +105,7 @@ public class CreateChange
|
|||||||
private final ChangeFinder changeFinder;
|
private final ChangeFinder changeFinder;
|
||||||
private final PatchSetUtil psUtil;
|
private final PatchSetUtil psUtil;
|
||||||
private final boolean allowDrafts;
|
private final boolean allowDrafts;
|
||||||
|
private final boolean privateByDefault;
|
||||||
private final MergeUtil.Factory mergeUtilFactory;
|
private final MergeUtil.Factory mergeUtilFactory;
|
||||||
private final SubmitType submitType;
|
private final SubmitType submitType;
|
||||||
private final NotifyUtil notifyUtil;
|
private final NotifyUtil notifyUtil;
|
||||||
@@ -143,6 +144,7 @@ public class CreateChange
|
|||||||
this.changeFinder = changeFinder;
|
this.changeFinder = changeFinder;
|
||||||
this.psUtil = psUtil;
|
this.psUtil = psUtil;
|
||||||
this.allowDrafts = config.getBoolean("change", "allowDrafts", true);
|
this.allowDrafts = config.getBoolean("change", "allowDrafts", true);
|
||||||
|
this.privateByDefault = config.getBoolean("change", "privateByDefault", false);
|
||||||
this.submitType = config.getEnum("project", null, "submitType", SubmitType.MERGE_IF_NECESSARY);
|
this.submitType = config.getEnum("project", null, "submitType", SubmitType.MERGE_IF_NECESSARY);
|
||||||
this.mergeUtilFactory = mergeUtilFactory;
|
this.mergeUtilFactory = mergeUtilFactory;
|
||||||
this.notifyUtil = notifyUtil;
|
this.notifyUtil = notifyUtil;
|
||||||
@@ -258,7 +260,7 @@ public class CreateChange
|
|||||||
}
|
}
|
||||||
ins.setTopic(topic);
|
ins.setTopic(topic);
|
||||||
ins.setDraft(input.status == ChangeStatus.DRAFT);
|
ins.setDraft(input.status == ChangeStatus.DRAFT);
|
||||||
ins.setPrivate(input.isPrivate != null && input.isPrivate);
|
ins.setPrivate(input.isPrivate == null ? privateByDefault : input.isPrivate);
|
||||||
ins.setWorkInProgress(input.workInProgress != null && input.workInProgress);
|
ins.setWorkInProgress(input.workInProgress != null && input.workInProgress);
|
||||||
ins.setGroups(groups);
|
ins.setGroups(groups);
|
||||||
ins.setNotify(input.notify);
|
ins.setNotify(input.notify);
|
||||||
|
|||||||
@@ -2177,7 +2177,9 @@ public class ReceiveCommits {
|
|||||||
changeInserterFactory
|
changeInserterFactory
|
||||||
.create(changeId, commit, refName)
|
.create(changeId, commit, refName)
|
||||||
.setTopic(magicBranch.topic)
|
.setTopic(magicBranch.topic)
|
||||||
.setPrivate(magicBranch.isPrivate)
|
.setPrivate(
|
||||||
|
magicBranch.isPrivate
|
||||||
|
|| (receiveConfig.privateByDefault && !magicBranch.removePrivate))
|
||||||
.setWorkInProgress(magicBranch.workInProgress)
|
.setWorkInProgress(magicBranch.workInProgress)
|
||||||
// Changes already validated in validateNewCommits.
|
// Changes already validated in validateNewCommits.
|
||||||
.setValidate(false);
|
.setValidate(false);
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ class ReceiveConfig {
|
|||||||
final boolean checkMagicRefs;
|
final boolean checkMagicRefs;
|
||||||
final boolean checkReferencedObjectsAreReachable;
|
final boolean checkReferencedObjectsAreReachable;
|
||||||
final boolean allowDrafts;
|
final boolean allowDrafts;
|
||||||
|
final boolean privateByDefault;
|
||||||
private final int systemMaxBatchChanges;
|
private final int systemMaxBatchChanges;
|
||||||
private final AccountLimits.Factory limitsFactory;
|
private final AccountLimits.Factory limitsFactory;
|
||||||
|
|
||||||
@@ -37,6 +38,7 @@ class ReceiveConfig {
|
|||||||
checkReferencedObjectsAreReachable =
|
checkReferencedObjectsAreReachable =
|
||||||
config.getBoolean("receive", null, "checkReferencedObjectsAreReachable", true);
|
config.getBoolean("receive", null, "checkReferencedObjectsAreReachable", true);
|
||||||
allowDrafts = config.getBoolean("change", null, "allowDrafts", true);
|
allowDrafts = config.getBoolean("change", null, "allowDrafts", true);
|
||||||
|
privateByDefault = config.getBoolean("change", null, "privateByDefault", false);
|
||||||
systemMaxBatchChanges = config.getInt("receive", "maxBatchChanges", 0);
|
systemMaxBatchChanges = config.getInt("receive", "maxBatchChanges", 0);
|
||||||
this.limitsFactory = limitsFactory;
|
this.limitsFactory = limitsFactory;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user