Latest commit bar with sha, age and commit count on the code view
Browse files at this commitad88fce765d83f39a4b46a99bd56c88f57c6a128Parent: 38ea98f- feat
- latest commit bar with sha, age and commit count on the code view
7 changed files +428 -9
- crates/forge-git/src/history.rs +20 -0
- crates/forge-git/tests/history.rs +38 -1
- crates/forge-web/src/i18n/code.rs +12 -0
- crates/forge-web/src/pages/repo.rs +17 -3
- crates/forge-web/src/pages/tree.rs +166 -5
- crates/forge-web/tests/browse_e2e.rs +49 -0
- style/_repo.scss +126 -0
crates/forge-git/src/history.rsmodified+20 -0
| @@ -263,6 +263,26 @@ pub async fn log( | |||
| 263 | .collect()) | 263 | .collect()) |
| 264 | } | 264 | } |
| 265 | 265 | ||
| 266 | +/// Number of commits reachable from `commit`, limited to `path` when given (`git rev-list | ||
| 267 | +/// --count`). Counts every commit, not just the ones a history page shows. | ||
| 268 | +pub async fn count(env: &GitEnv, repo: &Path, commit: &str, path: Option<&str>) -> Result<u64> { | ||
| 269 | + validate_oid(commit)?; | ||
| 270 | + let mut cmd = git(env, "rev-list") | ||
| 271 | + .git_dir(repo) | ||
| 272 | + .arg("--count") | ||
| 273 | + .user_revs(&[commit])?; | ||
| 274 | + if let Some(p) = path { | ||
| 275 | + browse::validate_repo_path(p)?; | ||
| 276 | + let spec = literal_spec(p); | ||
| 277 | + cmd = cmd.paths(&[spec.as_str()]); | ||
| 278 | + } | ||
| 279 | + let out = cmd.output().await?; | ||
| 280 | + let text = String::from_utf8_lossy(&out); | ||
| 281 | + text.trim() | ||
| 282 | + .parse::<u64>() | ||
| 283 | + .map_err(|_| Error::Failed(format!("unexpected rev-list count: {:?}", text.trim()))) | ||
| 284 | +} | ||
| 285 | + | ||
| 266 | /// Commits reachable from `new` but not from `old` (when `old` is given), oldest first. At most | 286 | /// Commits reachable from `new` but not from `old` (when `old` is given), oldest first. At most |
| 267 | /// `max` of the newest commits are returned. Both ids must be full object ids; they are passed | 287 | /// `max` of the newest commits are returned. Both ids must be full object ids; they are passed |
| 268 | /// after `--end-of-options`, so no value can be read as an option. | 288 | /// after `--end-of-options`, so no value can be read as an option. |
crates/forge-git/tests/history.rsmodified+38 -1
| @@ -4,7 +4,7 @@ use std::process::{Command, Stdio}; | |||
| 4 | 4 | ||
| 5 | use forge_git::history::{ | 5 | use forge_git::history::{ |
| 6 | ArchiveFormat, CommitDiff, DiffLimits, DiffStatus, FileDiff, LineKind, archive_command, | 6 | ArchiveFormat, CommitDiff, DiffLimits, DiffStatus, FileDiff, LineKind, archive_command, |
| 7 | - commit_diff, last_commits, log, | 7 | + commit_diff, count, last_commits, log, |
| 8 | }; | 8 | }; |
| 9 | use forge_git::{Error, GitEnv}; | 9 | use forge_git::{Error, GitEnv}; |
| 10 | 10 | ||
| @@ -322,6 +322,43 @@ async fn last_commits_finds_newest_touch_per_child() { | |||
| 322 | assert_eq!(short["sub"].oid, c5); | 322 | assert_eq!(short["sub"].oid, c5); |
| 323 | } | 323 | } |
| 324 | 324 | ||
| 325 | +#[tokio::test] | ||
| 326 | +async fn count_counts_all_commits_or_those_touching_a_path() { | ||
| 327 | + let f = fixture(); | ||
| 328 | + f.write("d/x.txt", "1\n"); | ||
| 329 | + f.commit("c1 add x"); | ||
| 330 | + f.write("d/y.txt", "1\n"); | ||
| 331 | + let c2 = f.commit("c2 add y"); | ||
| 332 | + f.write("d/x.txt", "2\n"); | ||
| 333 | + f.commit("c3 change x"); | ||
| 334 | + f.write("other.txt", "1\n"); | ||
| 335 | + let c4 = f.commit("c4 other"); | ||
| 336 | + | ||
| 337 | + let all = count(&f.env, &f.git_dir, &c4, None).await.unwrap(); | ||
| 338 | + assert_eq!(all, 4); | ||
| 339 | + let dir = count(&f.env, &f.git_dir, &c4, Some("d")).await.unwrap(); | ||
| 340 | + assert_eq!(dir, 3); | ||
| 341 | + let file = count(&f.env, &f.git_dir, &c4, Some("other.txt")) | ||
| 342 | + .await | ||
| 343 | + .unwrap(); | ||
| 344 | + assert_eq!(file, 1); | ||
| 345 | + let at_c2 = count(&f.env, &f.git_dir, &c2, Some("d/x.txt")) | ||
| 346 | + .await | ||
| 347 | + .unwrap(); | ||
| 348 | + assert_eq!(at_c2, 1); | ||
| 349 | + let untouched = count(&f.env, &f.git_dir, &c4, Some("missing")) | ||
| 350 | + .await | ||
| 351 | + .unwrap(); | ||
| 352 | + assert_eq!(untouched, 0); | ||
| 353 | + | ||
| 354 | + assert!(count(&f.env, &f.git_dir, "not-an-oid", None).await.is_err()); | ||
| 355 | + assert!( | ||
| 356 | + count(&f.env, &f.git_dir, &c4, Some("../escape")) | ||
| 357 | + .await | ||
| 358 | + .is_err() | ||
| 359 | + ); | ||
| 360 | +} | ||
| 361 | + | ||
| 325 | #[tokio::test] | 362 | #[tokio::test] |
| 326 | async fn archive_command_produces_listable_tar_gz() { | 363 | async fn archive_command_produces_listable_tar_gz() { |
| 327 | let f = fixture(); | 364 | let f = fixture(); |
crates/forge-web/src/i18n/code.rsmodified+12 -0
| @@ -36,6 +36,7 @@ pub enum K { | |||
| 36 | NameHeader, | 36 | NameHeader, |
| 37 | LastCommitHeader, | 37 | LastCommitHeader, |
| 38 | AgeHeader, | 38 | AgeHeader, |
| 39 | + LatestCommitLabel, | ||
| 39 | KindDir, | 40 | KindDir, |
| 40 | KindFile, | 41 | KindFile, |
| 41 | KindExec, | 42 | KindExec, |
| @@ -181,6 +182,8 @@ pub fn t(lang: Lang, key: K) -> &'static str { | |||
| 181 | (LastCommitHeader, Tr) => "Son commit", | 182 | (LastCommitHeader, Tr) => "Son commit", |
| 182 | (AgeHeader, En) => "Age", | 183 | (AgeHeader, En) => "Age", |
| 183 | (AgeHeader, Tr) => "Zaman", | 184 | (AgeHeader, Tr) => "Zaman", |
| 185 | + (LatestCommitLabel, En) => "Latest commit", | ||
| 186 | + (LatestCommitLabel, Tr) => "Son commit", | ||
| 184 | (KindDir, En) => "dir", | 187 | (KindDir, En) => "dir", |
| 185 | (KindDir, Tr) => "dizin", | 188 | (KindDir, Tr) => "dizin", |
| 186 | (KindFile, En) => "file", | 189 | (KindFile, En) => "file", |
| @@ -417,6 +420,14 @@ pub fn changed_files(lang: Lang, count: usize) -> String { | |||
| 417 | } | 420 | } |
| 418 | } | 421 | } |
| 419 | 422 | ||
| 423 | +/// `N commits` in English (`1 commit` for one), `N commit` in Turkish. | ||
| 424 | +pub fn commit_count(lang: Lang, count: u64) -> String { | ||
| 425 | + match lang { | ||
| 426 | + Lang::En => format!("{count} commit{}", if count == 1 { "" } else { "s" }), | ||
| 427 | + Lang::Tr => format!("{count} commit"), | ||
| 428 | + } | ||
| 429 | +} | ||
| 430 | + | ||
| 420 | /// The note that a diff stops at `max` files. `subject` names what the diff shows. | 431 | /// The note that a diff stops at `max` files. `subject` names what the diff shows. |
| 421 | pub fn diff_truncated(lang: Lang, max: usize, subject: &str) -> String { | 432 | pub fn diff_truncated(lang: Lang, max: usize, subject: &str) -> String { |
| 422 | match lang { | 433 | match lang { |
| @@ -521,6 +532,7 @@ mod tests { | |||
| 521 | K::NameHeader, | 532 | K::NameHeader, |
| 522 | K::LastCommitHeader, | 533 | K::LastCommitHeader, |
| 523 | K::AgeHeader, | 534 | K::AgeHeader, |
| 535 | + K::LatestCommitLabel, | ||
| 524 | K::KindDir, | 536 | K::KindDir, |
| 525 | K::KindFile, | 537 | K::KindFile, |
| 526 | K::KindExec, | 538 | K::KindExec, |
crates/forge-web/src/pages/repo.rsmodified+17 -3
| @@ -28,7 +28,7 @@ use crate::pages::refs::load_refs; | |||
| 28 | use crate::pages::releases::latest_card; | 28 | use crate::pages::releases::latest_card; |
| 29 | use crate::pages::repo_ctx::{RepoCtx, RepoHead, load_repo}; | 29 | use crate::pages::repo_ctx::{RepoCtx, RepoHead, load_repo}; |
| 30 | use crate::pages::tree::{ | 30 | use crate::pages::tree::{ |
| 31 | - entry_rows, last_commits, load_readme, read_dir, readme_card, tree_table, | 31 | + entry_rows, last_commits, latest_bar, load_readme, read_dir, readme_card, tree_table, |
| 32 | }; | 32 | }; |
| 33 | use crate::state::AppState; | 33 | use crate::state::AppState; |
| 34 | use crate::views::{now_unix, relative_time, repo_href, repo_tabs, shell, user_link}; | 34 | use crate::views::{now_unix, relative_time, repo_href, repo_tabs, shell, user_link}; |
| @@ -417,11 +417,25 @@ async fn repo_page(cx: &Cx) -> Result<impl View> { | |||
| 417 | // The tree and README exist only when the default branch has a commit. | 417 | // The tree and README exist only when the default branch has a commit. |
| 418 | let mut tree = None; | 418 | let mut tree = None; |
| 419 | let mut readme = None; | 419 | let mut readme = None; |
| 420 | + let mut bar = None; | ||
| 420 | if let Some(commit) = &head | 421 | if let Some(commit) = &head |
| 421 | && let Some(entries) = read_dir(ctx.path.clone(), commit.clone(), String::new()).await? | 422 | && let Some(entries) = read_dir(ctx.path.clone(), commit.clone(), String::new()).await? |
| 422 | { | 423 | { |
| 423 | let names: Vec<String> = entries.iter().map(|e| e.name.clone()).collect(); | 424 | let names: Vec<String> = entries.iter().map(|e| e.name.clone()).collect(); |
| 424 | - let last = last_commits(state, &ctx.path, commit, "", &names).await; | 425 | + let (last, latest) = tokio::join!( |
| 426 | + last_commits(state, &ctx.path, commit, "", &names), | ||
| 427 | + latest_bar( | ||
| 428 | + state, | ||
| 429 | + repo, | ||
| 430 | + &ctx.path, | ||
| 431 | + &branch, | ||
| 432 | + commit, | ||
| 433 | + "", | ||
| 434 | + lang, | ||
| 435 | + ctx.viewer_tz() | ||
| 436 | + ), | ||
| 437 | + ); | ||
| 438 | + bar = latest; | ||
| 425 | readme = load_readme(state, repo, &ctx.path, &branch, commit, "", &entries).await?; | 439 | readme = load_readme(state, repo, &ctx.path, &branch, commit, "", &entries).await?; |
| 426 | tree = Some(entry_rows( | 440 | tree = Some(entry_rows( |
| 427 | lang, | 441 | lang, |
| @@ -467,7 +481,7 @@ async fn repo_page(cx: &Cx) -> Result<impl View> { | |||
| 467 | </div> | 481 | </div> |
| 468 | <div class="repo-grid"> | 482 | <div class="repo-grid"> |
| 469 | <div class="repo-main"> | 483 | <div class="repo-main"> |
| 470 | - tree_table(rows: rows, lang: lang) | 484 | + tree_table(rows: rows, latest: bar, lang: lang) |
| 471 | if let Some(readme) = readme { | 485 | if let Some(readme) = readme { |
| 472 | readme_card(name: readme.name, markdown: readme.markdown, body: readme.body) | 486 | readme_card(name: readme.name, markdown: readme.markdown, body: readme.body) |
| 473 | } | 487 | } |
crates/forge-web/src/pages/tree.rsmodified+166 -5
| @@ -26,7 +26,8 @@ use crate::render::emoji::emojify; | |||
| 26 | use crate::render::markdown::{LinkContext, render_markdown}; | 26 | use crate::render::markdown::{LinkContext, render_markdown}; |
| 27 | use crate::state::AppState; | 27 | use crate::state::AppState; |
| 28 | use crate::views::{ | 28 | use crate::views::{ |
| 29 | - Crumb, breadcrumb, iso_time, now_unix, ref_selector, relative_time, repo_href, shell, short_oid, | 29 | + Crumb, avatar_url, breadcrumb, display_name, iso_time, now_unix, ref_selector, relative_time, |
| 30 | + repo_href, shell, short_oid, user_href, | ||
| 30 | }; | 31 | }; |
| 31 | 32 | ||
| 32 | /// Files at the root of a directory that count as its README, in priority order. | 33 | /// Files at the root of a directory that count as its README, in priority order. |
| @@ -112,6 +113,102 @@ pub struct LastCommit { | |||
| 112 | pub age: String, | 113 | pub age: String, |
| 113 | } | 114 | } |
| 114 | 115 | ||
| 116 | +/// The bar above a directory listing: the newest commit that touched the directory (or the | ||
| 117 | +/// whole ref at the root), with its author, short sha, age and the number of commits. | ||
| 118 | +pub struct LatestBar { | ||
| 119 | + pub last: LastCommit, | ||
| 120 | + pub short: String, | ||
| 121 | + pub author: String, | ||
| 122 | + /// Profile link, only when the author maps to a forge user. | ||
| 123 | + pub author_href: Option<String>, | ||
| 124 | + /// Avatar of that user. None for plain-text authors. | ||
| 125 | + pub avatar: Option<String>, | ||
| 126 | + pub commits_href: String, | ||
| 127 | + pub commits_label: String, | ||
| 128 | +} | ||
| 129 | + | ||
| 130 | +/// Latest commit bar for the listing of `dir` at `commit` (`""` is the root). The commit lookup | ||
| 131 | +/// and the commit count run side by side. Errors and timeouts leave the bar out, or the count | ||
| 132 | +/// out of its label. | ||
| 133 | +#[allow(clippy::too_many_arguments)] | ||
| 134 | +pub async fn latest_bar( | ||
| 135 | + state: &AppState, | ||
| 136 | + repo: &RepoRow, | ||
| 137 | + path: &Path, | ||
| 138 | + ref_name: &str, | ||
| 139 | + commit: &str, | ||
| 140 | + dir: &str, | ||
| 141 | + lang: Lang, | ||
| 142 | + tz: &str, | ||
| 143 | +) -> Option<LatestBar> { | ||
| 144 | + let filter = (!dir.is_empty()).then_some(dir); | ||
| 145 | + let (log, count) = tokio::join!( | ||
| 146 | + tokio::time::timeout( | ||
| 147 | + LAST_COMMIT_TIMEOUT, | ||
| 148 | + history::log(&state.git, path, commit, filter, 0, 1), | ||
| 149 | + ), | ||
| 150 | + tokio::time::timeout( | ||
| 151 | + LAST_COMMIT_TIMEOUT, | ||
| 152 | + history::count(&state.git, path, commit, filter), | ||
| 153 | + ), | ||
| 154 | + ); | ||
| 155 | + let info = match log { | ||
| 156 | + Ok(Ok(commits)) => commits.into_iter().next()?, | ||
| 157 | + Ok(Err(e)) => { | ||
| 158 | + tracing::warn!(error = %e, "latest-commit lookup failed"); | ||
| 159 | + return None; | ||
| 160 | + } | ||
| 161 | + Err(_) => { | ||
| 162 | + tracing::warn!("latest-commit lookup timed out"); | ||
| 163 | + return None; | ||
| 164 | + } | ||
| 165 | + }; | ||
| 166 | + let count = match count { | ||
| 167 | + Ok(Ok(n)) => Some(n), | ||
| 168 | + Ok(Err(e)) => { | ||
| 169 | + tracing::warn!(error = %e, "commit count failed"); | ||
| 170 | + None | ||
| 171 | + } | ||
| 172 | + Err(_) => { | ||
| 173 | + tracing::warn!("commit count timed out"); | ||
| 174 | + None | ||
| 175 | + } | ||
| 176 | + }; | ||
| 177 | + | ||
| 178 | + let user = state | ||
| 179 | + .store | ||
| 180 | + .verified_user_by_email(&info.author_email) | ||
| 181 | + .await | ||
| 182 | + .ok() | ||
| 183 | + .flatten(); | ||
| 184 | + let (author, author_href, avatar) = match user { | ||
| 185 | + Some(user) => ( | ||
| 186 | + display_name(lang, &user.username), | ||
| 187 | + Some(user_href(&user.username)), | ||
| 188 | + Some(avatar_url(&user.username, user.avatar_hash.as_deref())), | ||
| 189 | + ), | ||
| 190 | + None => (info.author_name.clone(), None, None), | ||
| 191 | + }; | ||
| 192 | + let rest = if dir.is_empty() { | ||
| 193 | + ref_name.to_owned() | ||
| 194 | + } else { | ||
| 195 | + format!("{ref_name}/{dir}") | ||
| 196 | + }; | ||
| 197 | + let commits_label = match count { | ||
| 198 | + Some(n) => g::commit_count(lang, n), | ||
| 199 | + None => g::t(lang, K::TabCommits).to_owned(), | ||
| 200 | + }; | ||
| 201 | + Some(LatestBar { | ||
| 202 | + last: last_commit_view(lang, repo, &info, now_unix(), tz), | ||
| 203 | + short: short_oid(&info.oid).to_owned(), | ||
| 204 | + author, | ||
| 205 | + author_href, | ||
| 206 | + avatar, | ||
| 207 | + commits_href: repo_href(&repo.owner_name, &repo.name, "commits", &rest), | ||
| 208 | + commits_label, | ||
| 209 | + }) | ||
| 210 | +} | ||
| 211 | + | ||
| 115 | /// One row of a directory listing. | 212 | /// One row of a directory listing. |
| 116 | pub struct EntryRow { | 213 | pub struct EntryRow { |
| 117 | /// "dir", "file", "exec", "link" or "submodule". | 214 | /// "dir", "file", "exec", "link" or "submodule". |
| @@ -289,11 +386,63 @@ pub async fn load_readme( | |||
| 289 | } | 386 | } |
| 290 | } | 387 | } |
| 291 | 388 | ||
| 292 | -/// Directory listing table: kind, name, last commit and its age. | 389 | +/// The latest commit bar above a listing. It is the first row of the listing box, and its |
| 390 | +/// padding and columns match the table rows below it. | ||
| 391 | +#[component] | ||
| 392 | +pub async fn latest_commit_bar(bar: LatestBar, lang: Lang) -> Result<impl View> { | ||
| 393 | + let LatestBar { | ||
| 394 | + last, | ||
| 395 | + short, | ||
| 396 | + author, | ||
| 397 | + author_href, | ||
| 398 | + avatar, | ||
| 399 | + commits_href, | ||
| 400 | + commits_label, | ||
| 401 | + } = bar; | ||
| 402 | + let initial = author | ||
| 403 | + .chars() | ||
| 404 | + .next() | ||
| 405 | + .map(|c| c.to_uppercase().collect::<String>()) | ||
| 406 | + .unwrap_or_default(); | ||
| 407 | + Ok(view! { | ||
| 408 | + <div class="latest-commit" aria-label=(g::t(lang, K::LatestCommitLabel))> | ||
| 409 | + <span class="latest-author"> | ||
| 410 | + if let Some(src) = avatar { | ||
| 411 | + <img class="avatar avatar-sm" src=(src) alt="" width="20" height="20"> | ||
| 412 | + } else { | ||
| 413 | + <span class="avatar avatar-sm avatar-blank" aria-hidden="true">(initial)</span> | ||
| 414 | + } | ||
| 415 | + if let Some(href) = author_href { | ||
| 416 | + <a href=(href)>(author)</a> | ||
| 417 | + } else { | ||
| 418 | + <span>(author)</span> | ||
| 419 | + } | ||
| 420 | + </span> | ||
| 421 | + <a class="latest-subject" href=(last.href.as_str())>(last.summary)</a> | ||
| 422 | + <span class="latest-meta"> | ||
| 423 | + <a class="mono latest-sha" href=(last.href.as_str())>(short)</a> | ||
| 424 | + <time class="latest-age" datetime=(last.iso.as_str()) title=(last.absolute.as_str())>(last.age)</time> | ||
| 425 | + <a class="latest-count" href=(commits_href.as_str())> | ||
| 426 | + <svg class="ico" viewBox="0 0 24 24" aria-hidden="true"><path d="M3 12a9 9 0 1 0 3-6.7L3 8"/><path d="M3 3v5h5"/><path d="M12 7v5l3 2"/></svg> | ||
| 427 | + (commits_label) | ||
| 428 | + </a> | ||
| 429 | + </span> | ||
| 430 | + </div> | ||
| 431 | + }) | ||
| 432 | +} | ||
| 433 | + | ||
| 434 | +/// Directory listing table: kind, name, last commit and its age. `latest` is the bar above it. | ||
| 293 | #[component] | 435 | #[component] |
| 294 | -pub async fn tree_table(rows: Vec<EntryRow>, lang: Lang) -> Result<impl View> { | 436 | +pub async fn tree_table( |
| 437 | + rows: Vec<EntryRow>, | ||
| 438 | + latest: Option<LatestBar>, | ||
| 439 | + lang: Lang, | ||
| 440 | +) -> Result<impl View> { | ||
| 295 | Ok(view! { | 441 | Ok(view! { |
| 296 | <div class="table-wrap"> | 442 | <div class="table-wrap"> |
| 443 | + if let Some(bar) = latest { | ||
| 444 | + latest_commit_bar(bar: bar, lang: lang) | ||
| 445 | + } | ||
| 297 | <table class="table tree-table"> | 446 | <table class="table tree-table"> |
| 298 | <thead> | 447 | <thead> |
| 299 | <tr> | 448 | <tr> |
| @@ -372,7 +521,19 @@ async fn tree_page(cx: &Cx) -> Result<impl View> { | |||
| 372 | return Err(not_found().into()); | 521 | return Err(not_found().into()); |
| 373 | }; | 522 | }; |
| 374 | let names: Vec<String> = entries.iter().map(|e| e.name.clone()).collect(); | 523 | let names: Vec<String> = entries.iter().map(|e| e.name.clone()).collect(); |
| 375 | - let last = last_commits(state, &ctx.path, &commit, &dir, &names).await; | 524 | + let (last, bar) = tokio::join!( |
| 525 | + last_commits(state, &ctx.path, &commit, &dir, &names), | ||
| 526 | + latest_bar( | ||
| 527 | + state, | ||
| 528 | + repo, | ||
| 529 | + &ctx.path, | ||
| 530 | + &ref_name, | ||
| 531 | + &commit, | ||
| 532 | + &dir, | ||
| 533 | + lang, | ||
| 534 | + ctx.viewer_tz() | ||
| 535 | + ), | ||
| 536 | + ); | ||
| 376 | let refs: Vec<RefInfo> = load_refs(ctx.path.clone()).await?; | 537 | let refs: Vec<RefInfo> = load_refs(ctx.path.clone()).await?; |
| 377 | let readme = load_readme(state, repo, &ctx.path, &ref_name, &commit, &dir, &entries).await?; | 538 | let readme = load_readme(state, repo, &ctx.path, &ref_name, &commit, &dir, &entries).await?; |
| 378 | let rows = entry_rows( | 539 | let rows = entry_rows( |
| @@ -401,7 +562,7 @@ async fn tree_page(cx: &Cx) -> Result<impl View> { | |||
| 401 | breadcrumb(lang: lang, crumbs: crumbs) | 562 | breadcrumb(lang: lang, crumbs: crumbs) |
| 402 | file_finder(lang: lang, owner: finder_owner, repo: finder_repo, ref_name: finder_ref) | 563 | file_finder(lang: lang, owner: finder_owner, repo: finder_repo, ref_name: finder_ref) |
| 403 | </div> | 564 | </div> |
| 404 | - tree_table(rows: rows, lang: lang) | 565 | + tree_table(rows: rows, latest: bar, lang: lang) |
| 405 | if let Some(readme) = readme { | 566 | if let Some(readme) = readme { |
| 406 | readme_card(name: readme.name, markdown: readme.markdown, body: readme.body) | 567 | readme_card(name: readme.name, markdown: readme.markdown, body: readme.body) |
| 407 | } | 568 | } |
crates/forge-web/tests/browse_e2e.rsmodified+49 -0
| @@ -136,6 +136,28 @@ fn element_texts(body: &str, selector: &str) -> Vec<String> { | |||
| 136 | .collect() | 136 | .collect() |
| 137 | } | 137 | } |
| 138 | 138 | ||
| 139 | +/// Checks the latest commit bar of a listing: one bar, with the subject, the short sha of `oid` | ||
| 140 | +/// and the commit count label. | ||
| 141 | +fn assert_latest_bar(body: &str, what: &str, subject: &str, oid: &str, count: &str) { | ||
| 142 | + let bars = element_texts(body, ".latest-commit"); | ||
| 143 | + assert_eq!(bars.len(), 1, "{what}: exactly one latest commit bar"); | ||
| 144 | + let subjects = element_texts(body, ".latest-commit .latest-subject"); | ||
| 145 | + assert_eq!(subjects.len(), 1, "{what}: bar must show the subject"); | ||
| 146 | + assert_eq!(subjects[0].trim(), subject, "{what}: bar subject"); | ||
| 147 | + let shas = element_texts(body, ".latest-commit .latest-sha"); | ||
| 148 | + assert_eq!(shas.len(), 1, "{what}: bar must show the sha"); | ||
| 149 | + assert_eq!(shas[0].trim(), &oid[..7], "{what}: bar short sha"); | ||
| 150 | + let counts = element_texts(body, ".latest-commit .latest-count"); | ||
| 151 | + assert!( | ||
| 152 | + counts.iter().any(|c| c.trim() == count), | ||
| 153 | + "{what}: bar must show {count:?}, got {counts:?}" | ||
| 154 | + ); | ||
| 155 | + assert!( | ||
| 156 | + !attr_values(body, ".latest-commit .latest-age", "title").is_empty(), | ||
| 157 | + "{what}: bar age needs an absolute time in its title" | ||
| 158 | + ); | ||
| 159 | +} | ||
| 160 | + | ||
| 139 | fn run_admin(config: &Path, username: &str, extra: &[&str], password: &str) { | 161 | fn run_admin(config: &Path, username: &str, extra: &[&str], password: &str) { |
| 140 | let out = Command::new(BIN) | 162 | let out = Command::new(BIN) |
| 141 | .arg("--config") | 163 | .arg("--config") |
| @@ -409,9 +431,25 @@ async fn browse_end_to_end() { | |||
| 409 | "README image must point at the raw origin: {image_srcs:?}" | 431 | "README image must point at the raw origin: {image_srcs:?}" |
| 410 | ); | 432 | ); |
| 411 | 433 | ||
| 434 | + // Latest commit bar: the root has one commit on main, so its subject, short sha and count. | ||
| 435 | + assert_latest_bar( | ||
| 436 | + &home_body, | ||
| 437 | + "repo home", | ||
| 438 | + "browse fixtures", | ||
| 439 | + &pub_main, | ||
| 440 | + "1 commit", | ||
| 441 | + ); | ||
| 442 | + | ||
| 412 | let tree = http.get("/tahinli/pub/tree/main/src", None).await; | 443 | let tree = http.get("/tahinli/pub/tree/main/src", None).await; |
| 413 | assert_eq!(tree.status, 200, "tree of src"); | 444 | assert_eq!(tree.status, 200, "tree of src"); |
| 414 | assert!(tree.body().contains("main.rs"), "tree must list main.rs"); | 445 | assert!(tree.body().contains("main.rs"), "tree must list main.rs"); |
| 446 | + assert_latest_bar( | ||
| 447 | + &tree.body(), | ||
| 448 | + "tree of src", | ||
| 449 | + "browse fixtures", | ||
| 450 | + &pub_main, | ||
| 451 | + "1 commit", | ||
| 452 | + ); | ||
| 415 | 453 | ||
| 416 | let blob = http.get("/tahinli/pub/blob/main/src/main.rs", None).await; | 454 | let blob = http.get("/tahinli/pub/blob/main/src/main.rs", None).await; |
| 417 | assert_eq!(blob.status, 200, "blob of main.rs"); | 455 | assert_eq!(blob.status, 200, "blob of main.rs"); |
| @@ -458,12 +496,23 @@ async fn browse_end_to_end() { | |||
| 458 | "branches must list feature/x" | 496 | "branches must list feature/x" |
| 459 | ); | 497 | ); |
| 460 | 498 | ||
| 499 | + let feature_head = String::from_utf8_lossy(&git(&pub_work, &["rev-parse", "feature/x"]).stdout) | ||
| 500 | + .trim() | ||
| 501 | + .to_owned(); | ||
| 461 | let feature_tree = http.get("/tahinli/pub/tree/feature/x", None).await; | 502 | let feature_tree = http.get("/tahinli/pub/tree/feature/x", None).await; |
| 462 | assert_eq!(feature_tree.status, 200, "tree of feature/x"); | 503 | assert_eq!(feature_tree.status, 200, "tree of feature/x"); |
| 463 | assert!( | 504 | assert!( |
| 464 | feature_tree.body().contains("feature.txt"), | 505 | feature_tree.body().contains("feature.txt"), |
| 465 | "feature/x tree must list feature.txt" | 506 | "feature/x tree must list feature.txt" |
| 466 | ); | 507 | ); |
| 508 | + // The feature commit is the newest on feature/x, on top of the two-commit history. | ||
| 509 | + assert_latest_bar( | ||
| 510 | + &feature_tree.body(), | ||
| 511 | + "tree of feature/x", | ||
| 512 | + "feature commit", | ||
| 513 | + &feature_head, | ||
| 514 | + "2 commits", | ||
| 515 | + ); | ||
| 467 | 516 | ||
| 468 | let archive = http.get("/tahinli/pub/archive/main.tar.gz", None).await; | 517 | let archive = http.get("/tahinli/pub/archive/main.tar.gz", None).await; |
| 469 | assert_eq!(archive.status, 200, "tar.gz archive"); | 518 | assert_eq!(archive.status, 200, "tar.gz archive"); |
style/_repo.scssmodified+126 -0
| @@ -912,3 +912,129 @@ | |||
| 912 | flex-basis: 100%; | 912 | flex-basis: 100%; |
| 913 | } | 913 | } |
| 914 | } | 914 | } |
| 915 | + | ||
| 916 | +// Latest commit bar: the first row of the listing box (repo home and tree views). Its padding | ||
| 917 | +// matches the table cells, so the author sits over the Name column and the age over the Age | ||
| 918 | +// column. The subject takes the slack and ellipsizes; on phones it drops to its own line. | ||
| 919 | +.latest-commit { | ||
| 920 | + display: flex; | ||
| 921 | + flex-wrap: wrap; | ||
| 922 | + align-items: center; | ||
| 923 | + gap: 12px; | ||
| 924 | + min-width: 0; | ||
| 925 | + padding: 10px 0; | ||
| 926 | + font-size: 13.5px; | ||
| 927 | + color: var(--text); | ||
| 928 | + border-bottom: 1px solid var(--border); | ||
| 929 | + | ||
| 930 | + .latest-author { | ||
| 931 | + display: inline-flex; | ||
| 932 | + flex: 0 1 auto; | ||
| 933 | + align-items: center; | ||
| 934 | + gap: 8px; | ||
| 935 | + min-width: 0; | ||
| 936 | + max-width: 14rem; | ||
| 937 | + white-space: nowrap; | ||
| 938 | + | ||
| 939 | + .avatar { | ||
| 940 | + flex: none; | ||
| 941 | + width: 20px; | ||
| 942 | + height: 20px; | ||
| 943 | + margin-right: 0; | ||
| 944 | + } | ||
| 945 | + | ||
| 946 | + // Plain-text authors have no avatar: a neutral disc with the author's initial. | ||
| 947 | + .avatar-blank { | ||
| 948 | + display: inline-flex; | ||
| 949 | + align-items: center; | ||
| 950 | + justify-content: center; | ||
| 951 | + box-sizing: border-box; | ||
| 952 | + border: 1px solid var(--border); | ||
| 953 | + font-size: 11px; | ||
| 954 | + font-weight: 600; | ||
| 955 | + line-height: 1; | ||
| 956 | + color: var(--muted); | ||
| 957 | + } | ||
| 958 | + | ||
| 959 | + a, | ||
| 960 | + span:not(.avatar) { | ||
| 961 | + min-width: 0; | ||
| 962 | + overflow: hidden; | ||
| 963 | + text-overflow: ellipsis; | ||
| 964 | + font-weight: 600; | ||
| 965 | + color: var(--text); | ||
| 966 | + } | ||
| 967 | + | ||
| 968 | + a:hover { | ||
| 969 | + color: var(--accent-ink); | ||
| 970 | + text-decoration: none; | ||
| 971 | + } | ||
| 972 | + } | ||
| 973 | + | ||
| 974 | + .latest-subject { | ||
| 975 | + flex: 1 1 0; | ||
| 976 | + min-width: 0; | ||
| 977 | + overflow: hidden; | ||
| 978 | + text-overflow: ellipsis; | ||
| 979 | + white-space: nowrap; | ||
| 980 | + color: var(--text); | ||
| 981 | + | ||
| 982 | + &:hover { | ||
| 983 | + color: var(--accent-ink); | ||
| 984 | + text-decoration: none; | ||
| 985 | + } | ||
| 986 | + } | ||
| 987 | + | ||
| 988 | + .latest-meta { | ||
| 989 | + display: inline-flex; | ||
| 990 | + flex: none; | ||
| 991 | + align-items: center; | ||
| 992 | + gap: 14px; | ||
| 993 | + white-space: nowrap; | ||
| 994 | + font-size: 13px; | ||
| 995 | + color: var(--muted); | ||
| 996 | + } | ||
| 997 | + | ||
| 998 | + .latest-sha { | ||
| 999 | + font-size: 12.5px; | ||
| 1000 | + color: var(--muted); | ||
| 1001 | + | ||
| 1002 | + &:hover { | ||
| 1003 | + color: var(--accent-ink); | ||
| 1004 | + text-decoration: none; | ||
| 1005 | + } | ||
| 1006 | + } | ||
| 1007 | + | ||
| 1008 | + .latest-count { | ||
| 1009 | + display: inline-flex; | ||
| 1010 | + align-items: center; | ||
| 1011 | + gap: 5px; | ||
| 1012 | + color: var(--muted); | ||
| 1013 | + | ||
| 1014 | + &:hover { | ||
| 1015 | + color: var(--text); | ||
| 1016 | + text-decoration: none; | ||
| 1017 | + } | ||
| 1018 | + | ||
| 1019 | + .ico { | ||
| 1020 | + width: 15px; | ||
| 1021 | + height: 15px; | ||
| 1022 | + } | ||
| 1023 | + } | ||
| 1024 | +} | ||
| 1025 | + | ||
| 1026 | +@media (max-width: 600px) { | ||
| 1027 | + .latest-commit { | ||
| 1028 | + row-gap: 6px; | ||
| 1029 | + | ||
| 1030 | + .latest-subject { | ||
| 1031 | + order: 3; | ||
| 1032 | + flex: 1 1 100%; | ||
| 1033 | + } | ||
| 1034 | + | ||
| 1035 | + .latest-meta { | ||
| 1036 | + gap: 10px; | ||
| 1037 | + margin-left: auto; | ||
| 1038 | + } | ||
| 1039 | + } | ||
| 1040 | +} | ||