Merge "Allow to configure new changes as private by default"
This commit is contained in:
commit
b27f99d5d8
@ -1152,6 +1152,16 @@ Zero or negative values allow robot comments of unlimited size.
|
||||
+
|
||||
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]]
|
||||
=== 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 PatchSetUtil psUtil;
|
||||
private final boolean allowDrafts;
|
||||
private final boolean privateByDefault;
|
||||
private final MergeUtil.Factory mergeUtilFactory;
|
||||
private final SubmitType submitType;
|
||||
private final NotifyUtil notifyUtil;
|
||||
@ -143,6 +144,7 @@ public class CreateChange
|
||||
this.changeFinder = changeFinder;
|
||||
this.psUtil = psUtil;
|
||||
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.mergeUtilFactory = mergeUtilFactory;
|
||||
this.notifyUtil = notifyUtil;
|
||||
@ -258,7 +260,7 @@ public class CreateChange
|
||||
}
|
||||
ins.setTopic(topic);
|
||||
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.setGroups(groups);
|
||||
ins.setNotify(input.notify);
|
||||
|
@ -2177,7 +2177,9 @@ public class ReceiveCommits {
|
||||
changeInserterFactory
|
||||
.create(changeId, commit, refName)
|
||||
.setTopic(magicBranch.topic)
|
||||
.setPrivate(magicBranch.isPrivate)
|
||||
.setPrivate(
|
||||
magicBranch.isPrivate
|
||||
|| (receiveConfig.privateByDefault && !magicBranch.removePrivate))
|
||||
.setWorkInProgress(magicBranch.workInProgress)
|
||||
// Changes already validated in validateNewCommits.
|
||||
.setValidate(false);
|
||||
|
@ -28,6 +28,7 @@ class ReceiveConfig {
|
||||
final boolean checkMagicRefs;
|
||||
final boolean checkReferencedObjectsAreReachable;
|
||||
final boolean allowDrafts;
|
||||
final boolean privateByDefault;
|
||||
private final int systemMaxBatchChanges;
|
||||
private final AccountLimits.Factory limitsFactory;
|
||||
|
||||
@ -37,6 +38,7 @@ class ReceiveConfig {
|
||||
checkReferencedObjectsAreReachable =
|
||||
config.getBoolean("receive", null, "checkReferencedObjectsAreReachable", true);
|
||||
allowDrafts = config.getBoolean("change", null, "allowDrafts", true);
|
||||
privateByDefault = config.getBoolean("change", null, "privateByDefault", false);
|
||||
systemMaxBatchChanges = config.getInt("receive", "maxBatchChanges", 0);
|
||||
this.limitsFactory = limitsFactory;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user