Merge changes Ib28802d3,If54a64ad,I833e9c2b,I0ecdda81,Ib654accc * changes: Distinguish btw. messages that can be shown to all users vs. admins only CodeOwnerResolverTest: Drop msg that is optionally expected but never occurs CheckCodeOwner: Return whether parent/folder owners are ignored CheckedCodeOwnerConfigFileInfoSubject: Drop 'assert' method prefix CheckCodeOwner: Replace 'code_owner_config_file_paths' field
diff --git a/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerScorings.java b/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerScorings.java index 7a283cd..8c80fc0 100644 --- a/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerScorings.java +++ b/java/com/google/gerrit/plugins/codeowners/backend/CodeOwnerScorings.java
@@ -17,11 +17,8 @@ import static com.google.common.collect.ImmutableMap.toImmutableMap; import com.google.auto.value.AutoValue; -import com.google.common.collect.ImmutableCollection; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import java.util.HashMap; -import java.util.Map; import java.util.Set; import java.util.function.Function; import java.util.stream.Collectors; @@ -68,8 +65,7 @@ public ImmutableMap<CodeOwnerScore, Integer> getScoringsByScore(CodeOwner codeOwner) { ImmutableMap.Builder<CodeOwnerScore, Integer> builder = ImmutableMap.builder(); for (CodeOwnerScoring scoring : scorings()) { - scoring.bestValue(codeOwner) - .ifPresent(value -> builder.put(scoring.score(), value)); + scoring.bestValue(codeOwner).ifPresent(value -> builder.put(scoring.score(), value)); } return builder.build(); }
diff --git a/java/com/google/gerrit/plugins/codeowners/restapi/CodeOwnerJson.java b/java/com/google/gerrit/plugins/codeowners/restapi/CodeOwnerJson.java index 7739500..09f7bbe 100644 --- a/java/com/google/gerrit/plugins/codeowners/restapi/CodeOwnerJson.java +++ b/java/com/google/gerrit/plugins/codeowners/restapi/CodeOwnerJson.java
@@ -87,14 +87,17 @@ * @param scorings the scorings data that should be populated in {@link CodeOwnerInfo}s * @return the provided code owner as {@link CodeOwnerInfo} */ - private static CodeOwnerInfo format(AccountLoader accountLoader, CodeOwner codeOwner, + private static CodeOwnerInfo format( + AccountLoader accountLoader, + CodeOwner codeOwner, ImmutableMap<CodeOwnerScore, Integer> scorings) { CodeOwnerInfo info = new CodeOwnerInfo(); info.account = accountLoader.get(requireNonNull(codeOwner, "codeOwner").accountId()); if (scorings != null) { - info.scorings = scorings.entrySet().stream() - .map(e -> Pair.of(e.getKey().name(), e.getValue())) - .collect(toImmutableMap(Pair::key, Pair::value)); + info.scorings = + scorings.entrySet().stream() + .map(e -> Pair.of(e.getKey().name(), e.getValue())) + .collect(toImmutableMap(Pair::key, Pair::value)); } return info; }
diff --git a/java/com/google/gerrit/plugins/codeowners/testing/CodeOwnerInfoSubject.java b/java/com/google/gerrit/plugins/codeowners/testing/CodeOwnerInfoSubject.java index de3d37a..7e858c6 100644 --- a/java/com/google/gerrit/plugins/codeowners/testing/CodeOwnerInfoSubject.java +++ b/java/com/google/gerrit/plugins/codeowners/testing/CodeOwnerInfoSubject.java
@@ -44,11 +44,12 @@ /** Constructs a {@link Correspondence} that maps {@link CodeOwnerInfo}s to scoring. */ public static final Correspondence<CodeOwnerInfo, Integer> hasScoring(CodeOwnerScore score) { return NullAwareCorrespondence.transforming( - codeOwnerInfo -> codeOwnerInfo.scorings.entrySet().stream() - .filter(factor -> factor.getKey().equals(score.name())) - .findFirst() - .orElseThrow() - .getValue(), + codeOwnerInfo -> + codeOwnerInfo.scorings.entrySet().stream() + .filter(factor -> factor.getKey().equals(score.name())) + .findFirst() + .orElseThrow() + .getValue(), "has scoring"); }
diff --git a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/AbstractGetCodeOwnersForPathIT.java b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/AbstractGetCodeOwnersForPathIT.java index a9c96a8..5cc69d3 100644 --- a/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/AbstractGetCodeOwnersForPathIT.java +++ b/javatests/com/google/gerrit/plugins/codeowners/acceptance/api/AbstractGetCodeOwnersForPathIT.java
@@ -391,8 +391,8 @@ @Test public void - cannotGetCodeOwnersWithSecondaryEmailsWithoutViewSecondaryEmailAndWithoutModifyAccountCapability() - throws Exception { + cannotGetCodeOwnersWithSecondaryEmailsWithoutViewSecondaryEmailAndWithoutModifyAccountCapability() + throws Exception { // create a code owner config codeOwnerConfigOperations .newCodeOwnerConfig() @@ -1421,9 +1421,9 @@ .collect(toList()); for (int i = 0; i < 10; i++) { assertThat( - queryCodeOwners( - getCodeOwnersApi().query().setResolveAllUsers(true).withSeed(seed), - "/foo/bar/baz.md")) + queryCodeOwners( + getCodeOwnersApi().query().setResolveAllUsers(true).withSeed(seed), + "/foo/bar/baz.md")) .hasCodeOwnersThat() .comparingElementsUsing(hasAccountId()) .containsExactlyElementsIn(expectedAccountIds) @@ -1988,7 +1988,6 @@ .assertNoUnresolvedErrorMessage(); } - @Test public void testCodeOwnersScoringsDistance() throws Exception { TestAccount user2 = accountCreator.user2(); @@ -2017,8 +2016,7 @@ .addCodeOwnerEmail(user2.email()) .create(); - CodeOwnersInfo codeOwnersInfo = - queryCodeOwners("/foo/bar/baz.md"); + CodeOwnersInfo codeOwnersInfo = queryCodeOwners("/foo/bar/baz.md"); assertThat(codeOwnersInfo) .hasCodeOwnersThat() .comparingElementsUsing(hasAccountId()) @@ -2035,7 +2033,6 @@ .inOrder(); } - @Test @GerritConfig(name = "accounts.visibility", value = "ALL") public void testCodeOwnersScoringsIsExplicitlyMentioned() throws Exception {
diff --git a/javatests/com/google/gerrit/plugins/codeowners/restapi/CodeOwnerJsonTest.java b/javatests/com/google/gerrit/plugins/codeowners/restapi/CodeOwnerJsonTest.java index 498ff09..5c01956 100644 --- a/javatests/com/google/gerrit/plugins/codeowners/restapi/CodeOwnerJsonTest.java +++ b/javatests/com/google/gerrit/plugins/codeowners/restapi/CodeOwnerJsonTest.java
@@ -51,8 +51,10 @@ @Test public void formatEmptyListOfCodeOwners() throws Exception { - assertThat(codeOwnerJsonFactory.create(EnumSet.of(FillOptions.ID)) - .format(ImmutableList.of(), ImmutableMap.of())) + assertThat( + codeOwnerJsonFactory + .create(EnumSet.of(FillOptions.ID)) + .format(ImmutableList.of(), ImmutableMap.of())) .isEmpty(); } @@ -61,7 +63,9 @@ ImmutableList<CodeOwnerInfo> codeOwnerInfos = codeOwnerJsonFactory .create(EnumSet.of(FillOptions.ID)) - .format(ImmutableList.of(CodeOwner.create(admin.id()), CodeOwner.create(user.id())), ImmutableMap.of()); + .format( + ImmutableList.of(CodeOwner.create(admin.id()), CodeOwner.create(user.id())), + ImmutableMap.of()); assertThat(codeOwnerInfos) .comparingElementsUsing(hasAccountId()) .containsExactly(admin.id(), user.id()) @@ -74,7 +78,9 @@ ImmutableList<CodeOwnerInfo> codeOwnerInfos = codeOwnerJsonFactory .create(EnumSet.of(FillOptions.ID, FillOptions.NAME)) - .format(ImmutableList.of(CodeOwner.create(admin.id()), CodeOwner.create(user.id())), ImmutableMap.of()); + .format( + ImmutableList.of(CodeOwner.create(admin.id()), CodeOwner.create(user.id())), + ImmutableMap.of()); assertThat(codeOwnerInfos) .comparingElementsUsing(hasAccountId()) .containsExactly(admin.id(), user.id()) @@ -85,7 +91,6 @@ .inOrder(); } - @Test public void formatCodeOwnersWithAccountIdAndScorings() throws Exception { CodeOwner adminCodeOwner = CodeOwner.create(admin.id()); @@ -101,8 +106,7 @@ ImmutableList<CodeOwnerInfo> codeOwnerInfos = codeOwnerJsonFactory .create(EnumSet.of(FillOptions.ID)) - .format(ImmutableList.of(adminCodeOwner, userCodeOwner), - scorings); + .format(ImmutableList.of(adminCodeOwner, userCodeOwner), scorings); assertThat(codeOwnerInfos) .comparingElementsUsing(hasAccountId()) .containsExactly(admin.id(), user.id())