fix(atward): Redirect //
queries to depot root
Makes it possible to open the default code viewer for the user at the depot root by searching for `//`. Fixes b/134. Change-Id: I409ad36cea28de27cd1789a84eda71f8979d3133 Reviewed-on: https://cl.tvl.fyi/c/depot/+/3437 Tested-by: BuildkiteCI Reviewed-by: sterni <sternenseemann@systemli.org>
This commit is contained in:
parent
da0b330756
commit
72ebd3411b
1 changed files with 23 additions and 3 deletions
|
@ -113,12 +113,18 @@ fn handlers() -> Vec<Handler> {
|
|||
// Depot paths (e.g. //web/atward or //ops/nixos/whitby/default.nix)
|
||||
// TODO(tazjin): Add support for specifying lines in a query parameter
|
||||
Handler {
|
||||
pattern: Regex::new("^//(?P<path>[a-zA-Z].*)$").unwrap(),
|
||||
pattern: Regex::new("^//(?P<path>[a-zA-Z].*)?$").unwrap(),
|
||||
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("");
|
||||
|
||||
if query.cs {
|
||||
Some(sourcegraph_path_url(&captures["path"]))
|
||||
Some(sourcegraph_path_url(path))
|
||||
} else {
|
||||
Some(cgit_url(&captures["path"]))
|
||||
Some(cgit_url(path))
|
||||
}
|
||||
},
|
||||
},
|
||||
|
@ -255,6 +261,20 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn depot_root_cgit_query() {
|
||||
assert_eq!(
|
||||
dispatch(
|
||||
&handlers(),
|
||||
&Query {
|
||||
query: "//".to_string(),
|
||||
cs: false,
|
||||
}
|
||||
),
|
||||
Some("https://code.tvl.fyi/tree/".to_string()),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn plain_host_queries() {
|
||||
assert_eq!(
|
||||
|
|
Loading…
Reference in a new issue