diff --git a/src/gh_range_diff.rs b/src/gh_range_diff.rs index 5a1453220..e804b7533 100644 --- a/src/gh_range_diff.rs +++ b/src/gh_range_diff.rs @@ -8,7 +8,6 @@ use axum::{ http::HeaderValue, response::IntoResponse, }; -use axum_extra::extract::Host; use hyper::header::CACHE_CONTROL; use hyper::{ HeaderMap, StatusCode, @@ -34,7 +33,6 @@ static MARKER_RE: LazyLock = pub async fn gh_range_diff( Path((owner, repo, basehead)): Path<(String, String, String)>, State(ctx): State>, - host: Host, ) -> axum::response::Result { let Some((oldhead, newhead)) = basehead.split_once("..") else { return Ok(( @@ -122,7 +120,6 @@ pub async fn gh_range_diff( let ((oldbase, old), (newbase, new)) = futures::try_join!(old, new)?; process_old_new( - host, (&owner, &repo), (&oldbase, oldhead, old), (&newbase, newhead, new), @@ -136,7 +133,6 @@ pub async fn gh_range_diff( pub async fn gh_ranges_diff( Path((owner, repo, oldbasehead, newbasehead)): Path<(String, String, String, String)>, State(ctx): State>, - host: Host, ) -> axum::response::Result { let Some((oldbase, oldhead)) = oldbasehead.split_once("..") else { return Ok(( @@ -191,7 +187,6 @@ pub async fn gh_ranges_diff( let (old, new) = futures::try_join!(old, new)?; process_old_new( - host, (&owner, &repo), (&oldbase, oldhead, old), (&newbase, newhead, new), @@ -199,7 +194,6 @@ pub async fn gh_ranges_diff( } fn process_old_new( - Host(host): Host, (owner, repo): (&str, &str), (oldbase, oldhead, mut old): (&str, &str, GithubCompare), (newbase, newhead, mut new): (&str, &str, GithubCompare), @@ -216,8 +210,10 @@ fn process_old_new( // Create the HTML buffer with a very rough approximation for the capacity let mut html: String = String::with_capacity(800 + old.files.len() * 100); - // Compute the bookmarklet for the current host - let bookmarklet = bookmarklet(&host); + let a_oldbase = a_github_commit(owner, repo, oldbase); + let a_oldhead = a_github_commit(owner, repo, oldhead); + let a_newbase = a_github_commit(owner, repo, newbase); + let a_newhead = a_github_commit(owner, repo, newhead); // Write HTML header, style, ... writeln!( @@ -228,7 +224,7 @@ fn process_old_new( - range-diff of {oldbase}...{oldhead} {newbase}...{newhead} + range-diff of {oldbase}..{oldhead} {newbase}..{newhead} -

range-diff of {oldbase}...{oldhead} {newbase}...{newhead}

-

Bookmarklet: range-diff 🛈 | {REMOVED_BLOCK_SIGN} before | {ADDED_BLOCK_SIGN} after

+

range-diff of {a_oldbase}..{a_oldhead} {a_newbase}..{a_newhead} in {owner}/{repo}

+

Legend: {REMOVED_BLOCK_SIGN} before | {ADDED_BLOCK_SIGN} after

"# )?; @@ -609,24 +609,6 @@ impl UnifiedDiffPrinter for HtmlDiffPrinter<'_> { } } -// Create the javascript bookmarklet based on the host -fn bookmarklet(host: &str) -> String { - let protocol = if host.starts_with("localhost:") { - "http" - } else { - "https" - }; - - format!( - r"javascript:(() => {{ - const githubUrlPattern = /^https:\/\/github\.com\/([^\/]+)\/([^\/]+)\/compare\/([^\/]+[.]{{2}}[^\/]+)$/; - const match = window.location.href.match(githubUrlPattern); - if (!match) {{alert('Invalid GitHub Compare URL format.\nExpected: https://github.com/ORG_NAME/REPO_NAME/compare/BASESHA..HEADSHA'); return;}} - const [, orgName, repoName, basehead] = match; window.location = `{protocol}://{host}/gh-range-diff/${{orgName}}/${{repoName}}/${{basehead}}`; -}})();" - ) -} - // Simple abstraction over `unicode_segmentation::split_word_bounds` for `imara_diff::TokenSource` struct SplitWordBoundaries<'a>(&'a str); @@ -643,3 +625,10 @@ impl<'a> imara_diff::TokenSource for SplitWordBoundaries<'a> { (self.0.len() as f32 / 4.7f32) as u32 } } + +fn a_github_commit(owner: &str, repo: &str, ref_: &str) -> String { + format!( + r#"{}"#, + &ref_[..=6] + ) +}