CommentSender: Use UrlFormatter to get URLs for file and comments
CommentSender is hard coded to provide the direct URL to a filename within a patch, and to the inline comments. The hard-coded URLs are in the legacy format, meaning they do not include the project name and are inconsistent with other links included in notifications and console messages from Gerrit. Hard-coding the URLs also means it's not possible for plugins to provide alternative URLs. Add new methods on the UrlFormatter interface, and provide default implementations that include the project name, thus making the URLs consistent with other URLs emitted by Gerrit, and also allowing plugins to provide alternatives. Change-Id: I0991dea120856c2c2bf1304749961e28b0b73a24
This commit is contained in:
@@ -47,6 +47,19 @@ public interface UrlFormatter {
|
||||
return getWebUrl().map(url -> url + "c/" + project.get() + "/+/" + id.get());
|
||||
}
|
||||
|
||||
/** Returns the URL for viewing a file in a given patch set of a change. */
|
||||
default Optional<String> getPatchFileView(Change change, int patchsetId, String filename) {
|
||||
return getChangeViewUrl(change.getProject(), change.getId())
|
||||
.map(url -> url + "/" + patchsetId + "/" + filename);
|
||||
}
|
||||
|
||||
/** Returns the URL for viewing a comment in a file in a given patch set of a change. */
|
||||
default Optional<String> getInlineCommentView(
|
||||
Change change, int patchsetId, String filename, short side, int startLine) {
|
||||
return getPatchFileView(change, patchsetId, filename)
|
||||
.map(url -> url + String.format("@%s%d", side == 0 ? "a" : "", startLine));
|
||||
}
|
||||
|
||||
/** Returns a URL pointing to a section of the settings page. */
|
||||
default Optional<String> getSettingsUrl(@Nullable String section) {
|
||||
return getWebUrl()
|
||||
|
||||
Reference in New Issue
Block a user