From bc3addc40963c1297382fb11732883d48a6316b2 Mon Sep 17 00:00:00 2001 From: Patrick Hiesel Date: Mon, 2 Dec 2019 17:23:24 +0100 Subject: [PATCH] Expose index.change.mergeable in ServerInfo This commit exposes indexMergeable in ServerInfo to allow the UI to hide the 'is:mergeable' operator conditionally if the Gerrit instance does not support indexing the 'mergeable' bit. Change-Id: I1959244ff0069d0368bbee1fc8a527c3f3b2b0b2 --- Documentation/rest-api-config.txt | 34 +++++++++++++++++++ .../common/ChangeIndexConfigInfo.java | 19 +++++++++++ .../extensions/common/IndexConfigInfo.java | 19 +++++++++++ .../gerrit/extensions/common/ServerInfo.java | 1 + .../server/restapi/config/GetServerInfo.java | 11 ++++++ .../acceptance/rest/config/ServerInfoIT.java | 10 ++++++ 6 files changed, 94 insertions(+) create mode 100644 java/com/google/gerrit/extensions/common/ChangeIndexConfigInfo.java create mode 100644 java/com/google/gerrit/extensions/common/IndexConfigInfo.java diff --git a/Documentation/rest-api-config.txt b/Documentation/rest-api-config.txt index 021a1bb308..affe1ea76f 100644 --- a/Documentation/rest-api-config.txt +++ b/Documentation/rest-api-config.txt @@ -1572,6 +1572,21 @@ configuration parameter] that controls whether the mergeability bit in link:rest-api-changes.html#change-info[ChangeInfo] will never be set. |============================= +[[change-index-config-info]] +=== ChangeIndexConfigInfo +The `ChangeIndexConfigInfo` entity contains information about Gerrit +configuration from the link:config-gerrit.html#index.change[index.change] +section. + +[options="header",cols="1,^1,5"] +|============================= +|Field Name ||Description +|`index_mergeable` |not set if `false`| +Value of the link:config-gerrit.html#index.change.indexMergeable[ +configuration parameter] that controls whether the mergeability bit is +indexed (hence queryable using `is:mergeable`). +|============================= + [[check-account-external-ids-input]] === CheckAccountExternalIdsInput The `CheckAccountExternalIdsInput` entity contains input for the @@ -1821,6 +1836,21 @@ Whether to enable the web UI for editing GPG keys. link:config-gerrit.html#gerrit.reportBugUrl[URL to report bugs]. |================================= +[[index-config-info]] +=== IndexConfigInfo +The `IndexConfigInfo` entity contains information about Gerrit +configuration from the link:config-gerrit.html#index[index] +section. + +[options="header",cols="1,^1,5"] +|============================= +|Field Name ||Description +|`change` || +Information about the configuration from the +link:config-gerrit.html#index.change[index.change] section as +link:#index.change[ChangeIndexConfigInfo] entity. +|============================= + [[hit-ration-info]] === HitRatioInfo The `HitRatioInfo` entity contains information about the hit ratio of a @@ -1947,6 +1977,10 @@ information about Gerrit Information about the configuration from the link:config-gerrit.html#gerrit[gerrit] section as link:#gerrit-info[ GerritInfo] entity. +|`index` || +Information about the configuration from the +link:config-gerrit.html#index[index] section as link:#index[ +IndexConfigInfo] entity. |`note_db_enabled` |not set if `false`| Whether the NoteDb storage backend is fully enabled. |`plugin` || diff --git a/java/com/google/gerrit/extensions/common/ChangeIndexConfigInfo.java b/java/com/google/gerrit/extensions/common/ChangeIndexConfigInfo.java new file mode 100644 index 0000000000..7bca79ee65 --- /dev/null +++ b/java/com/google/gerrit/extensions/common/ChangeIndexConfigInfo.java @@ -0,0 +1,19 @@ +// Copyright (C) 2019 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.extensions.common; + +public class ChangeIndexConfigInfo { + public Boolean indexMergeable; +} diff --git a/java/com/google/gerrit/extensions/common/IndexConfigInfo.java b/java/com/google/gerrit/extensions/common/IndexConfigInfo.java new file mode 100644 index 0000000000..084c53a725 --- /dev/null +++ b/java/com/google/gerrit/extensions/common/IndexConfigInfo.java @@ -0,0 +1,19 @@ +// Copyright (C) 2019 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.extensions.common; + +public class IndexConfigInfo { + public ChangeIndexConfigInfo change; +} diff --git a/java/com/google/gerrit/extensions/common/ServerInfo.java b/java/com/google/gerrit/extensions/common/ServerInfo.java index 82d5bc8061..9cf1ec1e25 100644 --- a/java/com/google/gerrit/extensions/common/ServerInfo.java +++ b/java/com/google/gerrit/extensions/common/ServerInfo.java @@ -20,6 +20,7 @@ public class ServerInfo { public ChangeConfigInfo change; public DownloadInfo download; public GerritInfo gerrit; + public IndexConfigInfo index; public Boolean noteDbEnabled; public PluginConfigInfo plugin; public SshdInfo sshd; diff --git a/java/com/google/gerrit/server/restapi/config/GetServerInfo.java b/java/com/google/gerrit/server/restapi/config/GetServerInfo.java index 2d504c7347..2d4bfe66ac 100644 --- a/java/com/google/gerrit/server/restapi/config/GetServerInfo.java +++ b/java/com/google/gerrit/server/restapi/config/GetServerInfo.java @@ -23,9 +23,11 @@ import com.google.gerrit.common.data.ContributorAgreement; import com.google.gerrit.extensions.common.AccountsInfo; import com.google.gerrit.extensions.common.AuthInfo; import com.google.gerrit.extensions.common.ChangeConfigInfo; +import com.google.gerrit.extensions.common.ChangeIndexConfigInfo; import com.google.gerrit.extensions.common.DownloadInfo; import com.google.gerrit.extensions.common.DownloadSchemeInfo; import com.google.gerrit.extensions.common.GerritInfo; +import com.google.gerrit.extensions.common.IndexConfigInfo; import com.google.gerrit.extensions.common.PluginConfigInfo; import com.google.gerrit.extensions.common.ReceiveInfo; import com.google.gerrit.extensions.common.ServerInfo; @@ -141,6 +143,7 @@ public class GetServerInfo implements RestReadView { info.change = getChangeInfo(); info.download = getDownloadInfo(); info.gerrit = getGerritInfo(); + info.index = getIndexInfo(); info.noteDbEnabled = true; info.plugin = getPluginInfo(); info.defaultTheme = getDefaultTheme(); @@ -296,6 +299,14 @@ public class GetServerInfo implements RestReadView { return info; } + private IndexConfigInfo getIndexInfo() { + ChangeIndexConfigInfo change = new ChangeIndexConfigInfo(); + change.indexMergeable = toBoolean(config.getBoolean("index", "change", "indexMergeable", true)); + IndexConfigInfo index = new IndexConfigInfo(); + index.change = change; + return index; + } + private String getDocUrl() { String docUrl = config.getString("gerrit", null, "docUrl"); if (Strings.isNullOrEmpty(docUrl)) { diff --git a/javatests/com/google/gerrit/acceptance/rest/config/ServerInfoIT.java b/javatests/com/google/gerrit/acceptance/rest/config/ServerInfoIT.java index 996119d922..9573eb0803 100644 --- a/javatests/com/google/gerrit/acceptance/rest/config/ServerInfoIT.java +++ b/javatests/com/google/gerrit/acceptance/rest/config/ServerInfoIT.java @@ -180,6 +180,9 @@ public class ServerInfoIT extends AbstractDaemonTest { assertThat(i.gerrit.allUsers).isEqualTo(AllUsersNameProvider.DEFAULT); assertThat(i.gerrit.reportBugUrl).isNull(); + // index + assertThat(i.index.change.indexMergeable).isNull(); // false in all tests + // plugin assertThat(i.plugin.jsResourcePaths).isEmpty(); @@ -206,4 +209,11 @@ public class ServerInfoIT extends AbstractDaemonTest { ServerInfo i = gApi.config().server().getInfo(); assertThat(i.change.excludeMergeableInChangeInfo).isTrue(); } + + @Test + @GerritConfig(name = "index.change.indexMergeable", value = "true") + public void indexMergeableIsTrueWhenTrueInConfig() throws Exception { + ServerInfo i = gApi.config().server().getInfo(); + assertThat(i.index.change.indexMergeable).isTrue(); + } }