Support wildcard matching in repository configuration
Per repository configuration was only supporting "*" as the repository name so it was only possible to configure one default submit type and same owner groups for all the new repositories. [repository "*"] ownerGroup = Registered Users defaultSubmitType = MERGE_IF_NECESSARY Now supports different repository configuration based on the name. The only matching patterns supported are exact match or wildcard matching which can be specified by ending the name by a *. Obviously, repository name "*" still represents all repositories. If a project matches more than one repository configuration, then the configuration from the more precise match will be used. In the following example, the default submit type for a project named project/plugins/a would be CHERRY_PICK. [repository "project/*"] defaultSubmitType = MERGE_IF_NECESSARY [repository "project/plugins/*"] defaultSubmitType = CHERRY_PICK Change-Id: I8b9c157f60a3ad1c6f542cef62e5de8fe9333126
This commit is contained in:
@@ -0,0 +1,147 @@
|
||||
// Copyright (C) 2014 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.server.config;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gerrit.extensions.client.SubmitType;
|
||||
import com.google.gerrit.reviewdb.client.Project.NameKey;
|
||||
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class RepositoryConfigTest {
|
||||
|
||||
private Config cfg;
|
||||
private RepositoryConfig repoCfg;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
cfg = new Config();
|
||||
repoCfg = new RepositoryConfig(cfg);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultSubmitTypeWhenNotConfigured() {
|
||||
assertThat(repoCfg.getDefaultSubmitType(new NameKey("someProject")))
|
||||
.isEqualTo(SubmitType.MERGE_IF_NECESSARY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultSubmitTypeForStarFilter() {
|
||||
configureDefaultSubmitType("*", SubmitType.CHERRY_PICK);
|
||||
assertThat(repoCfg.getDefaultSubmitType(new NameKey("someProject")))
|
||||
.isEqualTo(SubmitType.CHERRY_PICK);
|
||||
|
||||
configureDefaultSubmitType("*", SubmitType.FAST_FORWARD_ONLY);
|
||||
assertThat(repoCfg.getDefaultSubmitType(new NameKey("someProject")))
|
||||
.isEqualTo(SubmitType.FAST_FORWARD_ONLY);
|
||||
|
||||
configureDefaultSubmitType("*", SubmitType.REBASE_IF_NECESSARY);
|
||||
assertThat(repoCfg.getDefaultSubmitType(new NameKey("someProject")))
|
||||
.isEqualTo(SubmitType.REBASE_IF_NECESSARY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultSubmitTypeForSpecificFilter() {
|
||||
configureDefaultSubmitType("someProject", SubmitType.CHERRY_PICK);
|
||||
assertThat(repoCfg.getDefaultSubmitType(new NameKey("someOtherProject")))
|
||||
.isEqualTo(SubmitType.MERGE_IF_NECESSARY);
|
||||
assertThat(repoCfg.getDefaultSubmitType(new NameKey("someProject")))
|
||||
.isEqualTo(SubmitType.CHERRY_PICK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultSubmitTypeForStartWithFilter() {
|
||||
configureDefaultSubmitType("somePath/somePath/*",
|
||||
SubmitType.REBASE_IF_NECESSARY);
|
||||
configureDefaultSubmitType("somePath/*", SubmitType.CHERRY_PICK);
|
||||
configureDefaultSubmitType("*", SubmitType.MERGE_ALWAYS);
|
||||
|
||||
assertThat(repoCfg.getDefaultSubmitType(new NameKey("someProject")))
|
||||
.isEqualTo(SubmitType.MERGE_ALWAYS);
|
||||
|
||||
assertThat(
|
||||
repoCfg.getDefaultSubmitType(new NameKey("somePath/someProject")))
|
||||
.isEqualTo(SubmitType.CHERRY_PICK);
|
||||
|
||||
assertThat(
|
||||
repoCfg.getDefaultSubmitType(new NameKey(
|
||||
"somePath/somePath/someProject"))).isEqualTo(
|
||||
SubmitType.REBASE_IF_NECESSARY);
|
||||
}
|
||||
|
||||
private void configureDefaultSubmitType(String projectFilter,
|
||||
SubmitType submitType) {
|
||||
cfg.setString(RepositoryConfig.SECTION_NAME, projectFilter,
|
||||
RepositoryConfig.DEFAULT_SUBMIT_TYPE_NAME, submitType.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOwnerGroupsWhenNotConfigured() {
|
||||
assertThat(repoCfg.getOwnerGroups(new NameKey("someProject"))).isEqualTo(
|
||||
new String[] {});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOwnerGroupsForStarFilter() {
|
||||
String[] ownerGroups = new String[] {"group1", "group2"};
|
||||
configureOwnerGroups("*", Lists.newArrayList(ownerGroups));
|
||||
assertThat(repoCfg.getOwnerGroups(new NameKey("someProject"))).isEqualTo(
|
||||
ownerGroups);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOwnerGroupsForSpecificFilter() {
|
||||
String[] ownerGroups = new String[] {"group1", "group2"};
|
||||
configureOwnerGroups("someProject", Lists.newArrayList(ownerGroups));
|
||||
assertThat(repoCfg.getOwnerGroups(new NameKey("someOtherProject")))
|
||||
.isEqualTo(new String[] {});
|
||||
assertThat(repoCfg.getOwnerGroups(new NameKey("someProject"))).isEqualTo(
|
||||
ownerGroups);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOwnerGroupsForStartWithFilter() {
|
||||
String[] ownerGroups1 = new String[] {"group1"};
|
||||
String[] ownerGroups2 = new String[] {"group2"};
|
||||
String[] ownerGroups3 = new String[] {"group3"};
|
||||
|
||||
configureOwnerGroups("*", Lists.newArrayList(ownerGroups1));
|
||||
configureOwnerGroups("somePath/*", Lists.newArrayList(ownerGroups2));
|
||||
configureOwnerGroups("somePath/somePath/*",
|
||||
Lists.newArrayList(ownerGroups3));
|
||||
|
||||
assertThat(repoCfg.getOwnerGroups(new NameKey("someProject"))).isEqualTo(
|
||||
ownerGroups1);
|
||||
|
||||
assertThat(repoCfg.getOwnerGroups(new NameKey("somePath/someProject")))
|
||||
.isEqualTo(ownerGroups2);
|
||||
|
||||
assertThat(
|
||||
repoCfg.getOwnerGroups(new NameKey("somePath/somePath/someProject")))
|
||||
.isEqualTo(ownerGroups3);
|
||||
}
|
||||
|
||||
private void configureOwnerGroups(String projectFilter,
|
||||
List<String> ownerGroups) {
|
||||
cfg.setStringList(RepositoryConfig.SECTION_NAME, projectFilter,
|
||||
RepositoryConfig.OWNER_GROUP_NAME, ownerGroups);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user