feat(atward): Support depot revision queries (r/...)
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>
This commit is contained in:
parent
0e5730a26f
commit
10e279ac13
1 changed files with 26 additions and 4 deletions
|
@ -91,7 +91,6 @@ fn cgit_url(path: &str) -> String {
|
||||||
fn sourcegraph_path_url(path: &str) -> String {
|
fn sourcegraph_path_url(path: &str) -> String {
|
||||||
format!("https://cs.tvl.fyi/depot/-/tree/{}", path)
|
format!("https://cs.tvl.fyi/depot/-/tree/{}", path)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Definition of all supported query handlers in atward.
|
/// Definition of all supported query handlers in atward.
|
||||||
fn handlers() -> Vec<Handler> {
|
fn handlers() -> Vec<Handler> {
|
||||||
vec![
|
vec![
|
||||||
|
@ -110,6 +109,16 @@ fn handlers() -> Vec<Handler> {
|
||||||
pattern: Regex::new("^(?P<host>b|cl|cs|code|at|todo)$").unwrap(),
|
pattern: Regex::new("^(?P<host>b|cl|cs|code|at|todo)$").unwrap(),
|
||||||
target: |_, captures| Some(format!("https://{}.tvl.fyi/", &captures["host"])),
|
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)
|
// Depot paths (e.g. //web/atward or //ops/nixos/whitby/default.nix)
|
||||||
// TODO(tazjin): Add support for specifying lines in a query parameter
|
// TODO(tazjin): Add support for specifying lines in a query parameter
|
||||||
Handler {
|
Handler {
|
||||||
|
@ -117,9 +126,7 @@ fn handlers() -> Vec<Handler> {
|
||||||
target: |query, captures| {
|
target: |query, captures| {
|
||||||
// Pass an empty string if the path is missing, to
|
// Pass an empty string if the path is missing, to
|
||||||
// redirect to the depot root.
|
// redirect to the depot root.
|
||||||
let path = captures.name("path")
|
let path = captures.name("path").map(|m| m.as_str()).unwrap_or("");
|
||||||
.map(|m| m.as_str())
|
|
||||||
.unwrap_or("");
|
|
||||||
|
|
||||||
if query.cs {
|
if query.cs {
|
||||||
Some(sourcegraph_path_url(path))
|
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,);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue