Add support for parent revisions weblinks provided by plugins

Support for parent weblinks was removed in change I8508dcaf3. This is a
regression for some users who rely on that information being present.

On the other hand, not all users want to have these links going to the
same external service as the patch set revision links, so we can't just
add it back as it was.

Instead, add a new plugin web link interface for the parent revisions.

If a plugin provides an implementation of ParentWebLink, the links will
be displayed beside the parent revisions on the change screen.

For the built-in gitweb support, provide the parent links using the same
template as the patch set links, so they will always appear when the
gitweb config defines the 'revision' setting.

Bug: Issue 4908
Change-Id: Icdf0f997f939128717ee4edc2c147a26eeaebad6
(cherry picked from commit 58b8d76204)
This commit is contained in:
David Pursehouse
2016-12-09 11:12:27 +09:00
parent 8f83bbbb27
commit 1aedee62ae
8 changed files with 103 additions and 5 deletions

View File

@@ -2106,6 +2106,12 @@ public class MyWeblinkPlugin implements PatchSetWebLink {
}
----
ParentWebLinks will appear to the right of the SHA1 of the parent
revisions in the UI. The implementation should in most use cases direct
to the same external service as PatchSetWebLink; it is provided as a
separate interface because not all users want to have links for the
parent revisions.
FileWebLinks will appear in the side-by-side diff screen on the right
side of the patch selection on each side.

View File

@@ -0,0 +1,38 @@
// Copyright (C) 2016 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.webui;
import com.google.gerrit.extensions.annotations.ExtensionPoint;
import com.google.gerrit.extensions.common.WebLinkInfo;
@ExtensionPoint
public interface ParentWebLink extends WebLink {
/**
* {@link com.google.gerrit.extensions.common.WebLinkInfo}
* describing a link from a parent revision to an external service.
*
* <p>In order for the web link to be visible
* {@link com.google.gerrit.extensions.common.WebLinkInfo#url}
* and {@link com.google.gerrit.extensions.common.WebLinkInfo#name}
* must be set.<p>
*
* @param projectName Name of the project
* @param commit Commit sha1 of the parent revision
* @return WebLinkInfo that links to parent commit in external service,
* null if there should be no link.
*/
WebLinkInfo getParentWebLink(String projectName, String commit);
}

View File

@@ -55,6 +55,7 @@ class CommitBox extends Composite {
String collapsed();
String expanded();
String clippy();
String parentWebLink();
}
@UiField Style style;
@@ -65,6 +66,7 @@ class CommitBox extends Composite {
@UiField FlowPanel webLinkPanel;
@UiField TableRowElement firstParent;
@UiField FlowPanel parentCommits;
@UiField FlowPanel parentWebLinks;
@UiField InlineHyperlink authorNameEmail;
@UiField Element authorDate;
@UiField InlineHyperlink committerNameEmail;
@@ -113,7 +115,7 @@ class CommitBox extends Composite {
committerDate, change);
text.setHTML(commentLinkProcessor.apply(
new SafeHtmlBuilder().append(commit.message()).linkify()));
setWebLinks(revInfo);
setWebLinks(webLinkPanel, revInfo.commit());
if (revInfo.commit().parents().length() > 1) {
mergeCommit.setVisible(true);
@@ -128,11 +130,11 @@ class CommitBox extends Composite {
parentNotCurrentText.setInnerText(parentNotCurrent ? "\u25CF" : "");
}
private void setWebLinks(RevisionInfo revInfo) {
JsArray<WebLinkInfo> links = revInfo.commit().webLinks();
private void setWebLinks(FlowPanel panel, CommitInfo commit) {
JsArray<WebLinkInfo> links = commit.webLinks();
if (links != null) {
for (WebLinkInfo link : Natives.asList(links)) {
webLinkPanel.add(link.toAnchor());
panel.add(link.toAnchor());
}
}
}
@@ -145,11 +147,18 @@ class CommitBox extends Composite {
if (next == firstParent) {
CopyableLabel copyLabel = getCommitLabel(c);
parentCommits.add(copyLabel);
setWebLinks(parentWebLinks, c);
} else {
next.appendChild(DOM.createTD());
Element td1 = DOM.createTD();
td1.appendChild(getCommitLabel(c).getElement());
next.appendChild(td1);
FlowPanel linksPanel = new FlowPanel();
linksPanel.addStyleName(style.parentWebLink());
setWebLinks(linksPanel, c);
Element td2 = DOM.createTD();
td2.appendChild(linksPanel.getElement());
next.appendChild(td2);
previous.getParentElement().insertAfter(next, previous);
}
previous = next;

View File

@@ -88,6 +88,13 @@ limitations under the License.
margin-left:2px;
}
.parentWebLink a:first-child {
margin-left:16px;
}
.parentWebLink>a {
margin-left:2px;
}
.commit {
margin-right: 3px;
float: left;
@@ -178,6 +185,9 @@ limitations under the License.
<td>
<g:FlowPanel ui:field='parentCommits'/>
</td>
<td>
<g:FlowPanel ui:field='parentWebLinks' styleName='{style.parentWebLink}'/>
</td>
</tr>
<tr>
<th><ui:msg>Change-Id</ui:msg></th>

View File

@@ -26,6 +26,7 @@ import com.google.gerrit.extensions.webui.BranchWebLink;
import com.google.gerrit.extensions.webui.DiffWebLink;
import com.google.gerrit.extensions.webui.FileHistoryWebLink;
import com.google.gerrit.extensions.webui.FileWebLink;
import com.google.gerrit.extensions.webui.ParentWebLink;
import com.google.gerrit.extensions.webui.PatchSetWebLink;
import com.google.gerrit.extensions.webui.ProjectWebLink;
import com.google.gerrit.extensions.webui.WebLink;
@@ -73,6 +74,7 @@ public class WebLinks {
};
private final DynamicSet<PatchSetWebLink> patchSetLinks;
private final DynamicSet<ParentWebLink> parentLinks;
private final DynamicSet<FileWebLink> fileLinks;
private final DynamicSet<FileHistoryWebLink> fileHistoryLinks;
private final DynamicSet<DiffWebLink> diffLinks;
@@ -81,6 +83,7 @@ public class WebLinks {
@Inject
public WebLinks(DynamicSet<PatchSetWebLink> patchSetLinks,
DynamicSet<ParentWebLink> parentLinks,
DynamicSet<FileWebLink> fileLinks,
DynamicSet<FileHistoryWebLink> fileLogLinks,
DynamicSet<DiffWebLink> diffLinks,
@@ -88,6 +91,7 @@ public class WebLinks {
DynamicSet<BranchWebLink> branchLinks
) {
this.patchSetLinks = patchSetLinks;
this.parentLinks = parentLinks;
this.fileLinks = fileLinks;
this.fileHistoryLinks = fileLogLinks;
this.diffLinks = diffLinks;
@@ -112,6 +116,22 @@ public class WebLinks {
});
}
/**
* @param project Project name.
* @param revision SHA1 of the parent revision.
* @return Links for patch sets.
*/
public FluentIterable<WebLinkInfo> getParentLinks(final Project.NameKey project,
final String revision) {
return filterLinks(parentLinks, new Function<WebLink, WebLinkInfo>() {
@Override
public WebLinkInfo apply(WebLink webLink) {
return ((ParentWebLink)webLink).getParentWebLink(project.get(), revision);
}
});
}
/**
*
* @param project Project name.

View File

@@ -1069,6 +1069,11 @@ public class ChangeJson {
CommitInfo i = new CommitInfo();
i.commit = parent.name();
i.subject = parent.getShortMessage();
if (addLinks) {
FluentIterable<WebLinkInfo> parentLinks =
webLinks.getParentLinks(project, parent.name());
i.webLinks = parentLinks.isEmpty() ? null : parentLinks.toList();
}
info.parents.add(i);
}
return info;

View File

@@ -59,6 +59,7 @@ import com.google.gerrit.extensions.webui.BranchWebLink;
import com.google.gerrit.extensions.webui.DiffWebLink;
import com.google.gerrit.extensions.webui.FileHistoryWebLink;
import com.google.gerrit.extensions.webui.FileWebLink;
import com.google.gerrit.extensions.webui.ParentWebLink;
import com.google.gerrit.extensions.webui.PatchSetWebLink;
import com.google.gerrit.extensions.webui.ProjectWebLink;
import com.google.gerrit.extensions.webui.TopMenu;
@@ -347,6 +348,7 @@ public class GerritGlobalModule extends FactoryModule {
DynamicSet.setOf(binder(), ExternalIncludedIn.class);
DynamicMap.mapOf(binder(), ProjectConfigEntry.class);
DynamicSet.setOf(binder(), PatchSetWebLink.class);
DynamicSet.setOf(binder(), ParentWebLink.class);
DynamicSet.setOf(binder(), FileWebLink.class);
DynamicSet.setOf(binder(), FileHistoryWebLink.class);
DynamicSet.setOf(binder(), DiffWebLink.class);

View File

@@ -27,6 +27,7 @@ import com.google.gerrit.extensions.restapi.Url;
import com.google.gerrit.extensions.webui.BranchWebLink;
import com.google.gerrit.extensions.webui.FileHistoryWebLink;
import com.google.gerrit.extensions.webui.FileWebLink;
import com.google.gerrit.extensions.webui.ParentWebLink;
import com.google.gerrit.extensions.webui.PatchSetWebLink;
import com.google.gerrit.extensions.webui.ProjectWebLink;
import com.google.inject.AbstractModule;
@@ -74,6 +75,7 @@ public class GitwebConfig {
if (!isNullOrEmpty(type.getRevision())) {
DynamicSet.bind(binder(), PatchSetWebLink.class).to(GitwebLinks.class);
DynamicSet.bind(binder(), ParentWebLink.class).to(GitwebLinks.class);
}
if (!isNullOrEmpty(type.getProject())) {
@@ -240,7 +242,7 @@ public class GitwebConfig {
@Singleton
static class GitwebLinks implements BranchWebLink, FileHistoryWebLink,
FileWebLink, PatchSetWebLink, ProjectWebLink {
FileWebLink, PatchSetWebLink, ParentWebLink, ProjectWebLink {
private final String url;
private final GitwebType type;
private final ParameterizedString branch;
@@ -310,6 +312,12 @@ public class GitwebConfig {
return null;
}
@Override
public WebLinkInfo getParentWebLink(String projectName, String commit) {
// For Gitweb treat parent revision links the same as patch set links
return getPatchSetWebLink(projectName, commit);
}
@Override
public WebLinkInfo getProjectWeblink(String projectName) {
if (project != null) {