Allow to configure a default ref for loading the documentation
So far if a revision was not specified, the documentation was always
loaded from the branch to which HEAD points. Now a new configuration
parameter allows to configure the default ref from which the
documentation is loaded. E.g. it could be set to 'master' or to a tag
that marks the latest release 'refs/tags/v2.9.1'
Change-Id: I6a22e6de5d2593e87971012d6514b28f1af35aad
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
diff --git a/src/main/java/com/googlesource/gerrit/plugins/xdocs/XDocProjectConfig.java b/src/main/java/com/googlesource/gerrit/plugins/xdocs/XDocProjectConfig.java
index f3c931a..eb45cd7 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/xdocs/XDocProjectConfig.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/xdocs/XDocProjectConfig.java
@@ -22,6 +22,7 @@
import com.google.inject.assistedinject.Assisted;
import org.eclipse.jgit.lib.Config;
+import org.eclipse.jgit.lib.Constants;
public class XDocProjectConfig {
interface Factory {
@@ -29,6 +30,7 @@
}
private static final String SECTION_WEB = "web";
+ private static final String KEY_INDEX_REF = "indexRef";
private static final String KEY_INDEX_FILE = "indexFile";
private static final String DEFAULT_INDEX_FILE = "README.md";
@@ -40,6 +42,12 @@
this.cfg = cfgFactory.getProjectPluginConfigWithInheritance(project, pluginName);
}
+ String getIndexRef() {
+ return MoreObjects.firstNonNull(
+ cfg.getString(SECTION_WEB, null, KEY_INDEX_REF),
+ Constants.HEAD);
+ }
+
String getIndexFile() {
return MoreObjects.firstNonNull(
cfg.getString(SECTION_WEB, null, KEY_INDEX_FILE),
diff --git a/src/main/java/com/googlesource/gerrit/plugins/xdocs/XDocServlet.java b/src/main/java/com/googlesource/gerrit/plugins/xdocs/XDocServlet.java
index eea1cf6..f557bee 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/xdocs/XDocServlet.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/xdocs/XDocServlet.java
@@ -141,7 +141,10 @@
try {
ProjectControl projectControl = projectControlFactory.validateFor(key.project);
String rev = key.revision;
- if (rev == null || Constants.HEAD.equals(rev)) {
+ if (rev == null) {
+ rev = cfg.getIndexRef();
+ }
+ if (Constants.HEAD.equals(rev)) {
rev = getHead.get().apply(new ProjectResource(projectControl));
} else {
if (!ObjectId.isId(rev)) {
diff --git a/src/main/resources/Documentation/config.md b/src/main/resources/Documentation/config.md
index aef00c5..0a3f97e 100644
--- a/src/main/resources/Documentation/config.md
+++ b/src/main/resources/Documentation/config.md
@@ -11,9 +11,25 @@
```
[web]
+ indexRef = master
indexFile = Documentation/README.md
```
+<a id="webIndexRef">
+web.indexRef
+: The reference from which the documentation should be loaded if a
+ revision is not specified.
+
+ The documentation links in the project list will link to the index
+ file in this reference.
+
+ For branches the `refs/heads/` prefix may be omitted, all other
+ refs must be fully specified.
+
+ Inherited from the parent project if not specified.
+
+ Default: `HEAD`
+
<a id="webIndexFile">
web.indexFile
: The documentation file that serves as entry point for the project