Merge changes I650bb201,I7b194b79,Icb452f10
* changes:
Use method from AbstractDaemonTest to create branches
AbstractCodeOwnersTest: Add method to enable the code owners functionality
CheckCodeOwnerConfigFilesIT: Test that non-visible branches are omitted
diff --git a/java/com/google/gerrit/plugins/codeowners/acceptance/AbstractCodeOwnersTest.java b/java/com/google/gerrit/plugins/codeowners/acceptance/AbstractCodeOwnersTest.java
index a3dfde6..e8873e4 100644
--- a/java/com/google/gerrit/plugins/codeowners/acceptance/AbstractCodeOwnersTest.java
+++ b/java/com/google/gerrit/plugins/codeowners/acceptance/AbstractCodeOwnersTest.java
@@ -137,6 +137,10 @@
setCodeOwnersConfig(project, null, StatusConfig.KEY_DISABLED, "true");
}
+ protected void enableCodeOwnersForProject(Project.NameKey project) throws Exception {
+ setCodeOwnersConfig(project, null, StatusConfig.KEY_DISABLED, "false");
+ }
+
protected void setCodeOwnersConfig(
Project.NameKey project, String subsection, String key, String value) throws Exception {
Config codeOwnersConfig = new Config();
diff --git a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CheckCodeOwnerConfigFilesIT.java b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CheckCodeOwnerConfigFilesIT.java
index a0f3384..b163b1f 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CheckCodeOwnerConfigFilesIT.java
+++ b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CheckCodeOwnerConfigFilesIT.java
@@ -25,10 +25,11 @@
import com.google.gerrit.acceptance.config.GerritConfig;
import com.google.gerrit.acceptance.testsuite.project.ProjectOperations;
import com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations;
+import com.google.gerrit.entities.BranchNameKey;
import com.google.gerrit.entities.Permission;
import com.google.gerrit.entities.Project;
+import com.google.gerrit.entities.RefNames;
import com.google.gerrit.extensions.api.config.ConsistencyCheckInfo.ConsistencyProblemInfo;
-import com.google.gerrit.extensions.api.projects.BranchInput;
import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.BadRequestException;
import com.google.gerrit.extensions.restapi.RestApiException;
@@ -86,6 +87,22 @@
}
@Test
+ public void nonVisibleBranchesAreSkipped() throws Exception {
+ String branchName = "non-visible";
+ createBranch(BranchNameKey.create(project, branchName));
+
+ projectOperations
+ .project(project)
+ .forUpdate()
+ .add(block(Permission.READ).ref(RefNames.fullName(branchName)).group(REGISTERED_USERS))
+ .update();
+
+ assertThat(checkCodeOwnerConfigFilesIn(project))
+ .containsExactly(
+ "refs/heads/master", ImmutableMap.of(), "refs/meta/config", ImmutableMap.of());
+ }
+
+ @Test
@GerritConfig(name = "plugin.code-owners.disabledBranch", value = "refs/meta/config")
public void disabledBranchesAreSkipped() throws Exception {
assertThat(checkCodeOwnerConfigFilesIn(project))
@@ -219,8 +236,8 @@
@Test
public void validateSpecifiedBranches() throws Exception {
- gApi.projects().name(project.get()).branch("stable-1.0").create(new BranchInput());
- gApi.projects().name(project.get()).branch("stable-1.1").create(new BranchInput());
+ createBranch(BranchNameKey.create(project, "stable-1.0"));
+ createBranch(BranchNameKey.create(project, "stable-1.1"));
assertThat(
projectCodeOwnersApiFactory
@@ -235,8 +252,8 @@
@Test
public void validateSpecifiedBranches_shortNames() throws Exception {
- gApi.projects().name(project.get()).branch("stable-1.0").create(new BranchInput());
- gApi.projects().name(project.get()).branch("stable-1.1").create(new BranchInput());
+ createBranch(BranchNameKey.create(project, "stable-1.0"));
+ createBranch(BranchNameKey.create(project, "stable-1.1"));
assertThat(
projectCodeOwnersApiFactory
diff --git a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CodeOwnerConfigValidatorIT.java b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CodeOwnerConfigValidatorIT.java
index 6f3374b..dcc6464 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CodeOwnerConfigValidatorIT.java
+++ b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/CodeOwnerConfigValidatorIT.java
@@ -27,9 +27,9 @@
import com.google.gerrit.acceptance.config.GerritConfig;
import com.google.gerrit.acceptance.testsuite.project.ProjectOperations;
import com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations;
+import com.google.gerrit.entities.BranchNameKey;
import com.google.gerrit.entities.Permission;
import com.google.gerrit.entities.Project;
-import com.google.gerrit.extensions.api.projects.BranchInput;
import com.google.gerrit.extensions.api.projects.ConfigInput;
import com.google.gerrit.extensions.client.ChangeStatus;
import com.google.gerrit.extensions.client.ProjectState;
@@ -50,7 +50,6 @@
import com.google.gerrit.plugins.codeowners.backend.proto.ProtoBackend;
import com.google.gerrit.plugins.codeowners.backend.proto.ProtoCodeOwnerConfigParser;
import com.google.gerrit.plugins.codeowners.config.BackendConfig;
-import com.google.gerrit.plugins.codeowners.config.StatusConfig;
import com.google.inject.Inject;
import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.ObjectId;
@@ -343,7 +342,7 @@
r.assertOkStatus();
// re-enable the code owners functionality for the project
- setCodeOwnersConfig(project, null, StatusConfig.KEY_DISABLED, "false");
+ enableCodeOwnersForProject(project);
// delete the invalid code owner config file
PushOneCommit push =
@@ -369,7 +368,7 @@
r.assertOkStatus();
// re-enable the code owners functionality for the project
- setCodeOwnersConfig(project, null, StatusConfig.KEY_DISABLED, "false");
+ enableCodeOwnersForProject(project);
// update the code owner config so that it is still not parseable
r =
@@ -408,7 +407,7 @@
r.assertOkStatus();
// re-enable the code owners functionality for the project
- setCodeOwnersConfig(project, null, StatusConfig.KEY_DISABLED, "false");
+ enableCodeOwnersForProject(project);
// update the code owner config so that it is parseable now, but has validation issues
String unknownEmail1 = "non-existing-email@example.com";
@@ -459,7 +458,7 @@
r.assertOkStatus();
// re-enable the code owners functionality for the project
- setCodeOwnersConfig(project, null, StatusConfig.KEY_DISABLED, "false");
+ enableCodeOwnersForProject(project);
// update the code owner config so that the validation issue still exists, but no new issue is
// introduced
@@ -621,7 +620,7 @@
r.assertOkStatus();
// re-enable the code owners functionality for the project
- setCodeOwnersConfig(project, null, StatusConfig.KEY_DISABLED, "false");
+ enableCodeOwnersForProject(project);
// update the code owner config so that the validation issue still exists and a new issue is
// introduced
@@ -682,7 +681,7 @@
r.assertOkStatus();
// re-enable the code owners functionality for the project
- setCodeOwnersConfig(project, null, StatusConfig.KEY_DISABLED, "false");
+ enableCodeOwnersForProject(project);
// approve the change
approve(r.getChangeId());
@@ -733,7 +732,7 @@
r.assertOkStatus();
// re-enable the code owners functionality for the project
- setCodeOwnersConfig(project, null, StatusConfig.KEY_DISABLED, "false");
+ enableCodeOwnersForProject(project);
// approve the change
approve(r.getChangeId());
@@ -1181,7 +1180,7 @@
gApi.changes().id(r.getChangeId()).current().submit();
// re-enable the code owners functionality for the project
- setCodeOwnersConfig(project, null, StatusConfig.KEY_DISABLED, "false");
+ enableCodeOwnersForProject(project);
// create a code owner config that imports a non-parseable code owner config
CodeOwnerConfig.Key keyOfImportingCodeOwnerConfig = createCodeOwnerConfigKey("/");
@@ -1214,7 +1213,7 @@
public void validateMergeCommitCreatedViaTheCreateChangeRestApi() throws Exception {
// Create another branch.
String branchName = "stable";
- gApi.projects().name(project.get()).branch(branchName).create(new BranchInput());
+ createBranch(BranchNameKey.create(project, branchName));
// Create a code owner config file in the other branch.
codeOwnerConfigOperations
diff --git a/javatests/com/google/gerrit/plugins/codeowners/acceptance/testsuite/CodeOwnerConfigOperationsImplTest.java b/javatests/com/google/gerrit/plugins/codeowners/acceptance/testsuite/CodeOwnerConfigOperationsImplTest.java
index 7718b5d..d872186 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/acceptance/testsuite/CodeOwnerConfigOperationsImplTest.java
+++ b/javatests/com/google/gerrit/plugins/codeowners/acceptance/testsuite/CodeOwnerConfigOperationsImplTest.java
@@ -22,8 +22,8 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.truth.Truth8;
+import com.google.gerrit.entities.BranchNameKey;
import com.google.gerrit.entities.RefNames;
-import com.google.gerrit.extensions.api.projects.BranchInput;
import com.google.gerrit.plugins.codeowners.acceptance.AbstractCodeOwnersTest;
import com.google.gerrit.plugins.codeowners.acceptance.testsuite.CodeOwnerConfigOperations.PerCodeOwnerConfigOperations;
import com.google.gerrit.plugins.codeowners.backend.CodeOwnerConfig;
@@ -113,7 +113,7 @@
@Test
public void specifiedBranchIsRespectedForCodeOwnerConfigCreation() throws Exception {
String branchName = "foo";
- gApi.projects().name(project.get()).branch(branchName).create(new BranchInput());
+ createBranch(BranchNameKey.create(project, branchName));
CodeOwnerConfig.Key codeOwnerConfigKey =
codeOwnerConfigOperations
diff --git a/javatests/com/google/gerrit/plugins/codeowners/backend/CodeOwnerConfigScannerTest.java b/javatests/com/google/gerrit/plugins/codeowners/backend/CodeOwnerConfigScannerTest.java
index 14bf652..06be307 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/backend/CodeOwnerConfigScannerTest.java
+++ b/javatests/com/google/gerrit/plugins/codeowners/backend/CodeOwnerConfigScannerTest.java
@@ -27,7 +27,6 @@
import com.google.gerrit.plugins.codeowners.JgitPath;
import com.google.gerrit.plugins.codeowners.acceptance.AbstractCodeOwnersTest;
import com.google.gerrit.plugins.codeowners.acceptance.testsuite.CodeOwnerConfigOperations;
-import com.google.gerrit.plugins.codeowners.config.StatusConfig;
import java.nio.file.Paths;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.junit.TestRepository;
@@ -438,6 +437,6 @@
.getChangeId();
approve(changeId);
gApi.changes().id(changeId).current().submit();
- setCodeOwnersConfig(project, null, StatusConfig.KEY_DISABLED, "false");
+ enableCodeOwnersForProject(project);
}
}
diff --git a/javatests/com/google/gerrit/plugins/codeowners/backend/PathCodeOwnersTest.java b/javatests/com/google/gerrit/plugins/codeowners/backend/PathCodeOwnersTest.java
index 27d7202..e5d06ac 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/backend/PathCodeOwnersTest.java
+++ b/javatests/com/google/gerrit/plugins/codeowners/backend/PathCodeOwnersTest.java
@@ -31,7 +31,6 @@
import com.google.gerrit.entities.BranchNameKey;
import com.google.gerrit.entities.Project;
import com.google.gerrit.entities.Project.NameKey;
-import com.google.gerrit.extensions.api.projects.BranchInput;
import com.google.gerrit.extensions.api.projects.ConfigInput;
import com.google.gerrit.extensions.client.ProjectState;
import com.google.gerrit.extensions.registration.DynamicMap;
@@ -1302,14 +1301,10 @@
// Create other branches in project.
String branchName = "foo";
- BranchInput branchInput = new BranchInput();
- branchInput.ref = branchName;
- branchInput.revision = projectOperations.project(project).getHead("master").name();
- gApi.projects().name(project.get()).branch(branchInput.ref).create(branchInput);
+ createBranch(BranchNameKey.create(project, branchName));
// Create other branches in other project.
- branchInput.revision = projectOperations.project(otherProject).getHead("master").name();
- gApi.projects().name(otherProject.get()).branch(branchInput.ref).create(branchInput);
+ createBranch(BranchNameKey.create(otherProject, branchName));
// create importing config with global code owner and import with relative path
CodeOwnerConfig.Key rootCodeOwnerConfigKey =
@@ -1351,10 +1346,7 @@
public void importFromOtherBranch() throws Exception {
// Create other branch.
String otherBranch = "foo";
- BranchInput branchInput = new BranchInput();
- branchInput.ref = otherBranch;
- branchInput.revision = projectOperations.project(project).getHead("master").name();
- gApi.projects().name(project.get()).branch(branchInput.ref).create(branchInput);
+ createBranch(BranchNameKey.create(project, otherBranch));
// create importing config with global code owner and import with relative path
CodeOwnerConfig.Key rootCodeOwnerConfigKey =
@@ -1399,10 +1391,7 @@
// Create other branch.
String otherBranch = "foo";
- BranchInput branchInput = new BranchInput();
- branchInput.ref = otherBranch;
- branchInput.revision = projectOperations.project(otherProject).getHead("master").name();
- gApi.projects().name(otherProject.get()).branch(branchInput.ref).create(branchInput);
+ createBranch(BranchNameKey.create(otherProject, otherBranch));
// create importing config with global code owner and import with relative path
CodeOwnerConfig.Key rootCodeOwnerConfigKey =
diff --git a/javatests/com/google/gerrit/plugins/codeowners/config/CodeOwnersPluginConfigurationTest.java b/javatests/com/google/gerrit/plugins/codeowners/config/CodeOwnersPluginConfigurationTest.java
index 4ff9123..63ff5d7 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/config/CodeOwnersPluginConfigurationTest.java
+++ b/javatests/com/google/gerrit/plugins/codeowners/config/CodeOwnersPluginConfigurationTest.java
@@ -816,10 +816,6 @@
setCodeOwnersConfig(project, null, StatusConfig.KEY_DISABLED_BRANCH, disabledBranch);
}
- private void enableCodeOwnersForProject(Project.NameKey project) throws Exception {
- setCodeOwnersConfig(project, null, StatusConfig.KEY_DISABLED, "false");
- }
-
private void enableCodeOwnersForAllBranches(Project.NameKey project) throws Exception {
setCodeOwnersConfig(project, null, StatusConfig.KEY_DISABLED_BRANCH, "");
}
diff --git a/javatests/com/google/gerrit/plugins/codeowners/restapi/CodeOwnerProjectConfigJsonTest.java b/javatests/com/google/gerrit/plugins/codeowners/restapi/CodeOwnerProjectConfigJsonTest.java
index 6300a99..704d34d 100644
--- a/javatests/com/google/gerrit/plugins/codeowners/restapi/CodeOwnerProjectConfigJsonTest.java
+++ b/javatests/com/google/gerrit/plugins/codeowners/restapi/CodeOwnerProjectConfigJsonTest.java
@@ -22,7 +22,6 @@
import com.google.gerrit.entities.BranchNameKey;
import com.google.gerrit.entities.LabelType;
-import com.google.gerrit.extensions.api.projects.BranchInput;
import com.google.gerrit.plugins.codeowners.acceptance.AbstractCodeOwnersTest;
import com.google.gerrit.plugins.codeowners.api.BackendInfo;
import com.google.gerrit.plugins.codeowners.api.CodeOwnerProjectConfigInfo;
@@ -92,7 +91,7 @@
@Test
public void formatBackendIds() throws Exception {
- gApi.projects().name(project.get()).branch("stable-2.10").create(new BranchInput());
+ createBranch(BranchNameKey.create(project, "stable-2.10"));
when(codeOwnersPluginConfiguration.getBackend(project)).thenReturn(findOwnersBackend);
when(codeOwnersPluginConfiguration.getBackend(BranchNameKey.create(project, "master")))
@@ -132,7 +131,7 @@
@Test
public void formatCodeOwnerProjectConfig() throws Exception {
createOwnersOverrideLabel();
- gApi.projects().name(project.get()).branch("stable-2.10").create(new BranchInput());
+ createBranch(BranchNameKey.create(project, "stable-2.10"));
when(codeOwnersPluginConfiguration.isDisabled(project)).thenReturn(true);
when(codeOwnersPluginConfiguration.getBackend(project)).thenReturn(findOwnersBackend);