diff options
author | Vincent Ambo <mail@tazj.in> | 2021-11-05T11·29+0100 |
---|---|---|
committer | tazjin <mail@tazj.in> | 2021-11-05T12·26+0000 |
commit | 10e279ac13f3fe98cfd301dc38d54507740f9b86 (patch) | |
tree | 06294a312f89caed5a43a119b30a1030ca4a08e5 | |
parent | 0e5730a26f290dbc361a3a51756b60eec94e5c5f (diff) |
feat(atward): Support depot revision queries (r/...) r/3002
Redirects these to the cgit commit view. Only supports cgit because we don't have a good way to coax Sourcegraph into fetching these refs. Change-Id: I8c28ed015ba37c04eb4b7a667bde70ff6a92bf4c Reviewed-on: https://cl.tvl.fyi/c/depot/+/3772 Tested-by: BuildkiteCI Reviewed-by: sterni <sternenseemann@systemli.org>
-rw-r--r-- | web/atward/src/main.rs | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/web/atward/src/main.rs b/web/atward/src/main.rs index 94e9fff9bc71..26d79cde1a1b 100644 --- a/web/atward/src/main.rs +++ b/web/atward/src/main.rs @@ -91,7 +91,6 @@ fn cgit_url(path: &str) -> String { fn sourcegraph_path_url(path: &str) -> String { format!("https://cs.tvl.fyi/depot/-/tree/{}", path) } - /// Definition of all supported query handlers in atward. fn handlers() -> Vec<Handler> { vec![ @@ -110,6 +109,16 @@ fn handlers() -> Vec<Handler> { pattern: Regex::new("^(?P<host>b|cl|cs|code|at|todo)$").unwrap(), target: |_, captures| Some(format!("https://{}.tvl.fyi/", &captures["host"])), }, + // Depot revisions (e.g. r/3002) + Handler { + pattern: Regex::new("^r/(?P<rev>\\d+)$").unwrap(), + target: |_, captures| { + Some(format!( + "https://code.tvl.fyi/commit/?id=refs/r/{}", + &captures["rev"] + )) + }, + }, // Depot paths (e.g. //web/atward or //ops/nixos/whitby/default.nix) // TODO(tazjin): Add support for specifying lines in a query parameter Handler { @@ -117,9 +126,7 @@ fn handlers() -> Vec<Handler> { target: |query, captures| { // Pass an empty string if the path is missing, to // redirect to the depot root. - let path = captures.name("path") - .map(|m| m.as_str()) - .unwrap_or(""); + let path = captures.name("path").map(|m| m.as_str()).unwrap_or(""); if query.cs { Some(sourcegraph_path_url(path)) @@ -363,4 +370,19 @@ mod tests { }, ); } + + #[test] + fn depot_revision_query() { + assert_eq!( + dispatch(&handlers(), &"r/3002".into()), + Some("https://code.tvl.fyi/commit/?id=refs/r/3002".to_string()) + ); + + assert_eq!( + dispatch(&handlers(), &"something only mentioning r/3002".into()), + None, + ); + + assert_eq!(dispatch(&handlers(), &"r/invalid".into()), None,); + } } |