fix(gerrit): return HTML titles in more cases

At present, we don't return HTML titles if there's a trailing slash,
or a patchset. Instead, just consume the / and anything after it.

This also fixes /123, because this is HTTP redirected to the full path
*with a trailing slash* which otherwise wouldn't get the title
injected.

Change-Id: Idfd0e67752880a37dce0b400a3c1cfc53fac2912
Reviewed-on: https://cl.tvl.fyi/c/depot/+/859
Reviewed-by: BuildkiteCI
Reviewed-by: tazjin <mail@tazj.in>
Tested-by: BuildkiteCI
This commit is contained in:
Luke Granger-Brown 2020-07-02 23:28:39 +01:00 committed by lukegb
parent 26bb34823d
commit 3f6518ce99
5 changed files with 64 additions and 11 deletions

View file

@ -1,3 +1,12 @@
From aa4cda172a61eb4f09759cba98f4645fe74753a9 Mon Sep 17 00:00:00 2001
From: Luke Granger-Brown <git@lukegb.com>
Date: Thu, 2 Jul 2020 23:02:09 +0100
Subject: [PATCH 1/4] Use detzip in download_bower.py
---
tools/js/download_bower.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/js/download_bower.py b/tools/js/download_bower.py diff --git a/tools/js/download_bower.py b/tools/js/download_bower.py
index 1df4b826bc..65bda74082 100755 index 1df4b826bc..65bda74082 100755
--- a/tools/js/download_bower.py --- a/tools/js/download_bower.py
@ -11,3 +20,6 @@ index 1df4b826bc..65bda74082 100755
cwd=bc) cwd=bc)
if args.s: if args.s:
--
2.25.1

View file

@ -1,8 +1,17 @@
From f14cba31f2a9a75d06e58fd6313cc60d0cf5e690 Mon Sep 17 00:00:00 2001
From: Luke Granger-Brown <git@lukegb.com>
Date: Thu, 2 Jul 2020 23:02:32 +0100
Subject: [PATCH 2/4] Syntax highlight nix
---
.../app/elements/diff/gr-syntax-layer/gr-syntax-layer.js | 1 +
1 file changed, 1 insertion(+)
diff --git a/polygerrit-ui/app/elements/diff/gr-syntax-layer/gr-syntax-layer.js b/polygerrit-ui/app/elements/diff/gr-syntax-layer/gr-syntax-layer.js diff --git a/polygerrit-ui/app/elements/diff/gr-syntax-layer/gr-syntax-layer.js b/polygerrit-ui/app/elements/diff/gr-syntax-layer/gr-syntax-layer.js
index 1a0bbd9f50..0f2786a911 100644 index f1e930f177..cc937cff67 100644
--- a/polygerrit-ui/app/elements/diff/gr-syntax-layer/gr-syntax-layer.js --- a/polygerrit-ui/app/elements/diff/gr-syntax-layer/gr-syntax-layer.js
+++ b/polygerrit-ui/app/elements/diff/gr-syntax-layer/gr-syntax-layer.js +++ b/polygerrit-ui/app/elements/diff/gr-syntax-layer/gr-syntax-layer.js
@@ -99,6 +99,7 @@ const LANGUAGE_MAP = { @@ -101,6 +101,7 @@ const LANGUAGE_MAP = {
'text/x-vhdl': 'vhdl', 'text/x-vhdl': 'vhdl',
'text/x-yaml': 'yaml', 'text/x-yaml': 'yaml',
'text/vbscript': 'vbscript', 'text/vbscript': 'vbscript',
@ -10,3 +19,6 @@ index 1a0bbd9f50..0f2786a911 100644
}; };
const ASYNC_DELAY = 10; const ASYNC_DELAY = 10;
--
2.25.1

View file

@ -1,8 +1,17 @@
From c3603950e5ae377514febbebf9aa26c31e07cd5d Mon Sep 17 00:00:00 2001
From: Luke Granger-Brown <git@lukegb.com>
Date: Thu, 2 Jul 2020 23:02:43 +0100
Subject: [PATCH 3/4] Syntax highlight rules.pl
---
.../elements/diff/gr-syntax-layer/gr-syntax-layer.js | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/polygerrit-ui/app/elements/diff/gr-syntax-layer/gr-syntax-layer.js b/polygerrit-ui/app/elements/diff/gr-syntax-layer/gr-syntax-layer.js diff --git a/polygerrit-ui/app/elements/diff/gr-syntax-layer/gr-syntax-layer.js b/polygerrit-ui/app/elements/diff/gr-syntax-layer/gr-syntax-layer.js
index 1a0bbd9f50..d8d2fa643b 100644 index cc937cff67..2145bc169b 100644
--- a/polygerrit-ui/app/elements/diff/gr-syntax-layer/gr-syntax-layer.js --- a/polygerrit-ui/app/elements/diff/gr-syntax-layer/gr-syntax-layer.js
+++ b/polygerrit-ui/app/elements/diff/gr-syntax-layer/gr-syntax-layer.js +++ b/polygerrit-ui/app/elements/diff/gr-syntax-layer/gr-syntax-layer.js
@@ -102,6 +102,10 @@ const LANGUAGE_MAP = { @@ -105,6 +105,10 @@ const LANGUAGE_MAP = {
}; };
const ASYNC_DELAY = 10; const ASYNC_DELAY = 10;
@ -13,7 +22,7 @@ index 1a0bbd9f50..d8d2fa643b 100644
const CLASS_WHITELIST = { const CLASS_WHITELIST = {
'gr-diff gr-syntax gr-syntax-attr': true, 'gr-diff gr-syntax gr-syntax-attr': true,
'gr-diff gr-syntax gr-syntax-attribute': true, 'gr-diff gr-syntax gr-syntax-attribute': true,
@@ -233,10 +237,16 @@ class GrSyntaxLayer extends GestureEventListeners( @@ -236,10 +240,16 @@ class GrSyntaxLayer extends GestureEventListeners(
} }
} }
@ -30,3 +39,6 @@ index 1a0bbd9f50..d8d2fa643b 100644
LANGUAGE_MAP[diffFileMetaInfo.content_type]; LANGUAGE_MAP[diffFileMetaInfo.content_type];
} }
--
2.25.1

View file

@ -1,3 +1,17 @@
From ead56bd63491ba4fd3c24fb1e9af36a3fa2141bf Mon Sep 17 00:00:00 2001
From: Luke Granger-Brown <git@lukegb.com>
Date: Thu, 2 Jul 2020 23:03:02 +0100
Subject: [PATCH 4/4] Add titles to CLs over HTTP
---
.../gerrit/httpd/raw/IndexHtmlUtil.java | 14 +++-
.../google/gerrit/httpd/raw/IndexServlet.java | 7 +-
.../google/gerrit/httpd/raw/StaticModule.java | 5 +-
.../gerrit/httpd/raw/TitleComputer.java | 67 +++++++++++++++++++
.../gerrit/httpd/raw/PolyGerritIndexHtml.soy | 4 +-
5 files changed, 89 insertions(+), 8 deletions(-)
create mode 100644 java/com/google/gerrit/httpd/raw/TitleComputer.java
diff --git a/java/com/google/gerrit/httpd/raw/IndexHtmlUtil.java b/java/com/google/gerrit/httpd/raw/IndexHtmlUtil.java diff --git a/java/com/google/gerrit/httpd/raw/IndexHtmlUtil.java b/java/com/google/gerrit/httpd/raw/IndexHtmlUtil.java
index 41d2f83975..323567b4a4 100644 index 41d2f83975..323567b4a4 100644
--- a/java/com/google/gerrit/httpd/raw/IndexHtmlUtil.java --- a/java/com/google/gerrit/httpd/raw/IndexHtmlUtil.java
@ -109,7 +123,7 @@ index 414a120194..e1b6fb082d 100644
@Provides @Provides
diff --git a/java/com/google/gerrit/httpd/raw/TitleComputer.java b/java/com/google/gerrit/httpd/raw/TitleComputer.java diff --git a/java/com/google/gerrit/httpd/raw/TitleComputer.java b/java/com/google/gerrit/httpd/raw/TitleComputer.java
new file mode 100644 new file mode 100644
index 0000000000..efee24607c index 0000000000..8fd2053ad0
--- /dev/null --- /dev/null
+++ b/java/com/google/gerrit/httpd/raw/TitleComputer.java +++ b/java/com/google/gerrit/httpd/raw/TitleComputer.java
@@ -0,0 +1,67 @@ @@ -0,0 +1,67 @@
@ -159,7 +173,7 @@ index 0000000000..efee24607c
+ return Optional.empty(); + return Optional.empty();
+ } + }
+ +
+ private static final Pattern extractChangeIdRegex = Pattern.compile("^/(?:c/.*/\\+/)?(?<changeId>[0-9]+)(?:/[0-9]+)?$"); + private static final Pattern extractChangeIdRegex = Pattern.compile("^/(?:c/.*/\\+/)?(?<changeId>[0-9]+)(?:/[0-9]+)?(?:/.*)?$");
+ private final Provider<ChangesCollection> changes; + private final Provider<ChangesCollection> changes;
+ +
+ private Optional<Change.Id> tryExtractChange(String path) { + private Optional<Change.Id> tryExtractChange(String path) {
@ -198,3 +212,6 @@ index d162714399..0ba228ad00 100644
<meta name="referrer" content="never">{\n} <meta name="referrer" content="never">{\n}
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">{\n} <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">{\n}
--
2.25.1

View file

@ -40,10 +40,10 @@ pkgs.buildBazelPackage {
fetchSubmodules = true; fetchSubmodules = true;
}; };
patches = [ patches = [
./use_detzip.patch ./0001-Use-detzip-in-download_bower.py.patch
./syntax_highlight_nix.patch ./0002-Syntax-highlight-nix.patch
./syntax_highlight_rules_pl.patch ./0003-Syntax-highlight-rules.pl.patch
./add_titles_to_cls.patch ./0004-Add-titles-to-CLs-over-HTTP.patch
]; ];
bazelTarget = "release"; bazelTarget = "release";