diff options
author | Guy Cassetta <cassetta@google.com> | 2022-03-30 17:39:11 +0000 |
---|---|---|
committer | Guy Cassetta <cassetta@google.com> | 2022-04-11 15:31:45 +0000 |
commit | e0211e5c1766430f069990044d94f925d1b92c3a (patch) | |
tree | 951e8b54b39ab72f4a88ecb8041df0822feb5b80 | |
parent | ad8e19fe3194e2d7116c21885828c9bcc77440aa (diff) |
Update web link interfact to allow passing of the change key
Release-Notes: skip
Change-Id: I58a2db80c264943be428d37b75a244036cb4c30b
5 files changed, 55 insertions, 12 deletions
diff --git a/java/com/google/gerrit/extensions/webui/PatchSetWebLink.java b/java/com/google/gerrit/extensions/webui/PatchSetWebLink.java index 0e8e28e19f..74bccbde51 100644 --- a/java/com/google/gerrit/extensions/webui/PatchSetWebLink.java +++ b/java/com/google/gerrit/extensions/webui/PatchSetWebLink.java @@ -37,6 +37,34 @@ public interface PatchSetWebLink extends WebLink { * @return WebLinkInfo that links to patch set in external service, null if there should be no * link. */ + @Deprecated WebLinkInfo getPatchSetWebLink( String projectName, String commit, String commitMessage, String branchName); + + /** + * {@link com.google.gerrit.extensions.common.WebLinkInfo} describing a link from a patch set 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 of the patch set + * @param commitMessage the commit message of the change + * @param branchName target branch of the change + * @param changeKey the changeID for this change + * @return WebLinkInfo that links to patch set in external service, null if there should be no + * link. + */ + default WebLinkInfo getPatchSetWebLink( + String projectName, + String commit, + String commitMessage, + String branchName, + String changeKey) { + return getPatchSetWebLink(projectName, commit, commitMessage, branchName); + } } diff --git a/java/com/google/gerrit/server/WebLinks.java b/java/com/google/gerrit/server/WebLinks.java index 3a826949dc..dd36066389 100644 --- a/java/com/google/gerrit/server/WebLinks.java +++ b/java/com/google/gerrit/server/WebLinks.java @@ -86,12 +86,19 @@ public class WebLinks { * @param commit SHA1 of commit. * @param commitMessage the commit message of the commit. * @param branchName branch of the commit. + * @param changeKey change Identifier for this change */ public ImmutableList<WebLinkInfo> getPatchSetLinks( - Project.NameKey project, String commit, String commitMessage, String branchName) { + Project.NameKey project, + String commit, + String commitMessage, + String branchName, + String changeKey) { return filterLinks( patchSetLinks, - webLink -> webLink.getPatchSetWebLink(project.get(), commit, commitMessage, branchName)); + webLink -> + webLink.getPatchSetWebLink( + project.get(), commit, commitMessage, branchName, changeKey)); } /** diff --git a/java/com/google/gerrit/server/change/RevisionJson.java b/java/com/google/gerrit/server/change/RevisionJson.java index 0321fcbf1a..7d40f06463 100644 --- a/java/com/google/gerrit/server/change/RevisionJson.java +++ b/java/com/google/gerrit/server/change/RevisionJson.java @@ -168,7 +168,8 @@ public class RevisionJson { RevCommit commit, boolean addLinks, boolean fillCommit, - String branchName) + String branchName, + String changeKey) throws IOException { CommitInfo info = new CommitInfo(); if (fillCommit) { @@ -182,7 +183,8 @@ public class RevisionJson { if (addLinks) { ImmutableList<WebLinkInfo> patchSetLinks = - webLinks.getPatchSetLinks(project, commit.name(), commit.getFullMessage(), branchName); + webLinks.getPatchSetLinks( + project, commit.name(), commit.getFullMessage(), branchName, changeKey); info.webLinks = patchSetLinks.isEmpty() ? null : patchSetLinks; ImmutableList<WebLinkInfo> resolveConflictsLinks = webLinks.getResolveConflictsLinks( @@ -301,7 +303,9 @@ public class RevisionJson { rw.parseBody(commit); String branchName = cd.change().getDest().branch(); if (setCommit) { - out.commit = getCommitInfo(project, rw, commit, has(WEB_LINKS), fillCommit, branchName); + out.commit = + getCommitInfo( + project, rw, commit, has(WEB_LINKS), fillCommit, branchName, c.getKey().get()); } if (addFooters) { Ref ref = repo.exactRef(branchName); diff --git a/java/com/google/gerrit/server/restapi/change/GetCommit.java b/java/com/google/gerrit/server/restapi/change/GetCommit.java index d76ce041f6..5193501979 100644 --- a/java/com/google/gerrit/server/restapi/change/GetCommit.java +++ b/java/com/google/gerrit/server/restapi/change/GetCommit.java @@ -14,6 +14,8 @@ package com.google.gerrit.server.restapi.change; +import static java.util.concurrent.TimeUnit.DAYS; + import com.google.common.collect.ImmutableSet; import com.google.gerrit.entities.Project; import com.google.gerrit.extensions.common.CommitInfo; @@ -25,7 +27,6 @@ import com.google.gerrit.server.change.RevisionResource; import com.google.gerrit.server.git.GitRepositoryManager; import com.google.inject.Inject; import java.io.IOException; -import java.util.concurrent.TimeUnit; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevWalk; @@ -64,10 +65,11 @@ public class GetCommit implements RestReadView<RevisionResource> { commit, addLinks, /* fillCommit= */ true, - rsrc.getChange().getDest().branch()); + rsrc.getChange().getDest().branch(), + rsrc.getChange().getKey().get()); Response<CommitInfo> r = Response.ok(info); if (rsrc.isCacheable()) { - r.caching(CacheControl.PRIVATE(7, TimeUnit.DAYS)); + r.caching(CacheControl.PRIVATE(7, DAYS)); } return r; } diff --git a/java/com/google/gerrit/server/restapi/change/GetMergeList.java b/java/com/google/gerrit/server/restapi/change/GetMergeList.java index f0639b51f8..551b50fa28 100644 --- a/java/com/google/gerrit/server/restapi/change/GetMergeList.java +++ b/java/com/google/gerrit/server/restapi/change/GetMergeList.java @@ -14,6 +14,8 @@ package com.google.gerrit.server.restapi.change; +import static java.util.concurrent.TimeUnit.DAYS; + import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.gerrit.entities.Project; @@ -30,7 +32,6 @@ import com.google.inject.Inject; import java.io.IOException; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.TimeUnit; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevWalk; @@ -77,7 +78,7 @@ public class GetMergeList implements RestReadView<RevisionResource> { return createResponse(rsrc, ImmutableList.of()); } - List<RevCommit> commits = MergeListBuilder.build(rw, commit, uninterestingParent); + ImmutableList<RevCommit> commits = MergeListBuilder.build(rw, commit, uninterestingParent); List<CommitInfo> result = new ArrayList<>(commits.size()); RevisionJson changeJson = json.create(ImmutableSet.of()); for (RevCommit c : commits) { @@ -88,7 +89,8 @@ public class GetMergeList implements RestReadView<RevisionResource> { c, addLinks, /* fillCommit= */ true, - rsrc.getChange().getDest().branch())); + rsrc.getChange().getDest().branch(), + rsrc.getChange().getKey().get())); } return createResponse(rsrc, result); } @@ -98,7 +100,7 @@ public class GetMergeList implements RestReadView<RevisionResource> { RevisionResource rsrc, List<CommitInfo> result) { Response<List<CommitInfo>> r = Response.ok(result); if (rsrc.isCacheable()) { - r.caching(CacheControl.PRIVATE(7, TimeUnit.DAYS)); + r.caching(CacheControl.PRIVATE(7, DAYS)); } return r; } |