Commit messages are read as data: lists, the file tree and CI show a type tag, the first clause and +N, a commit page groups its clauses by type with the raw message one click away, and generated release notes get sections, while a message with no type shows as before
Browse files at this commite832da00e1a95c0f35c2996c2c382471d7f8135fParent: 8d87bc9- feat
- commit messages are read as data: lists, the file tree and CI show a type tag, the first clause and +N, a commit page groups its clauses by type with the raw message one click away, and generated release notes get sections, while a message with no type shows as before
- Needs you at /needs-you lists your failed runs, requested reviews, your pull requests with changes requested or approved, assigned issues and mentions
- lists work from the keyboard with j, k, Enter and x, and ? shows the keys
- the command palette lists the actions of the page you are on and posts them only through the server
- a failed run opens on its failing job and the log around the first error
- a running job shows the time left from past successful runs, or nothing with under three samples
- the pull Files tab marks files viewed per user, and a later change to a file clears its mark
- density and an optional finish sound are saved to the account
- style
- running jobs and pending checks follow the accent instead of yellow, CI bars grow to the server's width on a live update and new log lines fade in, both off for reduced motion
- the commit page and Appearance fit one screen
57 changed files +3590 -91
- crates/forge-core/migrations/0070_pull_viewed_files.sql +13 -0
- crates/forge-core/src/ci.rs +14 -0
- crates/forge-core/src/store/ci.rs +53 -1
- crates/forge-core/src/store/migrate.rs +1 -0
- crates/forge-core/src/store/mod.rs +2 -0
- crates/forge-core/src/store/needs.rs +244 -0
- crates/forge-core/src/store/pull_viewed.rs +133 -0
- crates/forge-core/src/store/user_prefs.rs +31 -0
- crates/forge-web/assets/nav.js +532 -9
- crates/forge-web/src/ci/release.rs +138 -9
- crates/forge-web/src/i18n/browse.rs +3 -0
- crates/forge-web/src/i18n/code.rs +8 -0
- crates/forge-web/src/i18n/misc.rs +65 -0
- crates/forge-web/src/i18n/mod.rs +1 -0
- crates/forge-web/src/i18n/needs.rs +44 -0
- crates/forge-web/src/i18n/pulls.rs +25 -0
- crates/forge-web/src/i18n/releases_ci.rs +44 -0
- crates/forge-web/src/pages/blame.rs +2 -1
- crates/forge-web/src/pages/branches.rs +2 -1
- crates/forge-web/src/pages/ci_estimate.rs +248 -0
- crates/forge-web/src/pages/ci_fail.rs +181 -0
- crates/forge-web/src/pages/ci_job.rs +6 -6
- crates/forge-web/src/pages/ci_runs.rs +113 -16
- crates/forge-web/src/pages/commit.rs +29 -2
- crates/forge-web/src/pages/commits.rs +3 -2
- crates/forge-web/src/pages/compare.rs +2 -1
- crates/forge-web/src/pages/finder.rs +1 -1
- crates/forge-web/src/pages/issue_parts.rs +3 -3
- crates/forge-web/src/pages/issues_list.rs +3 -3
- crates/forge-web/src/pages/mod.rs +3 -0
- crates/forge-web/src/pages/needs_you.rs +276 -0
- crates/forge-web/src/pages/notifications.rs +2 -2
- crates/forge-web/src/pages/palette.rs +3 -1
- crates/forge-web/src/pages/pull_files.rs +230 -8
- crates/forge-web/src/pages/pulls_list.rs +3 -3
- crates/forge-web/src/pages/refs.rs +2 -1
- crates/forge-web/src/pages/repo.rs +1 -1
- crates/forge-web/src/pages/repo_side.rs +44 -5
- crates/forge-web/src/pages/settings_appearance.rs +118 -3
- crates/forge-web/src/pages/tree.rs +2 -1
- crates/forge-web/src/render/commit_message.rs +213 -0
- crates/forge-web/src/render/mod.rs +1 -0
- crates/forge-web/src/views/commit_line.rs +50 -0
- crates/forge-web/src/views/mod.rs +12 -2
- crates/forge-web/src/views/repo_list.rs +1 -1
- style/_ci_estimate.scss +40 -0
- style/_commit_line.scss +39 -0
- style/_commit_page.scss +62 -0
- style/_density.scss +176 -0
- style/_fail_first.scss +77 -0
- style/_keyboard.scss +47 -0
- style/_live_motion.scss +35 -0
- style/_needs.scss +48 -0
- style/_palette.scss +9 -0
- style/_pull.scss +2 -2
- style/_review_flow.scss +130 -0
- style/main.scss +20 -6
crates/forge-core/migrations/0070_pull_viewed_files.sqladded+13 -0
| @@ -0,0 +1,13 @@ | |||
| 1 | +-- Files a signed-in reviewer marked Viewed on a pull request's Files tab. One row per user, pull | ||
| 2 | +-- request and path. `blob` is the file's blob id at the head when it was marked: a later push that | ||
| 3 | +-- changes the file no longer matches, and the page shows it as changed since it was viewed. Rows go | ||
| 4 | +-- with the user and with the pull request's issue (ON DELETE CASCADE). Applied by store/migrate.rs. | ||
| 5 | + | ||
| 6 | +CREATE TABLE pull_viewed_files ( | ||
| 7 | + user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE, | ||
| 8 | + issue_id TEXT NOT NULL REFERENCES issues(id) ON DELETE CASCADE, | ||
| 9 | + path TEXT NOT NULL, | ||
| 10 | + blob TEXT NOT NULL, | ||
| 11 | + viewed_at TEXT NOT NULL, | ||
| 12 | + PRIMARY KEY (user_id, issue_id, path) | ||
| 13 | +); | ||
crates/forge-core/src/ci.rsmodified+14 -0
| @@ -557,6 +557,20 @@ pub struct CiJob { | |||
| 557 | pub oom_kills: Option<u32>, | 557 | pub oom_kills: Option<u32>, |
| 558 | } | 558 | } |
| 559 | 559 | ||
| 560 | +/// One job's duration in a recent successful run of a repo, for the CI time estimate. Only the | ||
| 561 | +/// newest five successful runs per branch and per repo are sampled, so the ranks are 1 for the newest. | ||
| 562 | +#[derive(Debug, Clone, PartialEq, Eq)] | ||
| 563 | +pub struct JobSample { | ||
| 564 | + pub git_ref: String, | ||
| 565 | + /// The run's place among the repo's successful runs on its branch, newest first. | ||
| 566 | + pub branch_rank: i64, | ||
| 567 | + /// The run's place among the repo's successful runs on any branch, newest first. | ||
| 568 | + pub repo_rank: i64, | ||
| 569 | + pub job: String, | ||
| 570 | + /// The job's duration in seconds. | ||
| 571 | + pub secs: i64, | ||
| 572 | +} | ||
| 573 | + | ||
| 560 | /// A job of one runner, with the run and repo it belongs to, for the runner's admin page. The | 574 | /// A job of one runner, with the run and repo it belongs to, for the runner's admin page. The |
| 561 | /// run's page is `/{owner}/{repo}/ci/runs/{run_number}`. | 575 | /// run's page is `/{owner}/{repo}/ci/runs/{run_number}`. |
| 562 | #[derive(Debug, Clone, PartialEq, Eq)] | 576 | #[derive(Debug, Clone, PartialEq, Eq)] |
crates/forge-core/src/store/ci.rsmodified+53 -1
| @@ -14,7 +14,7 @@ use super::{ | |||
| 14 | finish, insert_err, missing_row, new_id, | 14 | finish, insert_err, missing_row, new_id, |
| 15 | }; | 15 | }; |
| 16 | use crate::ci::{ | 16 | use crate::ci::{ |
| 17 | - CiArtifact, CiJob, CiRun, CiRunner, FieldKind, JobState, MAX_RUNNER_CONCURRENCY, | 17 | + CiArtifact, CiJob, CiRun, CiRunner, FieldKind, JobSample, JobState, MAX_RUNNER_CONCURRENCY, |
| 18 | MIN_RUNNER_CONCURRENCY, MemoryOffer, NewJob, QueueSkips, RestartMode, RunState, RunnerJob, | 18 | MIN_RUNNER_CONCURRENCY, MemoryOffer, NewJob, QueueSkips, RestartMode, RunState, RunnerJob, |
| 19 | RunnerReport, RunnerRestart, STARVE_AFTER_SECS, pick_by_memory, validate_runner_field, | 19 | RunnerReport, RunnerRestart, STARVE_AFTER_SECS, pick_by_memory, validate_runner_field, |
| 20 | }; | 20 | }; |
| @@ -1678,6 +1678,58 @@ impl Store { | |||
| 1678 | jobs_of_run(&conn, run_id).await | 1678 | jobs_of_run(&conn, run_id).await |
| 1679 | } | 1679 | } |
| 1680 | 1680 | ||
| 1681 | + /// The durations of finished jobs that the CI time estimate learns from: each successful run's | ||
| 1682 | + /// jobs for the newest five successful runs of each branch in `git_refs`, and for the newest five | ||
| 1683 | + /// successful runs on any branch. One query, bounded by the refs given. | ||
| 1684 | + pub async fn recent_job_samples( | ||
| 1685 | + &self, | ||
| 1686 | + repo_id: &str, | ||
| 1687 | + git_refs: &[String], | ||
| 1688 | + ) -> Result<Vec<JobSample>> { | ||
| 1689 | + let mut params: Vec<Value> = Vec::with_capacity(git_refs.len() + 1); | ||
| 1690 | + params.push(Value::Text(repo_id.to_string())); | ||
| 1691 | + params.extend(git_refs.iter().map(|git_ref| Value::Text(git_ref.clone()))); | ||
| 1692 | + let scope = if git_refs.is_empty() { | ||
| 1693 | + "done.repo_rank <= 5".to_owned() | ||
| 1694 | + } else { | ||
| 1695 | + let marks: Vec<String> = (2..=git_refs.len() + 1).map(|i| format!("?{i}")).collect(); | ||
| 1696 | + format!( | ||
| 1697 | + "(done.branch_rank <= 5 AND done.git_ref IN ({})) OR done.repo_rank <= 5", | ||
| 1698 | + marks.join(", ") | ||
| 1699 | + ) | ||
| 1700 | + }; | ||
| 1701 | + let sql = format!( | ||
| 1702 | + "WITH done AS ( \ | ||
| 1703 | + SELECT id, git_ref, \ | ||
| 1704 | + ROW_NUMBER() OVER (PARTITION BY git_ref ORDER BY number DESC) AS branch_rank, \ | ||
| 1705 | + ROW_NUMBER() OVER (ORDER BY number DESC) AS repo_rank \ | ||
| 1706 | + FROM ci_runs WHERE repo_id = ?1 AND state = 'success' \ | ||
| 1707 | + ) \ | ||
| 1708 | + SELECT done.git_ref, done.branch_rank, done.repo_rank, j.name, j.started_at, \ | ||
| 1709 | + j.finished_at \ | ||
| 1710 | + FROM done JOIN ci_jobs j ON j.run_id = done.id \ | ||
| 1711 | + WHERE ({scope}) \ | ||
| 1712 | + AND j.state = 'success' AND j.started_at IS NOT NULL AND j.finished_at IS NOT NULL" | ||
| 1713 | + ); | ||
| 1714 | + let conn = self.read_conn().await; | ||
| 1715 | + let rows = fetch_all(&conn, &sql, params, |row| { | ||
| 1716 | + let started = col_opt_text(row, 4)?.as_deref().and_then(stamp_to_unix); | ||
| 1717 | + let finished = col_opt_text(row, 5)?.as_deref().and_then(stamp_to_unix); | ||
| 1718 | + Ok(match (started, finished) { | ||
| 1719 | + (Some(start), Some(end)) => Some(JobSample { | ||
| 1720 | + git_ref: col_text(row, 0)?, | ||
| 1721 | + branch_rank: col_int(row, 1)?, | ||
| 1722 | + repo_rank: col_int(row, 2)?, | ||
| 1723 | + job: col_text(row, 3)?, | ||
| 1724 | + secs: (end - start).max(0), | ||
| 1725 | + }), | ||
| 1726 | + _ => None, | ||
| 1727 | + }) | ||
| 1728 | + }) | ||
| 1729 | + .await?; | ||
| 1730 | + Ok(rows.into_iter().flatten().collect()) | ||
| 1731 | + } | ||
| 1732 | + | ||
| 1681 | /// The jobs a runner holds or held: every running one, then its `recent` newest finished jobs | 1733 | /// The jobs a runner holds or held: every running one, then its `recent` newest finished jobs |
| 1682 | /// (by start time). Each carries its run's number and its repo's owner and name. | 1734 | /// (by start time). Each carries its run's number and its repo's owner and name. |
| 1683 | pub async fn runner_jobs(&self, runner_id: &str, recent: usize) -> Result<Vec<RunnerJob>> { | 1735 | pub async fn runner_jobs(&self, runner_id: &str, recent: usize) -> Result<Vec<RunnerJob>> { |
crates/forge-core/src/store/migrate.rsmodified+1 -0
| @@ -109,6 +109,7 @@ pub const MIGRATIONS: &[(u32, &str)] = &[ | |||
| 109 | (67, include_str!("../../migrations/0067_coauthored_commits.sql")), | 109 | (67, include_str!("../../migrations/0067_coauthored_commits.sql")), |
| 110 | (68, include_str!("../../migrations/0068_ci_jobs_runner.sql")), | 110 | (68, include_str!("../../migrations/0068_ci_jobs_runner.sql")), |
| 111 | (69, include_str!("../../migrations/0069_user_prefs.sql")), | 111 | (69, include_str!("../../migrations/0069_user_prefs.sql")), |
| 112 | + (70, include_str!("../../migrations/0070_pull_viewed_files.sql")), | ||
| 112 | ]; | 113 | ]; |
| 113 | 114 | ||
| 114 | /// The highest migration version this binary knows about. | 115 | /// The highest migration version this binary knows about. |
crates/forge-core/src/store/mod.rsmodified+2 -0
| @@ -21,6 +21,7 @@ pub mod mail; | |||
| 21 | pub mod merge_queue; | 21 | pub mod merge_queue; |
| 22 | pub mod migrate; | 22 | pub mod migrate; |
| 23 | pub mod mirrors; | 23 | pub mod mirrors; |
| 24 | +pub mod needs; | ||
| 24 | pub mod notifications; | 25 | pub mod notifications; |
| 25 | pub mod notifications_extra; | 26 | pub mod notifications_extra; |
| 26 | pub mod oci; | 27 | pub mod oci; |
| @@ -29,6 +30,7 @@ pub mod packages; | |||
| 29 | pub mod passkeys; | 30 | pub mod passkeys; |
| 30 | pub mod pinned; | 31 | pub mod pinned; |
| 31 | pub mod profile_pins; | 32 | pub mod profile_pins; |
| 33 | +pub mod pull_viewed; | ||
| 32 | pub mod pulls; | 34 | pub mod pulls; |
| 33 | pub mod pulls_list_extra; | 35 | pub mod pulls_list_extra; |
| 34 | pub mod push_recent; | 36 | pub mod push_recent; |
crates/forge-core/src/store/needs.rsadded+244 -0
| @@ -0,0 +1,244 @@ | |||
| 1 | +//! What is waiting on the signed-in user, for the `/needs-you` page: their failing CI runs, their | ||
| 2 | +//! own open pull requests that carry a review verdict, and their assigned open issues. Reads only. | ||
| 3 | +//! Every query applies the viewer's readable-repo rule (`readable_repo`), as the other per-user | ||
| 4 | +//! lists do. Review requests and mentions come from `review_requests_for_user` and `waiting_on`. | ||
| 5 | + | ||
| 6 | +use std::time::Duration; | ||
| 7 | + | ||
| 8 | +use turso::Value; | ||
| 9 | + | ||
| 10 | +use super::notifications::{readable_params, readable_repo}; | ||
| 11 | +use super::{Store, col_int, col_text, fetch_all}; | ||
| 12 | +use crate::error::Result; | ||
| 13 | +use crate::time::stamp_ago; | ||
| 14 | + | ||
| 15 | +/// How far back a failing run counts. The same window as the profile corner's failing count. | ||
| 16 | +const FAILING_WINDOW: Duration = Duration::from_secs(7 * 24 * 60 * 60); | ||
| 17 | + | ||
| 18 | +/// A ref whose newest run by the user failed within `FAILING_WINDOW`. | ||
| 19 | +#[derive(Debug, Clone)] | ||
| 20 | +pub struct FailingRun { | ||
| 21 | + /// Owner username of the repo. | ||
| 22 | + pub owner: String, | ||
| 23 | + /// Repo name. | ||
| 24 | + pub repo: String, | ||
| 25 | + /// Run number within the repo. | ||
| 26 | + pub number: i64, | ||
| 27 | + /// Git ref the run ran on. | ||
| 28 | + pub git_ref: String, | ||
| 29 | + /// When the run was created. | ||
| 30 | + pub created_at: String, | ||
| 31 | +} | ||
| 32 | + | ||
| 33 | +/// The review verdict on a pull request. Changes requested wins over approval. | ||
| 34 | +#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| 35 | +pub enum Verdict { | ||
| 36 | + ChangesRequested, | ||
| 37 | + Approved, | ||
| 38 | +} | ||
| 39 | + | ||
| 40 | +/// An open pull request the user authored, with a review verdict. | ||
| 41 | +#[derive(Debug, Clone)] | ||
| 42 | +pub struct OwnPull { | ||
| 43 | + /// Owner username of the repo. | ||
| 44 | + pub owner: String, | ||
| 45 | + /// Repo name. | ||
| 46 | + pub repo: String, | ||
| 47 | + /// Pull request number. | ||
| 48 | + pub number: i64, | ||
| 49 | + /// Title of the pull request. | ||
| 50 | + pub title: String, | ||
| 51 | + /// The verdict from `review_summary`. | ||
| 52 | + pub verdict: Verdict, | ||
| 53 | + /// When the pull request last changed. | ||
| 54 | + pub updated_at: String, | ||
| 55 | +} | ||
| 56 | + | ||
| 57 | +/// An open issue assigned to the user. | ||
| 58 | +#[derive(Debug, Clone)] | ||
| 59 | +pub struct AssignedIssue { | ||
| 60 | + /// Owner username of the repo. | ||
| 61 | + pub owner: String, | ||
| 62 | + /// Repo name. | ||
| 63 | + pub repo: String, | ||
| 64 | + /// Issue number. | ||
| 65 | + pub number: i64, | ||
| 66 | + /// Title of the issue. | ||
| 67 | + pub title: String, | ||
| 68 | + /// When the issue last changed. | ||
| 69 | + pub updated_at: String, | ||
| 70 | +} | ||
| 71 | + | ||
| 72 | +impl Store { | ||
| 73 | + /// The user's newest run per (repo, ref) when it failed within the failing window, newest | ||
| 74 | + /// first, at most `limit`. Runs in repos the user cannot read are left out. | ||
| 75 | + pub async fn failing_runs(&self, actor_id: &str, limit: i64) -> Result<Vec<FailingRun>> { | ||
| 76 | + let readable = readable_repo(); | ||
| 77 | + let mut params = vec![Value::Text(actor_id.to_string())]; | ||
| 78 | + params.extend(readable_params(actor_id)); | ||
| 79 | + params.push(Value::Text(stamp_ago(FAILING_WINDOW))); | ||
| 80 | + params.push(Value::Integer(limit)); | ||
| 81 | + let conn = self.read_conn().await; | ||
| 82 | + fetch_all( | ||
| 83 | + &conn, | ||
| 84 | + &format!( | ||
| 85 | + "SELECT owner, name, number, git_ref, created_at FROM ( \ | ||
| 86 | + SELECT ci_runs.state, ci_runs.created_at, ci_runs.number, ci_runs.git_ref, \ | ||
| 87 | + o.username AS owner, r.name AS name, ROW_NUMBER() OVER ( \ | ||
| 88 | + PARTITION BY ci_runs.repo_id, ci_runs.git_ref ORDER BY ci_runs.number DESC) AS rn \ | ||
| 89 | + FROM ci_runs JOIN repos r ON r.id = ci_runs.repo_id \ | ||
| 90 | + JOIN users o ON o.id = r.owner_id \ | ||
| 91 | + WHERE ci_runs.actor_id = ? AND {readable} \ | ||
| 92 | + ) WHERE rn = 1 AND state IN ('failure', 'error') AND created_at >= ? \ | ||
| 93 | + ORDER BY created_at DESC, number DESC LIMIT ?" | ||
| 94 | + ), | ||
| 95 | + params, | ||
| 96 | + |row| { | ||
| 97 | + Ok(FailingRun { | ||
| 98 | + owner: col_text(row, 0)?, | ||
| 99 | + repo: col_text(row, 1)?, | ||
| 100 | + number: col_int(row, 2)?, | ||
| 101 | + git_ref: col_text(row, 3)?, | ||
| 102 | + created_at: col_text(row, 4)?, | ||
| 103 | + }) | ||
| 104 | + }, | ||
| 105 | + ) | ||
| 106 | + .await | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + /// Open pull requests the user authored that have a changes-requested or an approving review, | ||
| 110 | + /// newest first, at most `limit`. The verdict is `review_summary`'s, so a pull with a change | ||
| 111 | + /// request is listed as such even when someone else approved it. Pulls in repos the user cannot | ||
| 112 | + /// read are left out. | ||
| 113 | + pub async fn own_pulls_with_verdict( | ||
| 114 | + &self, | ||
| 115 | + author_id: &str, | ||
| 116 | + limit: usize, | ||
| 117 | + ) -> Result<Vec<OwnPull>> { | ||
| 118 | + let readable = readable_repo(); | ||
| 119 | + let mut params = vec![Value::Text(author_id.to_string())]; | ||
| 120 | + params.extend(readable_params(author_id)); | ||
| 121 | + // Candidates: the pulls with at least one approving or changes-requesting review. Each is | ||
| 122 | + // then checked with `review_summary`, which ignores dismissed and comment-only reviews. | ||
| 123 | + let candidates = { | ||
| 124 | + let conn = self.read_conn().await; | ||
| 125 | + fetch_all( | ||
| 126 | + &conn, | ||
| 127 | + &format!( | ||
| 128 | + "SELECT i.id, o.username, r.name, i.number, i.title, i.updated_at FROM issues i \ | ||
| 129 | + JOIN repos r ON r.id = i.repo_id \ | ||
| 130 | + JOIN users o ON o.id = r.owner_id \ | ||
| 131 | + WHERE i.kind = 'pull' AND i.state = 'open' AND i.author_id = ? AND {readable} \ | ||
| 132 | + AND EXISTS (SELECT 1 FROM pull_reviews pr WHERE pr.issue_id = i.id \ | ||
| 133 | + AND pr.state IN ('approved', 'changes_requested')) \ | ||
| 134 | + ORDER BY i.updated_at DESC, i.number DESC" | ||
| 135 | + ), | ||
| 136 | + params, | ||
| 137 | + |row| { | ||
| 138 | + Ok(( | ||
| 139 | + col_text(row, 0)?, | ||
| 140 | + col_text(row, 1)?, | ||
| 141 | + col_text(row, 2)?, | ||
| 142 | + col_int(row, 3)?, | ||
| 143 | + col_text(row, 4)?, | ||
| 144 | + col_text(row, 5)?, | ||
| 145 | + )) | ||
| 146 | + }, | ||
| 147 | + ) | ||
| 148 | + .await? | ||
| 149 | + }; | ||
| 150 | + | ||
| 151 | + let mut out = Vec::new(); | ||
| 152 | + for (id, owner, repo, number, title, updated_at) in candidates { | ||
| 153 | + if out.len() >= limit { | ||
| 154 | + break; | ||
| 155 | + } | ||
| 156 | + let summary = self.review_summary(&id).await?; | ||
| 157 | + let verdict = if !summary.changes_requested_by.is_empty() { | ||
| 158 | + Verdict::ChangesRequested | ||
| 159 | + } else if !summary.approved_by.is_empty() { | ||
| 160 | + Verdict::Approved | ||
| 161 | + } else { | ||
| 162 | + continue; | ||
| 163 | + }; | ||
| 164 | + out.push(OwnPull { | ||
| 165 | + owner, | ||
| 166 | + repo, | ||
| 167 | + number, | ||
| 168 | + title, | ||
| 169 | + verdict, | ||
| 170 | + updated_at, | ||
| 171 | + }); | ||
| 172 | + } | ||
| 173 | + Ok(out) | ||
| 174 | + } | ||
| 175 | + | ||
| 176 | + /// Open issues assigned to the user, newest first, at most `limit`. Pull requests are not | ||
| 177 | + /// listed. Issues in repos the user cannot read are left out. | ||
| 178 | + pub async fn assigned_issues(&self, user_id: &str, limit: i64) -> Result<Vec<AssignedIssue>> { | ||
| 179 | + let readable = readable_repo(); | ||
| 180 | + let mut params = vec![Value::Text(user_id.to_string())]; | ||
| 181 | + params.extend(readable_params(user_id)); | ||
| 182 | + params.push(Value::Integer(limit)); | ||
| 183 | + let conn = self.read_conn().await; | ||
| 184 | + fetch_all( | ||
| 185 | + &conn, | ||
| 186 | + &format!( | ||
| 187 | + "SELECT o.username, r.name, i.number, i.title, i.updated_at FROM issue_assignees ia \ | ||
| 188 | + JOIN issues i ON i.id = ia.issue_id AND i.kind = 'issue' AND i.state = 'open' \ | ||
| 189 | + JOIN repos r ON r.id = i.repo_id \ | ||
| 190 | + JOIN users o ON o.id = r.owner_id \ | ||
| 191 | + WHERE ia.user_id = ? AND {readable} \ | ||
| 192 | + ORDER BY i.updated_at DESC, i.number DESC LIMIT ?" | ||
| 193 | + ), | ||
| 194 | + params, | ||
| 195 | + |row| { | ||
| 196 | + Ok(AssignedIssue { | ||
| 197 | + owner: col_text(row, 0)?, | ||
| 198 | + repo: col_text(row, 1)?, | ||
| 199 | + number: col_int(row, 2)?, | ||
| 200 | + title: col_text(row, 3)?, | ||
| 201 | + updated_at: col_text(row, 4)?, | ||
| 202 | + }) | ||
| 203 | + }, | ||
| 204 | + ) | ||
| 205 | + .await | ||
| 206 | + } | ||
| 207 | +} | ||
| 208 | + | ||
| 209 | +#[cfg(test)] | ||
| 210 | +mod tests { | ||
| 211 | + use super::*; | ||
| 212 | + use crate::model::Visibility; | ||
| 213 | + | ||
| 214 | + #[tokio::test] | ||
| 215 | + async fn assigned_issues_hide_a_repo_the_viewer_cannot_read() { | ||
| 216 | + let dir = tempfile::tempdir().unwrap(); | ||
| 217 | + let store = Store::open(&dir.path().join("forge.db")).await.unwrap(); | ||
| 218 | + let tahinli = store | ||
| 219 | + .create_user("tahinli", None, "hash", false) | ||
| 220 | + .await | ||
| 221 | + .unwrap(); | ||
| 222 | + let bob = store.create_user("bob", None, "hash", false).await.unwrap(); | ||
| 223 | + let repo = store | ||
| 224 | + .create_repo(&tahinli.id, "proj", "", Visibility::Public, "main") | ||
| 225 | + .await | ||
| 226 | + .unwrap(); | ||
| 227 | + let issue = store | ||
| 228 | + .create_issue(&repo.id, &tahinli.id, "bug", "") | ||
| 229 | + .await | ||
| 230 | + .unwrap(); | ||
| 231 | + store | ||
| 232 | + .set_issue_assignees(&issue.id, &tahinli.id, &["bob".to_string()]) | ||
| 233 | + .await | ||
| 234 | + .unwrap(); | ||
| 235 | + assert_eq!(store.assigned_issues(&bob.id, 8).await.unwrap().len(), 1); | ||
| 236 | + | ||
| 237 | + // Once the repo is private and bob is not a collaborator, the assignment stays but is hidden. | ||
| 238 | + store | ||
| 239 | + .set_repo_visibility(&repo.id, Visibility::Private) | ||
| 240 | + .await | ||
| 241 | + .unwrap(); | ||
| 242 | + assert!(store.assigned_issues(&bob.id, 8).await.unwrap().is_empty()); | ||
| 243 | + } | ||
| 244 | +} | ||
crates/forge-core/src/store/pull_viewed.rsadded+133 -0
| @@ -0,0 +1,133 @@ | |||
| 1 | +//! Files a reviewer marked Viewed on a pull request's Files tab (migration 0070). One row per user, | ||
| 2 | +//! pull request and path, holding the blob id the mark was made for. The web layer compares that | ||
| 3 | +//! blob with the file's current one; this store only keeps the rows. Rows go with the user and | ||
| 4 | +//! with the pull request's issue (ON DELETE CASCADE). | ||
| 5 | + | ||
| 6 | +use std::collections::HashMap; | ||
| 7 | + | ||
| 8 | +use super::{Store, col_text, db_err, fetch_all}; | ||
| 9 | +use crate::error::Result; | ||
| 10 | +use crate::time::now_stamp; | ||
| 11 | + | ||
| 12 | +impl Store { | ||
| 13 | + /// The viewer's marks on one pull request as `path -> blob`. | ||
| 14 | + pub async fn pull_viewed_files( | ||
| 15 | + &self, | ||
| 16 | + user_id: &str, | ||
| 17 | + issue_id: &str, | ||
| 18 | + ) -> Result<HashMap<String, String>> { | ||
| 19 | + let conn = self.read_conn().await; | ||
| 20 | + let rows = fetch_all( | ||
| 21 | + &conn, | ||
| 22 | + "SELECT path, blob FROM pull_viewed_files WHERE user_id = ?1 AND issue_id = ?2", | ||
| 23 | + (user_id.to_string(), issue_id.to_string()), | ||
| 24 | + |row| Ok((col_text(row, 0)?, col_text(row, 1)?)), | ||
| 25 | + ) | ||
| 26 | + .await?; | ||
| 27 | + Ok(rows.into_iter().collect()) | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + /// Marks `path` viewed at `blob`, replacing an earlier mark of the same path. | ||
| 31 | + pub async fn set_pull_file_viewed( | ||
| 32 | + &self, | ||
| 33 | + user_id: &str, | ||
| 34 | + issue_id: &str, | ||
| 35 | + path: &str, | ||
| 36 | + blob: &str, | ||
| 37 | + ) -> Result<()> { | ||
| 38 | + let conn = self.inner.conn.lock().await; | ||
| 39 | + conn.execute( | ||
| 40 | + "INSERT INTO pull_viewed_files (user_id, issue_id, path, blob, viewed_at) \ | ||
| 41 | + VALUES (?1, ?2, ?3, ?4, ?5) \ | ||
| 42 | + ON CONFLICT (user_id, issue_id, path) DO UPDATE SET \ | ||
| 43 | + blob = excluded.blob, viewed_at = excluded.viewed_at", | ||
| 44 | + ( | ||
| 45 | + user_id.to_string(), | ||
| 46 | + issue_id.to_string(), | ||
| 47 | + path.to_string(), | ||
| 48 | + blob.to_string(), | ||
| 49 | + now_stamp(), | ||
| 50 | + ), | ||
| 51 | + ) | ||
| 52 | + .await | ||
| 53 | + .map_err(db_err)?; | ||
| 54 | + Ok(()) | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + /// Removes the viewer's mark on `path`. A path that was never marked is not an error. | ||
| 58 | + pub async fn clear_pull_file_viewed( | ||
| 59 | + &self, | ||
| 60 | + user_id: &str, | ||
| 61 | + issue_id: &str, | ||
| 62 | + path: &str, | ||
| 63 | + ) -> Result<()> { | ||
| 64 | + let conn = self.inner.conn.lock().await; | ||
| 65 | + conn.execute( | ||
| 66 | + "DELETE FROM pull_viewed_files WHERE user_id = ?1 AND issue_id = ?2 AND path = ?3", | ||
| 67 | + ( | ||
| 68 | + user_id.to_string(), | ||
| 69 | + issue_id.to_string(), | ||
| 70 | + path.to_string(), | ||
| 71 | + ), | ||
| 72 | + ) | ||
| 73 | + .await | ||
| 74 | + .map_err(db_err)?; | ||
| 75 | + Ok(()) | ||
| 76 | + } | ||
| 77 | +} | ||
| 78 | + | ||
| 79 | +#[cfg(test)] | ||
| 80 | +mod tests { | ||
| 81 | + use super::*; | ||
| 82 | + use crate::Visibility; | ||
| 83 | + | ||
| 84 | + #[tokio::test] | ||
| 85 | + async fn marks_are_per_user_and_replaced_by_the_newer_blob() { | ||
| 86 | + let dir = tempfile::tempdir().unwrap(); | ||
| 87 | + let store = Store::open(&dir.path().join("forge.db")).await.unwrap(); | ||
| 88 | + let alice = store | ||
| 89 | + .create_user("alice", None, "hash", false) | ||
| 90 | + .await | ||
| 91 | + .unwrap(); | ||
| 92 | + let bob = store.create_user("bob", None, "hash", false).await.unwrap(); | ||
| 93 | + let repo = store | ||
| 94 | + .create_repo(&alice.id, "app", "", Visibility::Public, "main") | ||
| 95 | + .await | ||
| 96 | + .unwrap(); | ||
| 97 | + let issue = store | ||
| 98 | + .create_issue(&repo.id, &alice.id, "Change", "") | ||
| 99 | + .await | ||
| 100 | + .unwrap(); | ||
| 101 | + | ||
| 102 | + store | ||
| 103 | + .set_pull_file_viewed(&alice.id, &issue.id, "src/a.rs", "old") | ||
| 104 | + .await | ||
| 105 | + .unwrap(); | ||
| 106 | + store | ||
| 107 | + .set_pull_file_viewed(&alice.id, &issue.id, "src/a.rs", "new") | ||
| 108 | + .await | ||
| 109 | + .unwrap(); | ||
| 110 | + let marks = store.pull_viewed_files(&alice.id, &issue.id).await.unwrap(); | ||
| 111 | + assert_eq!(marks.len(), 1); | ||
| 112 | + assert_eq!(marks.get("src/a.rs").map(String::as_str), Some("new")); | ||
| 113 | + assert!( | ||
| 114 | + store | ||
| 115 | + .pull_viewed_files(&bob.id, &issue.id) | ||
| 116 | + .await | ||
| 117 | + .unwrap() | ||
| 118 | + .is_empty() | ||
| 119 | + ); | ||
| 120 | + | ||
| 121 | + store | ||
| 122 | + .clear_pull_file_viewed(&alice.id, &issue.id, "src/a.rs") | ||
| 123 | + .await | ||
| 124 | + .unwrap(); | ||
| 125 | + assert!( | ||
| 126 | + store | ||
| 127 | + .pull_viewed_files(&alice.id, &issue.id) | ||
| 128 | + .await | ||
| 129 | + .unwrap() | ||
| 130 | + .is_empty() | ||
| 131 | + ); | ||
| 132 | + } | ||
| 133 | +} | ||
crates/forge-core/src/store/user_prefs.rsmodified+31 -0
| @@ -8,6 +8,15 @@ use super::{Store, col_text, db_err, fetch_all}; | |||
| 8 | use crate::error::Result; | 8 | use crate::error::Result; |
| 9 | use crate::time::now_stamp; | 9 | use crate::time::now_stamp; |
| 10 | 10 | ||
| 11 | +/// Key of the row density: `comfortable` (the default, no row) or `compact`. | ||
| 12 | +pub const DENSITY: &str = "density"; | ||
| 13 | +/// The densities a user may store. | ||
| 14 | +pub const DENSITIES: &[&str] = &["comfortable", "compact"]; | ||
| 15 | +/// Key of the run-finished tone: `on` or `off` (the default, no row). | ||
| 16 | +pub const SOUND: &str = "sound"; | ||
| 17 | +/// The sound values a user may store. | ||
| 18 | +pub const SOUND_VALUES: &[&str] = &["on", "off"]; | ||
| 19 | + | ||
| 11 | impl Store { | 20 | impl Store { |
| 12 | /// All of a user's preferences as `key -> value`. | 21 | /// All of a user's preferences as `key -> value`. |
| 13 | pub async fn user_prefs(&self, user_id: &str) -> Result<HashMap<String, String>> { | 22 | pub async fn user_prefs(&self, user_id: &str) -> Result<HashMap<String, String>> { |
| @@ -53,3 +62,25 @@ impl Store { | |||
| 53 | Ok(()) | 62 | Ok(()) |
| 54 | } | 63 | } |
| 55 | } | 64 | } |
| 65 | + | ||
| 66 | +#[cfg(test)] | ||
| 67 | +mod tests { | ||
| 68 | + use super::*; | ||
| 69 | + use crate::store::Store; | ||
| 70 | + | ||
| 71 | + #[tokio::test] | ||
| 72 | + async fn density_and_sound_round_trip_and_replace() { | ||
| 73 | + let dir = tempfile::tempdir().unwrap(); | ||
| 74 | + let store = Store::open(&dir.path().join("forge.db")).await.unwrap(); | ||
| 75 | + let user = store.create_user("tahinli", None, "unused", false).await.unwrap(); | ||
| 76 | + | ||
| 77 | + assert!(store.user_prefs(&user.id).await.unwrap().is_empty()); | ||
| 78 | + store.set_user_pref(&user.id, DENSITY, "compact").await.unwrap(); | ||
| 79 | + store.set_user_pref(&user.id, SOUND, "on").await.unwrap(); | ||
| 80 | + store.set_user_pref(&user.id, DENSITY, "comfortable").await.unwrap(); | ||
| 81 | + | ||
| 82 | + let prefs = store.user_prefs(&user.id).await.unwrap(); | ||
| 83 | + assert_eq!(prefs.get(DENSITY).map(String::as_str), Some("comfortable")); | ||
| 84 | + assert_eq!(prefs.get(SOUND).map(String::as_str), Some("on")); | ||
| 85 | + } | ||
| 86 | +} | ||
crates/forge-web/assets/nav.jsmodified+532 -9
| @@ -332,8 +332,10 @@ | |||
| 332 | var listTop = how === 'live' && oldList ? oldList.scrollTop : null; | 332 | var listTop = how === 'live' && oldList ? oldList.scrollTop : null; |
| 333 | // A fit pane keeps its scroll when the page stays put (a live change, a post, a filter), by its place in the page. | 333 | // A fit pane keeps its scroll when the page stays put (a live change, a post, a filter), by its place in the page. |
| 334 | var paneTops = how === 'live' || how === 'post' || how === 'query' ? paneScrolls() : null; | 334 | var paneTops = how === 'live' || how === 'post' || how === 'query' ? paneScrolls() : null; |
| 335 | + var bars = how === 'live' ? barSegments() : null; | ||
| 335 | adopt(doc, keepFields, dd, how === 'live' ? captureJobs() : null); | 336 | adopt(doc, keepFields, dd, how === 'live' ? captureJobs() : null); |
| 336 | placeRun(listTop); | 337 | placeRun(listTop); |
| 338 | + if (bars) { growBars(bars); } | ||
| 337 | if (paneTops) { setPaneScrolls(paneTops); } | 339 | if (paneTops) { setPaneScrolls(paneTops); } |
| 338 | if (tailAt) { | 340 | if (tailAt) { |
| 339 | var nextTail = document.querySelector('[data-live-log]'); | 341 | var nextTail = document.querySelector('[data-live-log]'); |
| @@ -391,6 +393,47 @@ | |||
| 391 | }); | 393 | }); |
| 392 | } | 394 | } |
| 393 | 395 | ||
| 396 | + // A live swap replaces the run list's bars, so a running job's segment would jump to its new width. | ||
| 397 | + // The old width of each segment is kept by its key (the run's link and the job's id); the new | ||
| 398 | + // element starts at that width and moves to the one the server sent, in the CSS transition of | ||
| 399 | + // .live-grow. A segment whose start moved (the ticker's rest box) is not carried. | ||
| 400 | + function motionHeld() { | ||
| 401 | + return !!(reducedMotion && reducedMotion.matches); | ||
| 402 | + } | ||
| 403 | + | ||
| 404 | + function barKey(el) { | ||
| 405 | + var row = el.closest('.ci-row'); | ||
| 406 | + return row ? row.getAttribute('href') + '|' + el.getAttribute('data-key') : null; | ||
| 407 | + } | ||
| 408 | + | ||
| 409 | + function barSegments() { | ||
| 410 | + if (motionHeld()) { return null; } | ||
| 411 | + var old = {}; | ||
| 412 | + Array.prototype.forEach.call(document.querySelectorAll('.ci-run-list .ci-seg[data-key]'), function (el) { | ||
| 413 | + var key = barKey(el); | ||
| 414 | + if (key) { old[key] = { x: el.getAttribute('x'), w: parseFloat(el.getAttribute('width')) || 0 }; } | ||
| 415 | + }); | ||
| 416 | + return old; | ||
| 417 | + } | ||
| 418 | + | ||
| 419 | + function growBars(old) { | ||
| 420 | + Array.prototype.forEach.call(document.querySelectorAll('.ci-run-list .ci-seg[data-key]'), function (el) { | ||
| 421 | + var key = barKey(el); | ||
| 422 | + var was = key ? old[key] : null; | ||
| 423 | + if (!was || el.getAttribute('x') !== was.x) { return; } | ||
| 424 | + var to = parseFloat(el.getAttribute('width')) || 0; | ||
| 425 | + if (Math.abs(to - was.w) < 0.5) { return; } | ||
| 426 | + el.classList.add('live-grow'); | ||
| 427 | + el.style.width = was.w + 'px'; | ||
| 428 | + el.getBoundingClientRect(); | ||
| 429 | + el.style.width = to + 'px'; | ||
| 430 | + setTimeout(function () { | ||
| 431 | + el.classList.remove('live-grow'); | ||
| 432 | + el.style.width = ''; | ||
| 433 | + }, 650); | ||
| 434 | + }); | ||
| 435 | + } | ||
| 436 | + | ||
| 394 | // The runs list scrolls inside its card: bring the selected row into view there. scrollIntoView | 437 | // The runs list scrolls inside its card: bring the selected row into view there. scrollIntoView |
| 395 | // would also scroll the page, so the list's own scrollTop is set instead. | 438 | // would also scroll the page, so the list's own scrollTop is set instead. |
| 396 | function placeRun(keepTop) { | 439 | function placeRun(keepTop) { |
| @@ -2436,6 +2479,7 @@ | |||
| 2436 | clearTimeout(activityTimer); | 2479 | clearTimeout(activityTimer); |
| 2437 | activityTimer = null; | 2480 | activityTimer = null; |
| 2438 | if (json.finished && json.finished.length) { activityTimer = setTimeout(refreshActivity, 30000); } | 2481 | if (json.finished && json.finished.length) { activityTimer = setTimeout(refreshActivity, 30000); } |
| 2482 | + soundFromActivity(json); | ||
| 2439 | } | 2483 | } |
| 2440 | 2484 | ||
| 2441 | // Fetches the activity JSON and draws it. Only the newest answer is drawn. A failed fetch leaves | 2485 | // Fetches the activity JSON and draws it. Only the newest answer is drawn. A failed fetch leaves |
| @@ -2451,6 +2495,98 @@ | |||
| 2451 | }).catch(function () { }); | 2495 | }).catch(function () { }); |
| 2452 | } | 2496 | } |
| 2453 | 2497 | ||
| 2498 | + // ---- run tones ---------------------------------------------------------------------------------- | ||
| 2499 | + // Two tones, made with Web Audio, when one of the viewer's own CI runs passes or fails (the | ||
| 2500 | + // activity JSON's `finished` list). Only when the account's sound switch is on (`data-sound="on"` | ||
| 2501 | + // on <html>). The first answer on a page only records the runs already finished, so a page load | ||
| 2502 | + // never replays them. A cancelled run makes no sound, nor does a visible tab on that run's page. | ||
| 2503 | + // Open tabs share one localStorage claim per run, so only one of them plays. | ||
| 2504 | + var CLAIM_PREFIX = 'forge-tone:'; | ||
| 2505 | + var CLAIM_MAX_AGE = 3600000; // ms: older claims are dropped when a new one is made | ||
| 2506 | + var toneTab = Math.random().toString(36).slice(2); | ||
| 2507 | + var finishedKeys = null; // the runs the newest answer listed; null until the first one | ||
| 2508 | + var toneCtx = null; // the AudioContext, made on first use | ||
| 2509 | + | ||
| 2510 | + // The two notes of an outcome: rising C5 then G5 for a pass, falling for a failure. Each note is a | ||
| 2511 | + // short sine with a quick fade in and out, so nothing clicks. | ||
| 2512 | + function playTones(outcome) { | ||
| 2513 | + var AC = window.AudioContext || window.webkitAudioContext; | ||
| 2514 | + if (!AC) { return; } | ||
| 2515 | + try { toneCtx = toneCtx || new AC(); } catch (err) { return; } | ||
| 2516 | + if (toneCtx.state === 'suspended') { toneCtx.resume().catch(function () { }); } | ||
| 2517 | + var freqs = outcome === 'passed' ? [523.25, 783.99] : [783.99, 523.25]; | ||
| 2518 | + var start = toneCtx.currentTime + 0.02; | ||
| 2519 | + freqs.forEach(function (hz, i) { | ||
| 2520 | + var at = start + i * 0.14; | ||
| 2521 | + var osc = toneCtx.createOscillator(), gain = toneCtx.createGain(); | ||
| 2522 | + osc.type = 'sine'; | ||
| 2523 | + osc.frequency.value = hz; | ||
| 2524 | + gain.gain.setValueAtTime(0.0001, at); | ||
| 2525 | + gain.gain.exponentialRampToValueAtTime(0.15, at + 0.02); | ||
| 2526 | + gain.gain.exponentialRampToValueAtTime(0.0001, at + 0.16); | ||
| 2527 | + osc.connect(gain); | ||
| 2528 | + gain.connect(toneCtx.destination); | ||
| 2529 | + osc.start(at); | ||
| 2530 | + osc.stop(at + 0.18); | ||
| 2531 | + }); | ||
| 2532 | + } | ||
| 2533 | + | ||
| 2534 | + // One tab plays for a run. Each tab writes its id under the run's key when the key is free, waits | ||
| 2535 | + // a moment, and plays only if its id is still there. The key stays, so no later answer plays it. | ||
| 2536 | + function claimTone(key, outcome) { | ||
| 2537 | + var name = CLAIM_PREFIX + key; | ||
| 2538 | + try { | ||
| 2539 | + if (localStorage.getItem(name) !== null) { return; } | ||
| 2540 | + var mine = toneTab + ':' + Date.now(); | ||
| 2541 | + localStorage.setItem(name, mine); | ||
| 2542 | + for (var i = localStorage.length - 1; i >= 0; i--) { | ||
| 2543 | + var old = localStorage.key(i); | ||
| 2544 | + if (old.indexOf(CLAIM_PREFIX) === 0 && Date.now() - parseInt(localStorage.getItem(old).split(':').pop(), 10) > CLAIM_MAX_AGE) { | ||
| 2545 | + localStorage.removeItem(old); | ||
| 2546 | + } | ||
| 2547 | + } | ||
| 2548 | + setTimeout(function () { | ||
| 2549 | + try { if (localStorage.getItem(name) === mine) { playTones(outcome); } } catch (err) { } | ||
| 2550 | + }, 80); | ||
| 2551 | + } catch (err) { } | ||
| 2552 | + } | ||
| 2553 | + | ||
| 2554 | + // Whether the run's own page is on screen in a visible tab: its result is already in view. | ||
| 2555 | + function onRunPage(href) { | ||
| 2556 | + try { | ||
| 2557 | + return document.visibilityState === 'visible' && new URL(href, location.href).pathname === location.pathname; | ||
| 2558 | + } catch (err) { return false; } | ||
| 2559 | + } | ||
| 2560 | + | ||
| 2561 | + // Called with each activity answer. The first answer only records the finished runs; a later one | ||
| 2562 | + // plays for each run it lists that the previous answer did not. | ||
| 2563 | + function soundFromActivity(json) { | ||
| 2564 | + var list = json.finished || []; | ||
| 2565 | + var keys = list.map(function (item) { return item.href + '|' + item.started; }); | ||
| 2566 | + var known = finishedKeys || []; | ||
| 2567 | + var first = finishedKeys === null; | ||
| 2568 | + finishedKeys = keys; | ||
| 2569 | + if (first || root.getAttribute('data-sound') !== 'on') { return; } | ||
| 2570 | + list.forEach(function (item, i) { | ||
| 2571 | + if (known.indexOf(keys[i]) >= 0) { return; } | ||
| 2572 | + if (item.outcome !== 'passed' && item.outcome !== 'failed') { return; } | ||
| 2573 | + if (onRunPage(item.href)) { return; } | ||
| 2574 | + claimTone(keys[i], item.outcome); | ||
| 2575 | + }); | ||
| 2576 | + } | ||
| 2577 | + | ||
| 2578 | + // The settings page's Play buttons: a preview of each tone, whatever the switch says. | ||
| 2579 | + document.addEventListener('click', function (e) { | ||
| 2580 | + var b = e.target && e.target.closest ? e.target.closest('[data-sound-play]') : null; | ||
| 2581 | + if (b) { playTones(b.getAttribute('data-sound-play')); } | ||
| 2582 | + }); | ||
| 2583 | + | ||
| 2584 | + // Signed-out visitors keep their density in localStorage. Signed in, the shell has set | ||
| 2585 | + // `data-density` on <html> already, so nothing is read here. | ||
| 2586 | + if (!signedIn && !root.hasAttribute('data-density')) { | ||
| 2587 | + try { if (localStorage.getItem('forge-density') === 'compact') { root.setAttribute('data-density', 'compact'); } } catch (err) { } | ||
| 2588 | + } | ||
| 2589 | + | ||
| 2454 | // The CI log (a job page's [data-live-log]). The server sends the raw text; this turns it into | 2590 | // The CI log (a job page's [data-live-log]). The server sends the raw text; this turns it into |
| 2455 | // numbered lines (#L12 anchors) with ANSI colours as spans, `::group::name` / `::endgroup::` | 2591 | // numbered lines (#L12 anchors) with ANSI colours as spans, `::group::name` / `::endgroup::` |
| 2456 | // sections as <details>, and a search box with highlight and next/previous. Streamed bytes go | 2592 | // sections as <details>, and a search box with highlight and next/previous. Streamed bytes go |
| @@ -2571,6 +2707,12 @@ | |||
| 2571 | 2707 | ||
| 2572 | function logTop(ci) { return ci.stack[ci.stack.length - 1]; } | 2708 | function logTop(ci) { return ci.stack[ci.stack.length - 1]; } |
| 2573 | 2709 | ||
| 2710 | + // Where a new line goes: the open group, or the chunk's wrapper while the group is the one the chunk began in. | ||
| 2711 | + function logHost(ci) { | ||
| 2712 | + var top = logTop(ci); | ||
| 2713 | + return ci.wrap && ci.wrap.parentNode === top ? ci.wrap : top; | ||
| 2714 | + } | ||
| 2715 | + | ||
| 2574 | // Adds text to the log: completes the open line, then makes a line for each newline. | 2716 | // Adds text to the log: completes the open line, then makes a line for each newline. |
| 2575 | function logFeed(pre, text) { | 2717 | function logFeed(pre, text) { |
| 2576 | var ci = pre._ci; | 2718 | var ci = pre._ci; |
| @@ -2580,7 +2722,7 @@ | |||
| 2580 | if (pieces[i] !== '' || ci.cur || ends) { | 2722 | if (pieces[i] !== '' || ci.cur || ends) { |
| 2581 | if (!ci.cur) { | 2723 | if (!ci.cur) { |
| 2582 | var el = logLineEl(ci.next); | 2724 | var el = logLineEl(ci.next); |
| 2583 | - logTop(ci).appendChild(el); | 2725 | + logHost(ci).appendChild(el); |
| 2584 | ci.cur = { el: el, raw: '', start: ansiCopy(ci.st) }; | 2726 | ci.cur = { el: el, raw: '', start: ansiCopy(ci.st) }; |
| 2585 | } | 2727 | } |
| 2586 | ci.cur.raw += pieces[i]; | 2728 | ci.cur.raw += pieces[i]; |
| @@ -3021,11 +3163,48 @@ | |||
| 3021 | if (!pre || !text) { return; } | 3163 | if (!pre || !text) { return; } |
| 3022 | if (offset) { pre.setAttribute('data-offset', offset); } | 3164 | if (offset) { pre.setAttribute('data-offset', offset); } |
| 3023 | var atEnd = pre.scrollTop + pre.clientHeight >= pre.scrollHeight - 24; | 3165 | var atEnd = pre.scrollTop + pre.clientHeight >= pre.scrollHeight - 24; |
| 3024 | - if (pre._ci) { logFeed(pre, text); logRefind(pre); } | 3166 | + if (pre._ci) { |
| 3167 | + // A small chunk's new lines go into a wrapper that fades in once; a burst appears at once. | ||
| 3168 | + var wrap = logFades(text) ? logWrap(pre) : null; | ||
| 3169 | + pre._ci.wrap = wrap; | ||
| 3170 | + logFeed(pre, text); | ||
| 3171 | + pre._ci.wrap = null; | ||
| 3172 | + if (wrap) { logSettle(wrap); } | ||
| 3173 | + logRefind(pre); | ||
| 3174 | + } | ||
| 3025 | else { pre.appendChild(document.createTextNode(text)); } | 3175 | else { pre.appendChild(document.createTextNode(text)); } |
| 3026 | if (atEnd) { pre.scrollTop = pre.scrollHeight; } | 3176 | if (atEnd) { pre.scrollTop = pre.scrollHeight; } |
| 3027 | } | 3177 | } |
| 3028 | 3178 | ||
| 3179 | + // A chunk fades in when it is at most 64 KiB in UTF-8 and the reader does not ask for reduced motion. | ||
| 3180 | + // A UTF-16 unit is at least one byte and at most three, so the length alone settles most chunks. | ||
| 3181 | + var LOG_FADE_MAX = 65536; | ||
| 3182 | + function logFades(text) { | ||
| 3183 | + if (motionHeld() || text.length > LOG_FADE_MAX) { return false; } | ||
| 3184 | + if (text.length <= 21845) { return true; } | ||
| 3185 | + return new Blob([text]).size <= LOG_FADE_MAX; | ||
| 3186 | + } | ||
| 3187 | + | ||
| 3188 | + // The wrapper goes at the end of the open container, where this chunk's lines will be added. | ||
| 3189 | + function logWrap(pre) { | ||
| 3190 | + var wrap = document.createElement('div'); | ||
| 3191 | + wrap.className = 'll-chunk'; | ||
| 3192 | + logTop(pre._ci).appendChild(wrap); | ||
| 3193 | + return wrap; | ||
| 3194 | + } | ||
| 3195 | + | ||
| 3196 | + // Once the fade is over the wrapper's lines move up into its parent and the wrapper is removed, so | ||
| 3197 | + // wrappers never pile up. A chunk that added no lines (it only finished the open line) has none to show. | ||
| 3198 | + function logSettle(wrap) { | ||
| 3199 | + if (!wrap.firstChild) { wrap.remove(); return; } | ||
| 3200 | + setTimeout(function () { | ||
| 3201 | + var p = wrap.parentNode; | ||
| 3202 | + if (!p) { return; } | ||
| 3203 | + while (wrap.firstChild) { p.insertBefore(wrap.firstChild, wrap); } | ||
| 3204 | + wrap.remove(); | ||
| 3205 | + }, 200); | ||
| 3206 | + } | ||
| 3207 | + | ||
| 3029 | // A re-render replaces the text the reader is selecting (a log line to copy, say), so a live change | 3208 | // A re-render replaces the text the reader is selecting (a log line to copy, say), so a live change |
| 3030 | // waits while a button is held or text on the page is selected, and is sent once the selection is | 3209 | // waits while a button is held or text on the page is selected, and is sent once the selection is |
| 3031 | // gone. A selection inside a field does not count: fields keep their state across a re-render. | 3210 | // gone. A selection inside a field does not count: fields keep their state across a re-render. |
| @@ -3281,6 +3460,16 @@ | |||
| 3281 | return (root.getAttribute('data-fs') || '{s}s').replace('{s}', secs); | 3460 | return (root.getAttribute('data-fs') || '{s}s').replace('{s}', secs); |
| 3282 | } | 3461 | } |
| 3283 | 3462 | ||
| 3463 | + // The words after the elapsed time of a run with an expected total: "about 12m left", or the | ||
| 3464 | + // data-over words once past it. Whole minutes from a minute, else seconds, as the server words it. | ||
| 3465 | + function leftWords(el, left, root) { | ||
| 3466 | + if (left <= 0) { return el.getAttribute('data-over') || ''; } | ||
| 3467 | + var t = left >= 60 | ||
| 3468 | + ? (el.getAttribute('data-lm') || '{m}m').replace('{m}', Math.ceil(left / 60)) | ||
| 3469 | + : (root.getAttribute('data-fs') || '{s}s').replace('{s}', Math.floor(left)); | ||
| 3470 | + return (el.getAttribute('data-left') || '{t}').replace('{t}', t); | ||
| 3471 | + } | ||
| 3472 | + | ||
| 3284 | function place(offset, span, width) { | 3473 | function place(offset, span, width) { |
| 3285 | if (span <= 0) { return 0; } | 3474 | if (span <= 0) { return 0; } |
| 3286 | return Math.round(Math.min(Math.max(offset, 0), span) * width / span); | 3475 | return Math.round(Math.min(Math.max(offset, 0), span) * width / span); |
| @@ -3298,7 +3487,19 @@ | |||
| 3298 | Array.prototype.forEach.call(live, function (el) { | 3487 | Array.prototype.forEach.call(live, function (el) { |
| 3299 | var since = el.getAttribute('data-since'); | 3488 | var since = el.getAttribute('data-since'); |
| 3300 | if (since !== null) { | 3489 | if (since !== null) { |
| 3301 | - var text = fmtDuration(now - parseInt(since, 10), root); | 3490 | + var secs = now - parseInt(since, 10); |
| 3491 | + var text = fmtDuration(secs, root); | ||
| 3492 | + var expected = el.getAttribute('data-expected'); | ||
| 3493 | + if (expected !== null) { | ||
| 3494 | + // A run with an estimate: its bar fills to the expected total and never goes past full. | ||
| 3495 | + var total = parseInt(expected, 10) || 0; | ||
| 3496 | + var elapsed = Math.max(0, Math.floor(secs)); | ||
| 3497 | + if (el.hasAttribute('data-est')) { | ||
| 3498 | + el.value = total > 0 && elapsed < total ? Math.round(elapsed * 100 / total) : 100; | ||
| 3499 | + return; | ||
| 3500 | + } | ||
| 3501 | + text += ' · ' + leftWords(el, total - elapsed, root); | ||
| 3502 | + } | ||
| 3302 | var pre = el.getAttribute('data-pre'); | 3503 | var pre = el.getAttribute('data-pre'); |
| 3303 | if (pre !== null) { text = pre + text + (el.getAttribute('data-post') || ''); } | 3504 | if (pre !== null) { text = pre + text + (el.getAttribute('data-post') || ''); } |
| 3304 | if (el.textContent !== text) { el.textContent = text; } | 3505 | if (el.textContent !== text) { el.textContent = text; } |
| @@ -3778,8 +3979,11 @@ | |||
| 3778 | var PALETTE_WORD = /[\s\/._\-·]/; // a character that starts a word, for the word-start match | 3979 | var PALETTE_WORD = /[\s\/._\-·]/; // a character that starts a word, for the word-start match |
| 3779 | // files: the current repo's file items, once its finder list is loaded (filesSrc names the finder | 3980 | // files: the current repo's file items, once its finder list is loaded (filesSrc names the finder |
| 3780 | // it came from); filesBusy names the source being fetched. | 3981 | // it came from); filesBusy names the source being fetched. |
| 3982 | + // acts: the actions this page offers, read from its live elements at each open. busy: a state change | ||
| 3983 | + // is on the wire. reload: the page a sent change answered with, shown once the palette closes. | ||
| 3781 | var pal = { dlg: null, input: null, list: null, note: null, hits: [], sel: 0, str: null, | 3984 | var pal = { dlg: null, input: null, list: null, note: null, hits: [], sel: 0, str: null, |
| 3782 | - data: null, request: null, failed: false, files: null, filesSrc: '', filesBusy: null }; | 3985 | + data: null, request: null, failed: false, files: null, filesSrc: '', filesBusy: null, |
| 3986 | + acts: [], busy: false, reload: null, prefill: '' }; | ||
| 3783 | 3987 | ||
| 3784 | // The words the palette shows, read from the topbar button: the server writes them in the viewer's | 3988 | // The words the palette shows, read from the topbar button: the server writes them in the viewer's |
| 3785 | // language, so this script carries no text of its own. | 3989 | // language, so this script carries no text of its own. |
| @@ -3793,10 +3997,40 @@ | |||
| 3793 | loading: word('loading'), | 3997 | loading: word('loading'), |
| 3794 | failed: word('failed'), | 3998 | failed: word('failed'), |
| 3795 | search: word('search-label'), | 3999 | search: word('search-label'), |
| 3796 | - heads: { repo: word('repos'), org: word('orgs'), page: word('pages'), file: word('files') } | 4000 | + done: word('done'), |
| 4001 | + refused: word('action-failed'), | ||
| 4002 | + heads: { action: word('actions'), repo: word('repos'), org: word('orgs'), page: word('pages'), file: word('files') } | ||
| 3797 | }; | 4003 | }; |
| 3798 | } | 4004 | } |
| 3799 | 4005 | ||
| 4006 | + // An action's label: the control's own text, without its icons and key hints, unless the control | ||
| 4007 | + // names itself with data-palette-label. | ||
| 4008 | + function paletteText(el) { | ||
| 4009 | + var named = el.getAttribute('data-palette-label'); | ||
| 4010 | + if (named) { return named.trim(); } | ||
| 4011 | + var copy = el.cloneNode(true); | ||
| 4012 | + Array.prototype.forEach.call(copy.querySelectorAll('svg, kbd, script, style'), function (n) { n.parentNode.removeChild(n); }); | ||
| 4013 | + return copy.textContent.replace(/\s+/g, ' ').trim(); | ||
| 4014 | + } | ||
| 4015 | + | ||
| 4016 | + // The actions of this page: its elements with data-palette-action, read from the live page at each | ||
| 4017 | + // open. The server renders a control only for a viewer who may use it, so the list holds only those. | ||
| 4018 | + // A mode says what Enter does: go follows a link, click clicks the control, post sends its form the | ||
| 4019 | + // way the control would, and confirm leads to a destructive control without running it. | ||
| 4020 | + function paletteActions() { | ||
| 4021 | + var out = [], seen = {}; | ||
| 4022 | + Array.prototype.forEach.call(document.querySelectorAll('[data-palette-action]'), function (el) { | ||
| 4023 | + var mode = el.getAttribute('data-palette-action'); | ||
| 4024 | + if (mode !== 'go' && mode !== 'click' && mode !== 'post' && mode !== 'confirm') { return; } | ||
| 4025 | + if (el.disabled) { return; } | ||
| 4026 | + var label = paletteText(el); | ||
| 4027 | + if (!label || seen[label]) { return; } | ||
| 4028 | + seen[label] = true; | ||
| 4029 | + out.push({ label: label, href: '', kind: 'action', mode: mode, el: el }); | ||
| 4030 | + }); | ||
| 4031 | + return out; | ||
| 4032 | + } | ||
| 4033 | + | ||
| 3800 | // How well the lowercased query matches a label: 3 for a prefix, 2 for a match at a word start, | 4034 | // How well the lowercased query matches a label: 3 for a prefix, 2 for a match at a word start, |
| 3801 | // 1 for the letters in order anywhere, 0 for no match. A shorter label wins within a tier, and the | 4035 | // 1 for the letters in order anywhere, 0 for no match. A shorter label wins within a tier, and the |
| 3802 | // bonus stays under 0.5 so it never lifts a label into the tier above. An empty query matches all. | 4036 | // bonus stays under 0.5 so it never lifts a label into the tier above. An empty query matches all. |
| @@ -3833,7 +4067,8 @@ | |||
| 3833 | }); | 4067 | }); |
| 3834 | } | 4068 | } |
| 3835 | } | 4069 | } |
| 3836 | - return pal.data ? items.concat(pal.data.items) : items; | 4070 | + if (pal.data) { items = items.concat(pal.data.items); } |
| 4071 | + return pal.acts.concat(items); | ||
| 3837 | } | 4072 | } |
| 3838 | 4073 | ||
| 3839 | // The current repo's files, offered once the query starts with its "owner/repo/". The list is the | 4074 | // The current repo's files, offered once the query starts with its "owner/repo/". The list is the |
| @@ -3887,6 +4122,8 @@ | |||
| 3887 | // like the query leads; with no query, the order is tabs, repos, orgs, then pages. | 4122 | // like the query leads; with no query, the order is tabs, repos, orgs, then pages. |
| 3888 | function renderPalette() { | 4123 | function renderPalette() { |
| 3889 | var raw = pal.input.value.trim(); | 4124 | var raw = pal.input.value.trim(); |
| 4125 | + // Still the text the palette opened with (a repo's path): no query yet, so actions are listed. | ||
| 4126 | + var idle = !!pal.prefill && pal.input.value === pal.prefill; | ||
| 3890 | var q = raw.toLowerCase(); | 4127 | var q = raw.toLowerCase(); |
| 3891 | // With a "/" the query is a path: an item matches when its label starts with it. | 4128 | // With a "/" the query is a path: an item matches when its label starts with it. |
| 3892 | var pathMode = q.indexOf('/') >= 0; | 4129 | var pathMode = q.indexOf('/') >= 0; |
| @@ -3894,6 +4131,8 @@ | |||
| 3894 | paletteItems().concat(paletteFiles(q)).forEach(function (item, idx) { | 4131 | paletteItems().concat(paletteFiles(q)).forEach(function (item, idx) { |
| 3895 | if (!Object.prototype.hasOwnProperty.call(pal.str.heads, item.kind)) { return; } | 4132 | if (!Object.prototype.hasOwnProperty.call(pal.str.heads, item.kind)) { return; } |
| 3896 | var s = pathMode ? (item.label.toLowerCase().indexOf(q) === 0 ? 3 : 0) : paletteScore(q, item.label); | 4133 | var s = pathMode ? (item.label.toLowerCase().indexOf(q) === 0 ? 3 : 0) : paletteScore(q, item.label); |
| 4134 | + // Above a path match (3), which would otherwise fill the list and cut the actions off. | ||
| 4135 | + if (item.kind === 'action' && idle) { s = 4; } | ||
| 3897 | if (s > 0) { scored.push({ item: item, score: s, idx: idx }); } | 4136 | if (s > 0) { scored.push({ item: item, score: s, idx: idx }); } |
| 3898 | }); | 4137 | }); |
| 3899 | scored.sort(function (a, b) { return b.score - a.score || a.idx - b.idx; }); | 4138 | scored.sort(function (a, b) { return b.score - a.score || a.idx - b.idx; }); |
| @@ -3904,6 +4143,9 @@ | |||
| 3904 | if (!groups[kind]) { groups[kind] = []; kinds.push(kind); } | 4143 | if (!groups[kind]) { groups[kind] = []; kinds.push(kind); } |
| 3905 | groups[kind].push(h.item); | 4144 | groups[kind].push(h.item); |
| 3906 | }); | 4145 | }); |
| 4146 | + // Actions of this page are listed above the destinations whenever they match. | ||
| 4147 | + var actAt = kinds.indexOf('action'); | ||
| 4148 | + if (actAt > 0) { kinds.splice(actAt, 1); kinds.unshift('action'); } | ||
| 3907 | // A plain query (no "/") ends with a search option, under no heading. | 4149 | // A plain query (no "/") ends with a search option, under no heading. |
| 3908 | if (raw && !pathMode) { | 4150 | if (raw && !pathMode) { |
| 3909 | kinds.push('search'); | 4151 | kinds.push('search'); |
| @@ -3931,9 +4173,16 @@ | |||
| 3931 | pal.list.appendChild(li); | 4173 | pal.list.appendChild(li); |
| 3932 | }); | 4174 | }); |
| 3933 | }); | 4175 | }); |
| 4176 | + pal.note.className = 'palette-note muted small'; | ||
| 3934 | if (pal.hits.length) { | 4177 | if (pal.hits.length) { |
| 3935 | pal.note.textContent = pal.str.hint; | 4178 | pal.note.textContent = pal.str.hint; |
| 3936 | paletteSelect(0); | 4179 | paletteSelect(0); |
| 4180 | + // With no query Enter must not run an action: the selection starts on the first destination. | ||
| 4181 | + if ((!raw || idle) && pal.hits[0].kind === 'action') { | ||
| 4182 | + for (var k = 0; k < pal.hits.length; k++) { | ||
| 4183 | + if (pal.hits[k].kind !== 'action') { paletteSelect(k); break; } | ||
| 4184 | + } | ||
| 4185 | + } | ||
| 3937 | } else { | 4186 | } else { |
| 3938 | pal.note.textContent = pal.failed ? pal.str.failed : (pal.data ? pal.str.empty : pal.str.loading); | 4187 | pal.note.textContent = pal.failed ? pal.str.failed : (pal.data ? pal.str.empty : pal.str.loading); |
| 3939 | pal.input.removeAttribute('aria-activedescendant'); | 4188 | pal.input.removeAttribute('aria-activedescendant'); |
| @@ -3962,6 +4211,7 @@ | |||
| 3962 | // a sidebar link does; a link the browser must handle itself goes through location. | 4211 | // a sidebar link does; a link the browser must handle itself goes through location. |
| 3963 | function paletteGo(href) { | 4212 | function paletteGo(href) { |
| 3964 | if (!href) { return; } | 4213 | if (!href) { return; } |
| 4214 | + pal.reload = null; | ||
| 3965 | pal.dlg.close(); | 4215 | pal.dlg.close(); |
| 3966 | var url = pageUrl(href); | 4216 | var url = pageUrl(href); |
| 3967 | if (!url) { location.assign(href); return; } | 4217 | if (!url) { location.assign(href); return; } |
| @@ -3969,6 +4219,62 @@ | |||
| 3969 | load({ target: withoutHash(url), dest: url, init: GET_INIT, how: 'nav', keep: false, post: false, form: null }); | 4219 | load({ target: withoutHash(url), dest: url, init: GET_INIT, how: 'nav', keep: false, post: false, form: null }); |
| 3970 | } | 4220 | } |
| 3971 | 4221 | ||
| 4222 | + // Shows a line in the palette's footer, in the colour of its state. | ||
| 4223 | + function paletteNote(text, state) { | ||
| 4224 | + pal.note.textContent = text; | ||
| 4225 | + pal.note.className = 'palette-note muted small' + (state ? ' ' + state : ''); | ||
| 4226 | + } | ||
| 4227 | + | ||
| 4228 | + // Sends a state-changing control's form as the control itself would: its csrf field and other | ||
| 4229 | + // inputs, its formaction if it has one, and its own name and value. The palette says done only when | ||
| 4230 | + // the server answered with a redirect and no error notice; a refusal shows the server's own message. | ||
| 4231 | + // The page is reloaded once the palette closes, so it shows the new state. | ||
| 4232 | + function paletteSubmit(el) { | ||
| 4233 | + var form = el.form || el.closest('form'); | ||
| 4234 | + var action = el.getAttribute('formaction') || (form ? form.getAttribute('action') : '') || location.href; | ||
| 4235 | + var url = pageUrl(action); | ||
| 4236 | + if (!form || !url) { return; } | ||
| 4237 | + var data = new FormData(form); | ||
| 4238 | + if (el.name) { data.append(el.name, el.value); } | ||
| 4239 | + pal.busy = true; | ||
| 4240 | + paletteNote(pal.str.loading, ''); | ||
| 4241 | + fetch(url.href, { method: 'POST', headers: { accept: 'text/html' }, credentials: 'same-origin', body: new URLSearchParams(data) }).then(function (r) { | ||
| 4242 | + return r.text().then(function (text) { return { ok: r.redirected && r.status < 400, url: r.url, html: text }; }); | ||
| 4243 | + }).then(function (res) { | ||
| 4244 | + pal.busy = false; | ||
| 4245 | + var doc = new DOMParser().parseFromString(res.html, 'text/html'); | ||
| 4246 | + var alert = doc.querySelector('main [role="alert"], main .alert'); | ||
| 4247 | + if (res.ok && !alert) { | ||
| 4248 | + pal.reload = pageUrl(res.url); | ||
| 4249 | + paletteNote(pal.str.done, 'is-ok'); | ||
| 4250 | + } else { | ||
| 4251 | + paletteNote(alert ? alert.textContent.replace(/\s+/g, ' ').trim() : pal.str.refused, 'is-bad'); | ||
| 4252 | + } | ||
| 4253 | + }, function () { | ||
| 4254 | + pal.busy = false; | ||
| 4255 | + paletteNote(pal.str.refused, 'is-bad'); | ||
| 4256 | + }); | ||
| 4257 | + } | ||
| 4258 | + | ||
| 4259 | + // Runs what Enter or a click picked: a destination is followed, an action is carried out by its mode. | ||
| 4260 | + // A destructive control is never clicked from here: the palette closes on it, so the reader confirms. | ||
| 4261 | + function paletteRun(item) { | ||
| 4262 | + if (!item) { return; } | ||
| 4263 | + if (item.kind !== 'action') { paletteGo(item.href); return; } | ||
| 4264 | + if (pal.busy || !item.el.isConnected) { return; } | ||
| 4265 | + var el = item.el; | ||
| 4266 | + if (item.mode === 'post') { paletteSubmit(el); return; } | ||
| 4267 | + pal.reload = null; | ||
| 4268 | + if (item.mode === 'go' || (item.mode === 'confirm' && el.tagName === 'A')) { | ||
| 4269 | + paletteGo(el.getAttribute('href')); | ||
| 4270 | + return; | ||
| 4271 | + } | ||
| 4272 | + pal.dlg.close(); | ||
| 4273 | + if (item.mode === 'click') { el.click(); return; } | ||
| 4274 | + el.scrollIntoView({ block: 'center' }); | ||
| 4275 | + el.focus(); | ||
| 4276 | + } | ||
| 4277 | + | ||
| 3972 | // Built once. Its markup is static; every word in it arrives through the button's data attributes. | 4278 | // Built once. Its markup is static; every word in it arrives through the button's data attributes. |
| 3973 | function buildPalette() { | 4279 | function buildPalette() { |
| 3974 | var dlg = document.createElement('dialog'); | 4280 | var dlg = document.createElement('dialog'); |
| @@ -3989,12 +4295,12 @@ | |||
| 3989 | if (e.isComposing) { return; } | 4295 | if (e.isComposing) { return; } |
| 3990 | if (e.key === 'ArrowDown') { e.preventDefault(); paletteSelect(pal.sel + 1); } | 4296 | if (e.key === 'ArrowDown') { e.preventDefault(); paletteSelect(pal.sel + 1); } |
| 3991 | else if (e.key === 'ArrowUp') { e.preventDefault(); paletteSelect(pal.sel - 1); } | 4297 | else if (e.key === 'ArrowUp') { e.preventDefault(); paletteSelect(pal.sel - 1); } |
| 3992 | - else if (e.key === 'Enter') { e.preventDefault(); if (pal.hits[pal.sel]) { paletteGo(pal.hits[pal.sel].href); } } | 4298 | + else if (e.key === 'Enter') { e.preventDefault(); paletteRun(pal.hits[pal.sel]); } |
| 3993 | // Tab completes the input to the selected item; Ctrl or Alt with Backspace drops the last path segment. | 4299 | // Tab completes the input to the selected item; Ctrl or Alt with Backspace drops the last path segment. |
| 3994 | else if (e.key === 'Tab') { | 4300 | else if (e.key === 'Tab') { |
| 3995 | e.preventDefault(); | 4301 | e.preventDefault(); |
| 3996 | var item = pal.hits[pal.sel]; | 4302 | var item = pal.hits[pal.sel]; |
| 3997 | - if (item && item.kind !== 'search') { pal.input.value = paletteCompletion(item); renderPalette(); } | 4303 | + if (item && item.kind !== 'search' && item.kind !== 'action') { pal.input.value = paletteCompletion(item); renderPalette(); } |
| 3998 | } | 4304 | } |
| 3999 | else if (e.key === 'Backspace' && (e.ctrlKey || e.altKey)) { | 4305 | else if (e.key === 'Backspace' && (e.ctrlKey || e.altKey)) { |
| 4000 | e.preventDefault(); | 4306 | e.preventDefault(); |
| @@ -4010,10 +4316,16 @@ | |||
| 4010 | }); | 4316 | }); |
| 4011 | pal.list.addEventListener('click', function (e) { | 4317 | pal.list.addEventListener('click', function (e) { |
| 4012 | var li = e.target && e.target.closest ? e.target.closest('li[role="option"]') : null; | 4318 | var li = e.target && e.target.closest ? e.target.closest('li[role="option"]') : null; |
| 4013 | - if (li) { paletteGo(pal.hits[Number(li.getAttribute('data-n'))].href); } | 4319 | + if (li) { paletteRun(pal.hits[Number(li.getAttribute('data-n'))]); } |
| 4014 | }); | 4320 | }); |
| 4015 | // The backdrop is the dialog element itself; the box fills the rest. | 4321 | // The backdrop is the dialog element itself; the box fills the rest. |
| 4016 | dlg.addEventListener('click', function (e) { if (e.target === dlg) { dlg.close(); } }); | 4322 | dlg.addEventListener('click', function (e) { if (e.target === dlg) { dlg.close(); } }); |
| 4323 | + // A change sent from the palette shows on the page once the palette is closed, by a page load. | ||
| 4324 | + dlg.addEventListener('close', function () { | ||
| 4325 | + var next = pal.reload; | ||
| 4326 | + pal.reload = null; | ||
| 4327 | + if (next) { load({ target: withoutHash(next), dest: next, init: GET_INIT, how: 'nav', keep: false, post: false, form: null }); } | ||
| 4328 | + }); | ||
| 4017 | } | 4329 | } |
| 4018 | 4330 | ||
| 4019 | function openPalette() { | 4331 | function openPalette() { |
| @@ -4025,6 +4337,7 @@ | |||
| 4025 | // A page swap removes body children, the dialog among them, so it is put back on each open. | 4337 | // A page swap removes body children, the dialog among them, so it is put back on each open. |
| 4026 | if (dlg.parentNode !== document.body) { document.body.appendChild(dlg); } | 4338 | if (dlg.parentNode !== document.body) { document.body.appendChild(dlg); } |
| 4027 | pal.str = paletteStrings(opener); | 4339 | pal.str = paletteStrings(opener); |
| 4340 | + pal.acts = paletteActions(); | ||
| 4028 | dlg.setAttribute('aria-label', pal.str.label); | 4341 | dlg.setAttribute('aria-label', pal.str.label); |
| 4029 | pal.input.placeholder = pal.str.placeholder; | 4342 | pal.input.placeholder = pal.str.placeholder; |
| 4030 | pal.input.setAttribute('aria-label', pal.str.placeholder); | 4343 | pal.input.setAttribute('aria-label', pal.str.placeholder); |
| @@ -4037,6 +4350,7 @@ | |||
| 4037 | // The path bar's path comes in as a prefix when it has owner and repo, ready to narrow down. | 4350 | // The path bar's path comes in as a prefix when it has owner and repo, ready to narrow down. |
| 4038 | var path = (opener.getAttribute('data-path') || '').replace(/\/+$/, ''); | 4351 | var path = (opener.getAttribute('data-path') || '').replace(/\/+$/, ''); |
| 4039 | var prefill = path.split('/').filter(Boolean).length >= 2 ? path + '/' : ''; | 4352 | var prefill = path.split('/').filter(Boolean).length >= 2 ? path + '/' : ''; |
| 4353 | + pal.prefill = prefill; | ||
| 4040 | pal.input.value = prefill; | 4354 | pal.input.value = prefill; |
| 4041 | renderPalette(); | 4355 | renderPalette(); |
| 4042 | pal.input.focus(); | 4356 | pal.input.focus(); |
| @@ -5173,3 +5487,212 @@ | |||
| 5173 | }).observe(document.body, { childList: true, subtree: true }); | 5487 | }).observe(document.body, { childList: true, subtree: true }); |
| 5174 | reveal(); | 5488 | reveal(); |
| 5175 | })(); | 5489 | })(); |
| 5490 | + | ||
| 5491 | +// ---- keyboard rows ---------------------------------------------------------------------------------- | ||
| 5492 | +// Rows marked data-kb-row (lists of commits, issues, pulls, CI runs, repos, notifications) take the | ||
| 5493 | +// keys: j and k move the selection, Enter opens the row's first link, x ticks its checkbox if it has | ||
| 5494 | +// one, and ? lists the keys. The selection is remembered by that link's address, so a live swap | ||
| 5495 | +// that keeps the row keeps it selected; otherwise it clears quietly. Nothing fires while typing, | ||
| 5496 | +// with a modifier held, or while a dialog (the palette included) is open. r and / are not bound | ||
| 5497 | +// here: r has no row form to post to, and / already opens the palette (see the report). | ||
| 5498 | +(function () { | ||
| 5499 | + 'use strict'; | ||
| 5500 | + | ||
| 5501 | + var KB_TEXT = { | ||
| 5502 | + en: { next: 'Next row', prev: 'Previous row', open: 'Open the row', pick: 'Select the row', keys: 'Show these keys', close: 'Close', title: 'Keyboard' }, | ||
| 5503 | + tr: { next: 'Sonraki satır', prev: 'Önceki satır', open: 'Satırı aç', pick: 'Satırı seç', keys: 'Bu tuşları göster', close: 'Kapat', title: 'Klavye' } | ||
| 5504 | + }; | ||
| 5505 | + | ||
| 5506 | + var selKey = null; // the address of the selected row's first link | ||
| 5507 | + | ||
| 5508 | + function lang() { | ||
| 5509 | + return (document.documentElement.getAttribute('lang') || '').toLowerCase().indexOf('tr') === 0 ? 'tr' : 'en'; | ||
| 5510 | + } | ||
| 5511 | + | ||
| 5512 | + function rows() { | ||
| 5513 | + return Array.prototype.filter.call(document.querySelectorAll('[data-kb-row]'), function (r) { | ||
| 5514 | + return r.offsetParent !== null; | ||
| 5515 | + }); | ||
| 5516 | + } | ||
| 5517 | + | ||
| 5518 | + function selectedRow() { | ||
| 5519 | + return document.querySelector('[data-kb-row].kb-sel'); | ||
| 5520 | + } | ||
| 5521 | + | ||
| 5522 | + function keyOf(row) { | ||
| 5523 | + var a = row.querySelector('a[href]'); | ||
| 5524 | + return a ? a.getAttribute('href') : null; | ||
| 5525 | + } | ||
| 5526 | + | ||
| 5527 | + function select(row) { | ||
| 5528 | + var cur = selectedRow(); | ||
| 5529 | + if (cur) { cur.classList.remove('kb-sel'); } | ||
| 5530 | + if (!row) { selKey = null; return; } | ||
| 5531 | + row.classList.add('kb-sel'); | ||
| 5532 | + selKey = keyOf(row); | ||
| 5533 | + row.scrollIntoView({ block: 'nearest' }); | ||
| 5534 | + } | ||
| 5535 | + | ||
| 5536 | + // j and k stop at the ends of the list rather than wrapping. With nothing selected, j takes the first row. | ||
| 5537 | + function step(dir) { | ||
| 5538 | + var list = rows(); | ||
| 5539 | + if (!list.length) { return; } | ||
| 5540 | + var at = list.indexOf(selectedRow()); | ||
| 5541 | + var next = at < 0 ? (dir > 0 ? 0 : list.length - 1) : Math.min(list.length - 1, Math.max(0, at + dir)); | ||
| 5542 | + select(list[next]); | ||
| 5543 | + } | ||
| 5544 | + | ||
| 5545 | + function openHelp() { | ||
| 5546 | + var T = KB_TEXT[lang()]; | ||
| 5547 | + var old = document.getElementById('kb-help'); | ||
| 5548 | + if (old) { old.parentNode.removeChild(old); } | ||
| 5549 | + var dlg = document.createElement('dialog'); | ||
| 5550 | + dlg.id = 'kb-help'; | ||
| 5551 | + dlg.className = 'kb-help'; | ||
| 5552 | + dlg.setAttribute('aria-label', T.title); | ||
| 5553 | + var h = document.createElement('h2'); | ||
| 5554 | + h.textContent = T.title; | ||
| 5555 | + dlg.appendChild(h); | ||
| 5556 | + var dl = document.createElement('dl'); | ||
| 5557 | + [['j', T.next], ['k', T.prev], ['Enter', T.open], ['x', T.pick], ['?', T.keys]].forEach(function (pair) { | ||
| 5558 | + var dt = document.createElement('dt'); | ||
| 5559 | + var kbd = document.createElement('kbd'); | ||
| 5560 | + kbd.textContent = pair[0]; | ||
| 5561 | + dt.appendChild(kbd); | ||
| 5562 | + var dd = document.createElement('dd'); | ||
| 5563 | + dd.textContent = pair[1]; | ||
| 5564 | + dl.appendChild(dt); | ||
| 5565 | + dl.appendChild(dd); | ||
| 5566 | + }); | ||
| 5567 | + dlg.appendChild(dl); | ||
| 5568 | + var form = document.createElement('form'); | ||
| 5569 | + form.method = 'dialog'; | ||
| 5570 | + var btn = document.createElement('button'); | ||
| 5571 | + btn.type = 'submit'; | ||
| 5572 | + btn.className = 'button'; | ||
| 5573 | + btn.textContent = T.close; | ||
| 5574 | + form.appendChild(btn); | ||
| 5575 | + dlg.appendChild(form); | ||
| 5576 | + document.body.appendChild(dlg); | ||
| 5577 | + if (dlg.showModal) { dlg.showModal(); } | ||
| 5578 | + } | ||
| 5579 | + | ||
| 5580 | + document.addEventListener('keydown', function (e) { | ||
| 5581 | + var t = e.target; | ||
| 5582 | + if (e.isComposing || (t && (t.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName)))) { return; } | ||
| 5583 | + if (e.ctrlKey || e.metaKey || e.altKey || document.querySelector('dialog[open]')) { return; } | ||
| 5584 | + if (e.key === '?') { e.preventDefault(); openHelp(); return; } | ||
| 5585 | + if (e.shiftKey) { return; } | ||
| 5586 | + if (e.key === 'j') { step(1); } | ||
| 5587 | + else if (e.key === 'k') { step(-1); } | ||
| 5588 | + else if (e.key === 'Enter') { | ||
| 5589 | + // A focused link or button keeps its own Enter; only a bare page takes the selected row. | ||
| 5590 | + var row = selectedRow(); | ||
| 5591 | + if (!row || (t && /^(A|BUTTON|SUMMARY)$/.test(t.tagName))) { return; } | ||
| 5592 | + var a = row.querySelector('a[href]'); | ||
| 5593 | + if (a) { e.preventDefault(); a.click(); } | ||
| 5594 | + } else if (e.key === 'x') { | ||
| 5595 | + var cur = selectedRow(); | ||
| 5596 | + var cb = cur ? cur.querySelector('input[type="checkbox"]') : null; | ||
| 5597 | + if (cb && !cb.disabled) { e.preventDefault(); cb.click(); } | ||
| 5598 | + } | ||
| 5599 | + }, false); | ||
| 5600 | + | ||
| 5601 | + // After a live swap or a page change the rows are new nodes: the selection moves to the row with the | ||
| 5602 | + // same address, or clears when there is none. | ||
| 5603 | + document.addEventListener('forge:swapped', function () { | ||
| 5604 | + if (!selKey) { return; } | ||
| 5605 | + var hit = rows().filter(function (r) { return keyOf(r) === selKey; })[0]; | ||
| 5606 | + if (hit) { hit.classList.add('kb-sel'); } else { selKey = null; } | ||
| 5607 | + }, false); | ||
| 5608 | +})(); | ||
| 5609 | + | ||
| 5610 | +// ---- pull request files: viewed marks --------------------------------------------------------------- | ||
| 5611 | +// The Viewed panel (data-viewed-panel) on the Files tab. A checkbox posts its new state to the | ||
| 5612 | +// pull's viewed route, and the page reloads only once the server answered; a refused post re-enables | ||
| 5613 | +// the box and changes nothing. Viewed files are collapsed by their heading (is-viewed). v toggles the | ||
| 5614 | +// focused row and n focuses the next unviewed one. Neither fires while typing, with a modifier held, | ||
| 5615 | +// or while a dialog is open. Neither key is bound elsewhere: j, k, Enter, x and ? belong to the row | ||
| 5616 | +// keys above and / to the palette. | ||
| 5617 | +(function () { | ||
| 5618 | + 'use strict'; | ||
| 5619 | + | ||
| 5620 | + var panel = document.querySelector('[data-viewed-panel]'); | ||
| 5621 | + if (!panel) { return; } | ||
| 5622 | + var rows = Array.prototype.slice.call(panel.querySelectorAll('[data-viewed-row]')); | ||
| 5623 | + var sections = Array.prototype.slice.call(document.querySelectorAll('section.diff-file')); | ||
| 5624 | + var focus = -1; | ||
| 5625 | + | ||
| 5626 | + function sectionOf(row) { | ||
| 5627 | + var label = row.getAttribute('data-label'); | ||
| 5628 | + return sections.filter(function (s) { return s.getAttribute('data-keep-anchor') === label; })[0] || null; | ||
| 5629 | + } | ||
| 5630 | + | ||
| 5631 | + function boxOf(row) { return row.querySelector('[data-viewed-toggle]'); } | ||
| 5632 | + | ||
| 5633 | + rows.forEach(function (row) { | ||
| 5634 | + var sec = sectionOf(row); | ||
| 5635 | + if (sec) { sec.classList.toggle('is-viewed', row.getAttribute('data-state') === 'viewed'); } | ||
| 5636 | + }); | ||
| 5637 | + | ||
| 5638 | + // The box keeps its old state until the server answers. The box is the new state's request: a | ||
| 5639 | + // checked box asks to clear the mark (viewed 0), an unchecked one asks to set it (viewed 1). | ||
| 5640 | + function post(box) { | ||
| 5641 | + if (!box || box.disabled) { return; } | ||
| 5642 | + box.disabled = true; | ||
| 5643 | + var body = new URLSearchParams(); | ||
| 5644 | + body.set('csrf', panel.getAttribute('data-csrf')); | ||
| 5645 | + body.set('path', box.getAttribute('data-path')); | ||
| 5646 | + body.set('viewed', box.checked ? '0' : '1'); | ||
| 5647 | + fetch(panel.getAttribute('data-action'), { method: 'POST', body: body, credentials: 'same-origin' }) | ||
| 5648 | + .then(function (res) { | ||
| 5649 | + if (!res.ok) { throw new Error('status ' + res.status); } | ||
| 5650 | + window.location.reload(); | ||
| 5651 | + }) | ||
| 5652 | + .catch(function () { box.disabled = false; }); | ||
| 5653 | + } | ||
| 5654 | + | ||
| 5655 | + panel.addEventListener('click', function (e) { | ||
| 5656 | + var box = e.target && e.target.closest ? e.target.closest('[data-viewed-toggle]') : null; | ||
| 5657 | + if (!box) { return; } | ||
| 5658 | + e.preventDefault(); | ||
| 5659 | + post(box); | ||
| 5660 | + }); | ||
| 5661 | + | ||
| 5662 | + function focusRow(i) { | ||
| 5663 | + rows.forEach(function (r) { r.classList.remove('is-focus'); }); | ||
| 5664 | + focus = i; | ||
| 5665 | + rows[i].classList.add('is-focus'); | ||
| 5666 | + var sec = sectionOf(rows[i]); | ||
| 5667 | + if (sec) { sec.scrollIntoView({ block: 'start' }); } | ||
| 5668 | + } | ||
| 5669 | + | ||
| 5670 | + // The next row after the focused one that is not viewed, wrapping; -1 when every file is viewed. | ||
| 5671 | + function nextUnviewed() { | ||
| 5672 | + var n = rows.length; | ||
| 5673 | + for (var k = 1; k <= n; k++) { | ||
| 5674 | + var i = (focus + k + n) % n; | ||
| 5675 | + if (rows[i].getAttribute('data-state') !== 'viewed') { return i; } | ||
| 5676 | + } | ||
| 5677 | + return -1; | ||
| 5678 | + } | ||
| 5679 | + | ||
| 5680 | + document.addEventListener('keydown', function (e) { | ||
| 5681 | + if ((e.key !== 'v' && e.key !== 'n') || e.ctrlKey || e.metaKey || e.altKey || e.isComposing) { return; } | ||
| 5682 | + var t = e.target; | ||
| 5683 | + if (t && (t.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName))) { return; } | ||
| 5684 | + if (document.querySelector('dialog[open]')) { return; } | ||
| 5685 | + if (e.key === 'n') { | ||
| 5686 | + var next = nextUnviewed(); | ||
| 5687 | + if (next < 0) { return; } | ||
| 5688 | + e.preventDefault(); | ||
| 5689 | + focusRow(next); | ||
| 5690 | + } else { | ||
| 5691 | + if (focus < 0) { return; } | ||
| 5692 | + var box = boxOf(rows[focus]); | ||
| 5693 | + if (!box || box.disabled) { return; } | ||
| 5694 | + e.preventDefault(); | ||
| 5695 | + post(box); | ||
| 5696 | + } | ||
| 5697 | + }); | ||
| 5698 | +})(); | ||
crates/forge-web/src/ci/release.rsmodified+138 -9
| @@ -25,6 +25,7 @@ use tokio::io::AsyncWriteExt; | |||
| 25 | use super::api::fit_to_cap; | 25 | use super::api::fit_to_cap; |
| 26 | use super::{artifact_key, log_path, schedule, status_creator}; | 26 | use super::{artifact_key, log_path, schedule, status_creator}; |
| 27 | use crate::release_ops::{self, CreateRelease, ReleaseError}; | 27 | use crate::release_ops::{self, CreateRelease, ReleaseError}; |
| 28 | +use crate::render::commit_message::CommitMessage; | ||
| 28 | use crate::state::AppState; | 29 | use crate::state::AppState; |
| 29 | 30 | ||
| 30 | /// Most commits listed in the notes. Older commits are left out. | 31 | /// Most commits listed in the notes. Older commits are left out. |
| @@ -299,10 +300,48 @@ async fn changelog( | |||
| 299 | Ok(bullets(&commits, footer.as_deref())) | 300 | Ok(bullets(&commits, footer.as_deref())) |
| 300 | } | 301 | } |
| 301 | 302 | ||
| 302 | -/// One `- subject (shortsha)` line per commit, newest first, then the footer. Commits that would | 303 | +/// Note sections in output order. Commit kinds map to them through `section_of`. |
| 303 | -/// push the notes past the body limit are left out. | 304 | +const SECTIONS: [&str; 7] = [ |
| 305 | + "Features", | ||
| 306 | + "Fixes", | ||
| 307 | + "Performance", | ||
| 308 | + "Style", | ||
| 309 | + "CI", | ||
| 310 | + "Documentation", | ||
| 311 | + "Other", | ||
| 312 | +]; | ||
| 313 | + | ||
| 314 | +/// The index in `SECTIONS` for a commit kind. Unknown kinds go to `Other`. | ||
| 315 | +fn section_of(kind: &str) -> usize { | ||
| 316 | + match kind { | ||
| 317 | + "feat" => 0, | ||
| 318 | + "fix" => 1, | ||
| 319 | + "perf" => 2, | ||
| 320 | + "style" | "ui" | "ux" => 3, | ||
| 321 | + "ci" => 4, | ||
| 322 | + "docs" => 5, | ||
| 323 | + _ => 6, | ||
| 324 | + } | ||
| 325 | +} | ||
| 326 | + | ||
| 327 | +/// The notes body. When at least one subject is structured, the clauses are grouped under | ||
| 328 | +/// `SECTIONS`; otherwise one `- subject (shortsha)` line per commit, newest first. Commits that | ||
| 329 | +/// would push the notes past the body limit are left out, and the footer is kept in the count. | ||
| 304 | fn bullets(commits: &[CommitInfo], footer: Option<&str>) -> String { | 330 | fn bullets(commits: &[CommitInfo], footer: Option<&str>) -> String { |
| 305 | let footer_len = footer.map_or(0, |f| f.chars().count() + 2); | 331 | let footer_len = footer.map_or(0, |f| f.chars().count() + 2); |
| 332 | + let structured = commits | ||
| 333 | + .iter() | ||
| 334 | + .any(|commit| CommitMessage::parse(&commit.summary).is_some()); | ||
| 335 | + let body = if structured { | ||
| 336 | + grouped_bullets(commits, footer_len) | ||
| 337 | + } else { | ||
| 338 | + flat_bullets(commits, footer_len) | ||
| 339 | + }; | ||
| 340 | + with_footer(&body, footer) | ||
| 341 | +} | ||
| 342 | + | ||
| 343 | +/// One `- subject (shortsha)` line per commit, newest first. | ||
| 344 | +fn flat_bullets(commits: &[CommitInfo], footer_len: usize) -> String { | ||
| 306 | let mut body = String::new(); | 345 | let mut body = String::new(); |
| 307 | let mut used = 0usize; | 346 | let mut used = 0usize; |
| 308 | for commit in commits { | 347 | for commit in commits { |
| @@ -315,6 +354,58 @@ fn bullets(commits: &[CommitInfo], footer: Option<&str>) -> String { | |||
| 315 | used += len; | 354 | used += len; |
| 316 | body.push_str(&line); | 355 | body.push_str(&line); |
| 317 | } | 356 | } |
| 357 | + body | ||
| 358 | +} | ||
| 359 | + | ||
| 360 | +/// Lines grouped under `SECTIONS`, in commit order within each section. A heading costs its | ||
| 361 | +/// `### name` line and the blank line after the section, and is counted once per section. | ||
| 362 | +fn grouped_bullets(commits: &[CommitInfo], footer_len: usize) -> String { | ||
| 363 | + let mut sections: Vec<Vec<String>> = vec![Vec::new(); SECTIONS.len()]; | ||
| 364 | + let mut used = 0usize; | ||
| 365 | + 'commits: for commit in commits { | ||
| 366 | + let short = commit.oid.get(..7).unwrap_or(&commit.oid); | ||
| 367 | + let clauses: Vec<(usize, String)> = match CommitMessage::parse(&commit.summary) { | ||
| 368 | + Some(message) => message | ||
| 369 | + .groups | ||
| 370 | + .iter() | ||
| 371 | + .flat_map(|group| { | ||
| 372 | + let section = section_of(&group.kind); | ||
| 373 | + group.clauses.iter().map(move |clause| (section, clause.clone())) | ||
| 374 | + }) | ||
| 375 | + .collect(), | ||
| 376 | + None => vec![(section_of(""), commit.summary.clone())], | ||
| 377 | + }; | ||
| 378 | + for (section, text) in clauses { | ||
| 379 | + let line = format!("- {text} ({short})\n"); | ||
| 380 | + let mut len = line.chars().count(); | ||
| 381 | + if sections[section].is_empty() { | ||
| 382 | + len += SECTIONS[section].chars().count() + 6; | ||
| 383 | + } | ||
| 384 | + if used + len + footer_len > MAX_BODY_CHARS { | ||
| 385 | + break 'commits; | ||
| 386 | + } | ||
| 387 | + used += len; | ||
| 388 | + sections[section].push(line); | ||
| 389 | + } | ||
| 390 | + } | ||
| 391 | + let mut body = String::new(); | ||
| 392 | + for (name, lines) in SECTIONS.iter().zip(§ions) { | ||
| 393 | + if lines.is_empty() { | ||
| 394 | + continue; | ||
| 395 | + } | ||
| 396 | + if !body.is_empty() { | ||
| 397 | + body.push('\n'); | ||
| 398 | + } | ||
| 399 | + body.push_str(&format!("### {name}\n")); | ||
| 400 | + for line in lines { | ||
| 401 | + body.push_str(line); | ||
| 402 | + } | ||
| 403 | + } | ||
| 404 | + body | ||
| 405 | +} | ||
| 406 | + | ||
| 407 | +/// The body without trailing whitespace, then the footer after a blank line. | ||
| 408 | +fn with_footer(body: &str, footer: Option<&str>) -> String { | ||
| 318 | let mut body = body.trim_end().to_owned(); | 409 | let mut body = body.trim_end().to_owned(); |
| 319 | if let Some(footer) = footer { | 410 | if let Some(footer) = footer { |
| 320 | if !body.is_empty() { | 411 | if !body.is_empty() { |
| @@ -553,11 +644,8 @@ title = "forge {tag}" | |||
| 553 | 644 | ||
| 554 | let release = release_named(&fx, "v1.1").await.expect("release made"); | 645 | let release = release_named(&fx, "v1.1").await.expect("release made"); |
| 555 | let short = &oid[..7]; | 646 | let short = &oid[..7]; |
| 556 | - assert!( | 647 | + assert!(release.body.starts_with("### Features\n- one (")); |
| 557 | - release | 648 | + assert!(release.body.contains(&format!("### Fixes\n- two ({short})"))); |
| 558 | - .body | ||
| 559 | - .starts_with(&format!("- fix: two ({short})\n- feat: one (")) | ||
| 560 | - ); | ||
| 561 | assert!(release.body.ends_with("Full changelog: v1.0...v1.1")); | 649 | assert!(release.body.ends_with("Full changelog: v1.0...v1.1")); |
| 562 | assert!( | 650 | assert!( |
| 563 | !release.body.contains("- change ("), | 651 | !release.body.contains("- change ("), |
| @@ -729,8 +817,8 @@ title = "forge {tag}" | |||
| 729 | on_run_finished(&fx.state, &run_of(&fx, 2).await).await; | 817 | on_run_finished(&fx.state, &run_of(&fx, 2).await).await; |
| 730 | 818 | ||
| 731 | let release = release_named(&fx, "v1.1").await.expect("release made"); | 819 | let release = release_named(&fx, "v1.1").await.expect("release made"); |
| 732 | - assert!(release.body.starts_with("- fix: two (")); | 820 | + assert!(release.body.starts_with("### Features\n- one (")); |
| 733 | - assert!(release.body.contains("- feat: one (")); | 821 | + assert!(release.body.contains("### Fixes\n- two (")); |
| 734 | assert!(release.body.ends_with("Full changelog: v1.0...v1.1")); | 822 | assert!(release.body.ends_with("Full changelog: v1.0...v1.1")); |
| 735 | assert!(release_named(&fx, "v1.0").await.is_none()); | 823 | assert!(release_named(&fx, "v1.0").await.is_none()); |
| 736 | } | 824 | } |
| @@ -759,4 +847,45 @@ title = "forge {tag}" | |||
| 759 | ); | 847 | ); |
| 760 | assert_eq!(bullets(&[], None), ""); | 848 | assert_eq!(bullets(&[], None), ""); |
| 761 | } | 849 | } |
| 850 | + | ||
| 851 | + fn info(oid: &str, summary: &str) -> CommitInfo { | ||
| 852 | + CommitInfo { | ||
| 853 | + oid: oid.to_owned(), | ||
| 854 | + parents: Vec::new(), | ||
| 855 | + author_name: String::new(), | ||
| 856 | + author_email: String::new(), | ||
| 857 | + author_time: 0, | ||
| 858 | + committer_name: String::new(), | ||
| 859 | + committer_email: String::new(), | ||
| 860 | + committer_time: 0, | ||
| 861 | + summary: summary.to_owned(), | ||
| 862 | + message: String::new(), | ||
| 863 | + } | ||
| 864 | + } | ||
| 865 | + | ||
| 866 | + #[test] | ||
| 867 | + fn bullets_group_structured_commits_in_section_order() { | ||
| 868 | + let commits = vec![ | ||
| 869 | + info("aaaaaaa1111", "🐛 fix: b; ✨ feat: a"), | ||
| 870 | + info("bbbbbbb2222", "Update the readme"), | ||
| 871 | + info("ccccccc3333", "✨ feat: c"), | ||
| 872 | + ]; | ||
| 873 | + assert_eq!( | ||
| 874 | + bullets(&commits, None), | ||
| 875 | + "### Features\n- a (aaaaaaa)\n- c (ccccccc)\n\n### Fixes\n- b (aaaaaaa)\n\n### Other\n- Update the readme (bbbbbbb)" | ||
| 876 | + ); | ||
| 877 | + } | ||
| 878 | + | ||
| 879 | + #[test] | ||
| 880 | + fn bullets_count_headings_and_footer_in_the_limit() { | ||
| 881 | + let long = "x".repeat(1000); | ||
| 882 | + let commits: Vec<CommitInfo> = (0..200) | ||
| 883 | + .map(|i| info(&format!("{i:07}abcdef"), &format!("✨ feat: {long}{i}"))) | ||
| 884 | + .collect(); | ||
| 885 | + let footer = "Full changelog: a...b"; | ||
| 886 | + let body = bullets(&commits, Some(footer)); | ||
| 887 | + assert!(body.chars().count() <= MAX_BODY_CHARS); | ||
| 888 | + assert!(body.starts_with("### Features\n- ")); | ||
| 889 | + assert!(body.ends_with(footer)); | ||
| 890 | + } | ||
| 762 | } | 891 | } |
crates/forge-web/src/i18n/browse.rsmodified+3 -0
| @@ -62,6 +62,9 @@ strings! { | |||
| 62 | PaletteLoading => "Loading…", "Yükleniyor…"; | 62 | PaletteLoading => "Loading…", "Yükleniyor…"; |
| 63 | PaletteFailed => "The list could not be loaded.", "Liste yüklenemedi."; | 63 | PaletteFailed => "The list could not be loaded.", "Liste yüklenemedi."; |
| 64 | PaletteFiles => "Files", "Dosyalar"; | 64 | PaletteFiles => "Files", "Dosyalar"; |
| 65 | + PaletteActions => "Actions on this page", "Bu sayfadaki işlemler"; | ||
| 66 | + PaletteDone => "Done", "Tamamlandı"; | ||
| 67 | + PaletteActionFailed => "The action did not go through.", "İşlem gerçekleşmedi."; | ||
| 65 | 68 | ||
| 66 | BranchAuthorHeader => "Author", "Yazar"; | 69 | BranchAuthorHeader => "Author", "Yazar"; |
| 67 | BranchAheadBehindHeader => "Ahead / behind", "Önde / geride"; | 70 | BranchAheadBehindHeader => "Ahead / behind", "Önde / geride"; |
crates/forge-web/src/i18n/code.rsmodified+8 -0
| @@ -75,6 +75,7 @@ pub enum K { | |||
| 75 | AddSingleComment, | 75 | AddSingleComment, |
| 76 | CancelLink, | 76 | CancelLink, |
| 77 | ThisCommit, | 77 | ThisCommit, |
| 78 | + ShowFullMessage, | ||
| 78 | CommitStatusPrefix, | 79 | CommitStatusPrefix, |
| 79 | StateSuccess, | 80 | StateSuccess, |
| 80 | StateFailure, | 81 | StateFailure, |
| @@ -91,6 +92,7 @@ pub enum K { | |||
| 91 | CoAuthorAnd, | 92 | CoAuthorAnd, |
| 92 | CoAuthorsLabel, | 93 | CoAuthorsLabel, |
| 93 | RootCommit, | 94 | RootCommit, |
| 95 | + CommitChangesLabel, | ||
| 94 | ParentLabel, | 96 | ParentLabel, |
| 95 | BrowseFiles, | 97 | BrowseFiles, |
| 96 | SigVerified, | 98 | SigVerified, |
| @@ -266,6 +268,8 @@ pub fn t(lang: Lang, key: K) -> &'static str { | |||
| 266 | (CancelLink, Tr) => "İptal", | 268 | (CancelLink, Tr) => "İptal", |
| 267 | (ThisCommit, En) => "this commit", | 269 | (ThisCommit, En) => "this commit", |
| 268 | (ThisCommit, Tr) => "bu commit", | 270 | (ThisCommit, Tr) => "bu commit", |
| 271 | + (ShowFullMessage, En) => "Show full message", | ||
| 272 | + (ShowFullMessage, Tr) => "Tam mesajı göster", | ||
| 269 | (CommitStatusPrefix, En) => "Commit status: ", | 273 | (CommitStatusPrefix, En) => "Commit status: ", |
| 270 | (CommitStatusPrefix, Tr) => "Commit durumu: ", | 274 | (CommitStatusPrefix, Tr) => "Commit durumu: ", |
| 271 | (StateSuccess, En) => "success", | 275 | (StateSuccess, En) => "success", |
| @@ -298,6 +302,8 @@ pub fn t(lang: Lang, key: K) -> &'static str { | |||
| 298 | (CoAuthorsLabel, Tr) => "Ortak yazarlar", | 302 | (CoAuthorsLabel, Tr) => "Ortak yazarlar", |
| 299 | (RootCommit, En) => "Root commit (no parents)", | 303 | (RootCommit, En) => "Root commit (no parents)", |
| 300 | (RootCommit, Tr) => "Kök commit (üst commit yok)", | 304 | (RootCommit, Tr) => "Kök commit (üst commit yok)", |
| 305 | + (CommitChangesLabel, En) => "Changes in this commit", | ||
| 306 | + (CommitChangesLabel, Tr) => "Bu commit'teki değişiklikler", | ||
| 301 | (ParentLabel, En) => "Parent: ", | 307 | (ParentLabel, En) => "Parent: ", |
| 302 | (ParentLabel, Tr) => "Üst commit: ", | 308 | (ParentLabel, Tr) => "Üst commit: ", |
| 303 | (BrowseFiles, En) => "Browse files at this commit", | 309 | (BrowseFiles, En) => "Browse files at this commit", |
| @@ -605,6 +611,7 @@ mod tests { | |||
| 605 | K::AddSingleComment, | 611 | K::AddSingleComment, |
| 606 | K::CancelLink, | 612 | K::CancelLink, |
| 607 | K::ThisCommit, | 613 | K::ThisCommit, |
| 614 | + K::ShowFullMessage, | ||
| 608 | K::CommitStatusPrefix, | 615 | K::CommitStatusPrefix, |
| 609 | K::StateSuccess, | 616 | K::StateSuccess, |
| 610 | K::StateFailure, | 617 | K::StateFailure, |
| @@ -621,6 +628,7 @@ mod tests { | |||
| 621 | K::CoAuthorAnd, | 628 | K::CoAuthorAnd, |
| 622 | K::CoAuthorsLabel, | 629 | K::CoAuthorsLabel, |
| 623 | K::RootCommit, | 630 | K::RootCommit, |
| 631 | + K::CommitChangesLabel, | ||
| 624 | K::ParentLabel, | 632 | K::ParentLabel, |
| 625 | K::BrowseFiles, | 633 | K::BrowseFiles, |
| 626 | K::SigVerified, | 634 | K::SigVerified, |
crates/forge-web/src/i18n/misc.rsmodified+65 -0
| @@ -42,6 +42,23 @@ pub enum K { | |||
| 42 | SidebarLeft, | 42 | SidebarLeft, |
| 43 | SidebarRight, | 43 | SidebarRight, |
| 44 | ChooseSidebar, | 44 | ChooseSidebar, |
| 45 | + // Appearance: row density, and the run-finished tone. | ||
| 46 | + DensityLabel, | ||
| 47 | + DensityComfortable, | ||
| 48 | + DensityCompact, | ||
| 49 | + DensityHelp, | ||
| 50 | + ChooseDensity, | ||
| 51 | + SoundLabel, | ||
| 52 | + SoundSwitch, | ||
| 53 | + SoundOwnRuns, | ||
| 54 | + SoundPassed, | ||
| 55 | + SoundPassedNote, | ||
| 56 | + SoundFailed, | ||
| 57 | + SoundFailedNote, | ||
| 58 | + SoundPlay, | ||
| 59 | + SoundFootOwn, | ||
| 60 | + SoundFootTones, | ||
| 61 | + ChooseSound, | ||
| 45 | // Notifications: row kinds. | 62 | // Notifications: row kinds. |
| 46 | KindOpenIssue, | 63 | KindOpenIssue, |
| 47 | KindClosedIssue, | 64 | KindClosedIssue, |
| @@ -211,6 +228,22 @@ const ALL: &[K] = &[ | |||
| 211 | K::SidebarLeft, | 228 | K::SidebarLeft, |
| 212 | K::SidebarRight, | 229 | K::SidebarRight, |
| 213 | K::ChooseSidebar, | 230 | K::ChooseSidebar, |
| 231 | + K::DensityLabel, | ||
| 232 | + K::DensityComfortable, | ||
| 233 | + K::DensityCompact, | ||
| 234 | + K::DensityHelp, | ||
| 235 | + K::ChooseDensity, | ||
| 236 | + K::SoundLabel, | ||
| 237 | + K::SoundSwitch, | ||
| 238 | + K::SoundOwnRuns, | ||
| 239 | + K::SoundPassed, | ||
| 240 | + K::SoundPassedNote, | ||
| 241 | + K::SoundFailed, | ||
| 242 | + K::SoundFailedNote, | ||
| 243 | + K::SoundPlay, | ||
| 244 | + K::SoundFootOwn, | ||
| 245 | + K::SoundFootTones, | ||
| 246 | + K::ChooseSound, | ||
| 214 | K::KindOpenIssue, | 247 | K::KindOpenIssue, |
| 215 | K::KindClosedIssue, | 248 | K::KindClosedIssue, |
| 216 | K::KindOpenPull, | 249 | K::KindOpenPull, |
| @@ -399,6 +432,38 @@ pub fn t(lang: Lang, key: K) -> &'static str { | |||
| 399 | (SidebarRight, Tr) => "Sağ", | 432 | (SidebarRight, Tr) => "Sağ", |
| 400 | (ChooseSidebar, En) => "Choose a sidebar position from the list.", | 433 | (ChooseSidebar, En) => "Choose a sidebar position from the list.", |
| 401 | (ChooseSidebar, Tr) => "Listeden bir kenar çubuğu konumu seçin.", | 434 | (ChooseSidebar, Tr) => "Listeden bir kenar çubuğu konumu seçin.", |
| 435 | + (DensityLabel, En) => "Density", | ||
| 436 | + (DensityLabel, Tr) => "Yoğunluk", | ||
| 437 | + (DensityComfortable, En) => "Comfortable", | ||
| 438 | + (DensityComfortable, Tr) => "Rahat", | ||
| 439 | + (DensityCompact, En) => "Compact", | ||
| 440 | + (DensityCompact, Tr) => "Sıkı", | ||
| 441 | + (DensityHelp, En) => "Saved to your account. Compact shows more rows on a screen.", | ||
| 442 | + (DensityHelp, Tr) => "Hesabınıza kaydedilir. Sıkı görünüm ekranda daha çok satır gösterir.", | ||
| 443 | + (ChooseDensity, En) => "Choose Comfortable or Compact.", | ||
| 444 | + (ChooseDensity, Tr) => "Rahat ya da Sıkı seçin.", | ||
| 445 | + (SoundLabel, En) => "Sound", | ||
| 446 | + (SoundLabel, Tr) => "Ses", | ||
| 447 | + (SoundSwitch, En) => "Play a tone when my run finishes", | ||
| 448 | + (SoundSwitch, Tr) => "Çalıştırmam bitince bir ses çal", | ||
| 449 | + (SoundOwnRuns, En) => "Only your own runs", | ||
| 450 | + (SoundOwnRuns, Tr) => "Yalnızca kendi çalıştırmalarınız", | ||
| 451 | + (SoundPassed, En) => "Run passed", | ||
| 452 | + (SoundPassed, Tr) => "Çalıştırma başarılı", | ||
| 453 | + (SoundPassedNote, En) => "two rising notes", | ||
| 454 | + (SoundPassedNote, Tr) => "yükselen iki nota", | ||
| 455 | + (SoundFailed, En) => "Run failed", | ||
| 456 | + (SoundFailed, Tr) => "Çalıştırma başarısız", | ||
| 457 | + (SoundFailedNote, En) => "two falling notes", | ||
| 458 | + (SoundFailedNote, Tr) => "alçalan iki nota", | ||
| 459 | + (SoundPlay, En) => "Play", | ||
| 460 | + (SoundPlay, Tr) => "Çal", | ||
| 461 | + (SoundFootOwn, En) => "Never for a page you are looking at.", | ||
| 462 | + (SoundFootOwn, Tr) => "Baktığınız sayfa için asla çalmaz.", | ||
| 463 | + (SoundFootTones, En) => "Tones are made in the browser, with no audio files.", | ||
| 464 | + (SoundFootTones, Tr) => "Sesler tarayıcıda üretilir, ses dosyası yoktur.", | ||
| 465 | + (ChooseSound, En) => "Choose on or off.", | ||
| 466 | + (ChooseSound, Tr) => "Açık ya da kapalı seçin.", | ||
| 402 | (KindOpenIssue, En) => "Open issue", | 467 | (KindOpenIssue, En) => "Open issue", |
| 403 | (KindOpenIssue, Tr) => "Açık sorun", | 468 | (KindOpenIssue, Tr) => "Açık sorun", |
| 404 | (KindClosedIssue, En) => "Closed issue", | 469 | (KindClosedIssue, En) => "Closed issue", |
crates/forge-web/src/i18n/mod.rsmodified+1 -0
| @@ -31,6 +31,7 @@ pub mod link; | |||
| 31 | pub mod merge_queue; | 31 | pub mod merge_queue; |
| 32 | pub mod migrate; | 32 | pub mod migrate; |
| 33 | pub mod misc; | 33 | pub mod misc; |
| 34 | +pub mod needs; | ||
| 34 | pub mod orgs; | 35 | pub mod orgs; |
| 35 | pub mod packages; | 36 | pub mod packages; |
| 36 | pub mod pulls; | 37 | pub mod pulls; |
crates/forge-web/src/i18n/needs.rsadded+44 -0
| @@ -0,0 +1,44 @@ | |||
| 1 | +//! Strings for the `/needs-you` page and its command palette entry. | ||
| 2 | + | ||
| 3 | +use super::Lang; | ||
| 4 | + | ||
| 5 | +#[derive(Clone, Copy, Debug, PartialEq, Eq)] | ||
| 6 | +pub enum K { | ||
| 7 | + NeedsYou, | ||
| 8 | + FailedRuns, | ||
| 9 | + ReviewsRequested, | ||
| 10 | + YourPulls, | ||
| 11 | + AssignedIssues, | ||
| 12 | + Mentions, | ||
| 13 | + ChangesRequested, | ||
| 14 | + Approved, | ||
| 15 | + AllReviewRequests, | ||
| 16 | + AllClear, | ||
| 17 | +} | ||
| 18 | + | ||
| 19 | +pub fn t(lang: Lang, key: K) -> &'static str { | ||
| 20 | + use K::*; | ||
| 21 | + use Lang::*; | ||
| 22 | + match (key, lang) { | ||
| 23 | + (NeedsYou, En) => "Needs you", | ||
| 24 | + (NeedsYou, Tr) => "Sizi bekleyenler", | ||
| 25 | + (FailedRuns, En) => "Your failed runs", | ||
| 26 | + (FailedRuns, Tr) => "Başarısız çalıştırmalarınız", | ||
| 27 | + (ReviewsRequested, En) => "Reviews requested", | ||
| 28 | + (ReviewsRequested, Tr) => "İstenen incelemeler", | ||
| 29 | + (YourPulls, En) => "Your pull requests", | ||
| 30 | + (YourPulls, Tr) => "Pull request'leriniz", | ||
| 31 | + (AssignedIssues, En) => "Assigned issues", | ||
| 32 | + (AssignedIssues, Tr) => "Size atanan sorunlar", | ||
| 33 | + (Mentions, En) => "Mentions", | ||
| 34 | + (Mentions, Tr) => "Bahsetmeler", | ||
| 35 | + (ChangesRequested, En) => "Changes requested", | ||
| 36 | + (ChangesRequested, Tr) => "Değişiklik istendi", | ||
| 37 | + (Approved, En) => "Approved", | ||
| 38 | + (Approved, Tr) => "Onaylandı", | ||
| 39 | + (AllReviewRequests, En) => "All review requests", | ||
| 40 | + (AllReviewRequests, Tr) => "Tüm inceleme istekleri", | ||
| 41 | + (AllClear, En) => "Nothing is waiting on you.", | ||
| 42 | + (AllClear, Tr) => "Sizi bekleyen bir şey yok.", | ||
| 43 | + } | ||
| 44 | +} | ||
crates/forge-web/src/i18n/pulls.rsmodified+25 -0
| @@ -38,6 +38,10 @@ pub enum K { | |||
| 38 | RequestChangesChoice, | 38 | RequestChangesChoice, |
| 39 | SubmitReview, | 39 | SubmitReview, |
| 40 | DiscardPending, | 40 | DiscardPending, |
| 41 | + ViewedFiles, | ||
| 42 | + ViewedHint, | ||
| 43 | + ViewedMark, | ||
| 44 | + ChangedSinceViewed, | ||
| 41 | 45 | ||
| 42 | // pull_branch.rs | 46 | // pull_branch.rs |
| 43 | BranchErrProtected, | 47 | BranchErrProtected, |
| @@ -147,6 +151,14 @@ pub fn t(lang: Lang, key: K) -> &'static str { | |||
| 147 | (SubmitReview, Tr) => "İncelemeyi gönder", | 151 | (SubmitReview, Tr) => "İncelemeyi gönder", |
| 148 | (DiscardPending, En) => "Discard pending comments", | 152 | (DiscardPending, En) => "Discard pending comments", |
| 149 | (DiscardPending, Tr) => "Bekleyen yorumları sil", | 153 | (DiscardPending, Tr) => "Bekleyen yorumları sil", |
| 154 | + (ViewedFiles, En) => "Viewed files", | ||
| 155 | + (ViewedFiles, Tr) => "Görüntülenen dosyalar", | ||
| 156 | + (ViewedHint, En) => "v marks the focused file, n moves to the next unviewed one.", | ||
| 157 | + (ViewedHint, Tr) => "v odaktaki dosyayı işaretler, n görülmemiş sonrakine geçer.", | ||
| 158 | + (ViewedMark, En) => "Mark as viewed", | ||
| 159 | + (ViewedMark, Tr) => "Görüntülendi olarak işaretle", | ||
| 160 | + (ChangedSinceViewed, En) => "Changed since you viewed", | ||
| 161 | + (ChangedSinceViewed, Tr) => "Görüntülediğinizden beri değişti", | ||
| 150 | 162 | ||
| 151 | (BranchErrProtected, En) => "This branch is protected, so it cannot be deleted.", | 163 | (BranchErrProtected, En) => "This branch is protected, so it cannot be deleted.", |
| 152 | (BranchErrProtected, Tr) => "Bu dal korumalı olduğu için silinemez.", | 164 | (BranchErrProtected, Tr) => "Bu dal korumalı olduğu için silinemez.", |
| @@ -248,6 +260,15 @@ pub fn commit_count(lang: Lang, count: usize) -> String { | |||
| 248 | } | 260 | } |
| 249 | } | 261 | } |
| 250 | 262 | ||
| 263 | +/// The Viewed panel's count line: "2 of 16 viewed", or "2 / 16 görüldü" in Turkish, which needs no | ||
| 264 | +/// plural suffix. | ||
| 265 | +pub fn viewed_count(lang: Lang, done: usize, total: usize) -> String { | ||
| 266 | + match lang { | ||
| 267 | + Lang::En => format!("{done} of {total} viewed"), | ||
| 268 | + Lang::Tr => format!("{done} / {total} görüldü"), | ||
| 269 | + } | ||
| 270 | +} | ||
| 271 | + | ||
| 251 | /// The review bar's pending comment line. | 272 | /// The review bar's pending comment line. |
| 252 | pub fn pending_comments(lang: Lang, count: usize) -> String { | 273 | pub fn pending_comments(lang: Lang, count: usize) -> String { |
| 253 | match (lang, count) { | 274 | match (lang, count) { |
| @@ -334,6 +355,10 @@ mod tests { | |||
| 334 | K::RequestChangesChoice, | 355 | K::RequestChangesChoice, |
| 335 | K::SubmitReview, | 356 | K::SubmitReview, |
| 336 | K::DiscardPending, | 357 | K::DiscardPending, |
| 358 | + K::ViewedFiles, | ||
| 359 | + K::ViewedHint, | ||
| 360 | + K::ViewedMark, | ||
| 361 | + K::ChangedSinceViewed, | ||
| 337 | K::BranchErrProtected, | 362 | K::BranchErrProtected, |
| 338 | K::BranchErrDefault, | 363 | K::BranchErrDefault, |
| 339 | K::BranchErrMoved, | 364 | K::BranchErrMoved, |
crates/forge-web/src/i18n/releases_ci.rsmodified+44 -0
| @@ -90,6 +90,13 @@ pub enum K { | |||
| 90 | StateStopping, | 90 | StateStopping, |
| 91 | StoppingButton, | 91 | StoppingButton, |
| 92 | 92 | ||
| 93 | + // The failure block at the top of a failed run. | ||
| 94 | + FailHeading, | ||
| 95 | + FailLine, | ||
| 96 | + FailOpenLog, | ||
| 97 | + FailNoLog, | ||
| 98 | + FailNoError, | ||
| 99 | + | ||
| 93 | // Release notices, shown after a release action. | 100 | // Release notices, shown after a release action. |
| 94 | RelSaved, | 101 | RelSaved, |
| 95 | RelDeleted, | 102 | RelDeleted, |
| @@ -144,6 +151,9 @@ pub enum K { | |||
| 144 | TargetMoveHelp, | 151 | TargetMoveHelp, |
| 145 | TargetLockedHelp, | 152 | TargetLockedHelp, |
| 146 | ReplaceAsset, | 153 | ReplaceAsset, |
| 154 | + | ||
| 155 | + // CI time estimate: a running run past its expected total. | ||
| 156 | + TakingLonger, | ||
| 147 | } | 157 | } |
| 148 | 158 | ||
| 149 | pub fn t(lang: Lang, key: K) -> &'static str { | 159 | pub fn t(lang: Lang, key: K) -> &'static str { |
| @@ -275,6 +285,16 @@ pub fn t(lang: Lang, key: K) -> &'static str { | |||
| 275 | (CopyDone, Tr) => "Kopyalandı", | 285 | (CopyDone, Tr) => "Kopyalandı", |
| 276 | (CopyFailed, En) => "Copy failed", | 286 | (CopyFailed, En) => "Copy failed", |
| 277 | (CopyFailed, Tr) => "Kopyalanamadı", | 287 | (CopyFailed, Tr) => "Kopyalanamadı", |
| 288 | + (FailHeading, En) => "Failed job", | ||
| 289 | + (FailHeading, Tr) => "Başarısız iş", | ||
| 290 | + (FailLine, En) => "line", | ||
| 291 | + (FailLine, Tr) => "satır", | ||
| 292 | + (FailOpenLog, En) => "Open in full log", | ||
| 293 | + (FailOpenLog, Tr) => "Tam günlükte aç", | ||
| 294 | + (FailNoLog, En) => "This job wrote no log.", | ||
| 295 | + (FailNoLog, Tr) => "Bu iş günlük yazmadı.", | ||
| 296 | + (FailNoError, En) => "No error line found. The last lines of the log are shown.", | ||
| 297 | + (FailNoError, Tr) => "Hata satırı bulunamadı. Günlüğün son satırları gösteriliyor.", | ||
| 278 | (Duration, En) => "Duration", | 298 | (Duration, En) => "Duration", |
| 279 | (Duration, Tr) => "Süre", | 299 | (Duration, Tr) => "Süre", |
| 280 | (LogTruncated, En) => "Showing the last 512 KiB of the log. The full log is linked above.", | 300 | (LogTruncated, En) => "Showing the last 512 KiB of the log. The full log is linked above.", |
| @@ -465,6 +485,24 @@ pub fn t(lang: Lang, key: K) -> &'static str { | |||
| 465 | } | 485 | } |
| 466 | (ReplaceAsset, En) => "Replace", | 486 | (ReplaceAsset, En) => "Replace", |
| 467 | (ReplaceAsset, Tr) => "Değiştir", | 487 | (ReplaceAsset, Tr) => "Değiştir", |
| 488 | + (TakingLonger, En) => "taking longer than usual", | ||
| 489 | + (TakingLonger, Tr) => "normalden uzun sürüyor", | ||
| 490 | + } | ||
| 491 | +} | ||
| 492 | + | ||
| 493 | +/// "about 12m left", with `t` the time: a number of minutes or seconds, or the `{t}` placeholder. | ||
| 494 | +pub fn time_left(lang: Lang, t: &str) -> String { | ||
| 495 | + match lang { | ||
| 496 | + Lang::En => format!("about {t} left"), | ||
| 497 | + Lang::Tr => format!("yaklaşık {t} kaldı"), | ||
| 498 | + } | ||
| 499 | +} | ||
| 500 | + | ||
| 501 | +/// "12m", or "12 dk" in Turkish: a minutes count, or the `{m}` placeholder. | ||
| 502 | +pub fn minutes_only(lang: Lang, m: impl Display) -> String { | ||
| 503 | + match lang { | ||
| 504 | + Lang::En => format!("{m}m"), | ||
| 505 | + Lang::Tr => format!("{m} dk"), | ||
| 468 | } | 506 | } |
| 469 | } | 507 | } |
| 470 | 508 | ||
| @@ -629,6 +667,11 @@ mod tests { | |||
| 629 | K::StateSkipped, | 667 | K::StateSkipped, |
| 630 | K::StateStopping, | 668 | K::StateStopping, |
| 631 | K::StoppingButton, | 669 | K::StoppingButton, |
| 670 | + K::FailHeading, | ||
| 671 | + K::FailLine, | ||
| 672 | + K::FailOpenLog, | ||
| 673 | + K::FailNoLog, | ||
| 674 | + K::FailNoError, | ||
| 632 | K::RelSaved, | 675 | K::RelSaved, |
| 633 | K::RelDeleted, | 676 | K::RelDeleted, |
| 634 | K::RelAssetUploaded, | 677 | K::RelAssetUploaded, |
| @@ -678,6 +721,7 @@ mod tests { | |||
| 678 | K::TargetMoveHelp, | 721 | K::TargetMoveHelp, |
| 679 | K::TargetLockedHelp, | 722 | K::TargetLockedHelp, |
| 680 | K::ReplaceAsset, | 723 | K::ReplaceAsset, |
| 724 | + K::TakingLonger, | ||
| 681 | ]; | 725 | ]; |
| 682 | 726 | ||
| 683 | #[test] | 727 | #[test] |
crates/forge-web/src/pages/blame.rsmodified+2 -1
| @@ -22,6 +22,7 @@ use crate::pages::repo_ctx::load_repo; | |||
| 22 | use crate::pages::tree::{MAX_BLOB_BYTES, path_crumbs, read_file, resolve}; | 22 | use crate::pages::tree::{MAX_BLOB_BYTES, path_crumbs, read_file, resolve}; |
| 23 | use crate::render::emoji::emojify; | 23 | use crate::render::emoji::emojify; |
| 24 | use crate::state::AppState; | 24 | use crate::state::AppState; |
| 25 | +use crate::views::commit_line::commit_line; | ||
| 25 | use crate::views::{ | 26 | use crate::views::{ |
| 26 | Crumb, breadcrumb, human_size, iso_time, now_unix, relative_time, repo_href, shell, short_oid, | 27 | Crumb, breadcrumb, human_size, iso_time, now_unix, relative_time, repo_href, shell, short_oid, |
| 27 | }; | 28 | }; |
| @@ -117,7 +118,7 @@ async fn blame_table(rows: Vec<Row>, lang: Lang) -> Result<impl View> { | |||
| 117 | <span class="blame-author">(meta.author.as_str())</span> | 118 | <span class="blame-author">(meta.author.as_str())</span> |
| 118 | <time class="muted" data-rel="true" datetime=(meta.iso.as_str())>(meta.age.as_str())</time> | 119 | <time class="muted" data-rel="true" datetime=(meta.iso.as_str())>(meta.age.as_str())</time> |
| 119 | </div> | 120 | </div> |
| 120 | - <a class="blame-summary" href=(meta.commit_href.as_str()) title=(meta.summary.as_str())>(meta.summary.as_str())</a> | 121 | + <a class="blame-summary" href=(meta.commit_href.as_str()) title=(meta.summary.as_str())>commit_line(subject: meta.summary.clone(), no_tag: true)</a> |
| 121 | if let Some(prior) = meta.prior_href { | 122 | if let Some(prior) = meta.prior_href { |
| 122 | <a class="blame-prior small" href=(prior.as_str())>(b::t(lang, b::K::BlamePrior))</a> | 123 | <a class="blame-prior small" href=(prior.as_str())>(b::t(lang, b::K::BlamePrior))</a> |
| 123 | } | 124 | } |
crates/forge-web/src/pages/branches.rsmodified+2 -1
| @@ -29,6 +29,7 @@ use crate::pages::repo_ctx::{RepoCtx, load_repo}; | |||
| 29 | use crate::pages::tree::{LastCommit, last_commit_view}; | 29 | use crate::pages::tree::{LastCommit, last_commit_view}; |
| 30 | use crate::post_update::after_ref_update; | 30 | use crate::post_update::after_ref_update; |
| 31 | use crate::state::AppState; | 31 | use crate::state::AppState; |
| 32 | +use crate::views::commit_line::commit_line; | ||
| 32 | use crate::views::{alert, empty_state, iso_time, now_unix, relative_time, repo_href, shell}; | 33 | use crate::views::{alert, empty_state, iso_time, now_unix, relative_time, repo_href, shell}; |
| 33 | 34 | ||
| 34 | path_param!(owner); | 35 | path_param!(owner); |
| @@ -164,7 +165,7 @@ async fn branch_table( | |||
| 164 | </span> | 165 | </span> |
| 165 | </td> | 166 | </td> |
| 166 | if let Some(last) = row.last { | 167 | if let Some(last) = row.last { |
| 167 | - <td class="tree-commit"><a href=(last.href.as_str())>(last.summary.as_str())</a></td> | 168 | + <td class="tree-commit"><a href=(last.href.as_str())>commit_line(subject: last.summary.clone())</a></td> |
| 168 | } else { | 169 | } else { |
| 169 | <td class="tree-commit"></td> | 170 | <td class="tree-commit"></td> |
| 170 | } | 171 | } |
crates/forge-web/src/pages/ci_estimate.rsadded+248 -0
| @@ -0,0 +1,248 @@ | |||
| 1 | +//! The time left of a running CI run, estimated from its own past runs. The functions are pure: the | ||
| 2 | +//! store hands in the samples, the run's jobs go in as steps, and the answers are unix seconds, | ||
| 3 | +//! seconds or the page's words. The estimate of a job is the median of its last five successful runs | ||
| 4 | +//! on the branch, or on any branch when the branch has fewer than `MIN_SAMPLES`. Failed and cancelled | ||
| 5 | +//! runs are never sampled. | ||
| 6 | + | ||
| 7 | +use std::collections::{HashMap, HashSet}; | ||
| 8 | + | ||
| 9 | +use forge_core::ci::{JobSample, JobState}; | ||
| 10 | +use serde::Deserialize; | ||
| 11 | + | ||
| 12 | +use crate::i18n::Lang; | ||
| 13 | +use crate::i18n::releases_ci as rc; | ||
| 14 | + | ||
| 15 | +/// Samples a job needs before its estimate is trusted: a guess from fewer is worse than none. | ||
| 16 | +pub const MIN_SAMPLES: usize = 3; | ||
| 17 | + | ||
| 18 | +/// One job of a run, as the estimate reads it. Times are unix seconds. | ||
| 19 | +pub struct Step { | ||
| 20 | + pub name: String, | ||
| 21 | + pub needs: Vec<String>, | ||
| 22 | + pub state: JobState, | ||
| 23 | + pub started: Option<i64>, | ||
| 24 | + pub finished: Option<i64>, | ||
| 25 | +} | ||
| 26 | + | ||
| 27 | +/// The `needs` of a job spec, read from its JSON. A spec that does not read has none. | ||
| 28 | +pub fn needs_of(spec_json: &str) -> Vec<String> { | ||
| 29 | + #[derive(Deserialize, Default)] | ||
| 30 | + #[serde(default)] | ||
| 31 | + struct Needs { | ||
| 32 | + needs: Vec<String>, | ||
| 33 | + } | ||
| 34 | + serde_json::from_str::<Needs>(spec_json) | ||
| 35 | + .map(|spec| spec.needs) | ||
| 36 | + .unwrap_or_default() | ||
| 37 | +} | ||
| 38 | + | ||
| 39 | +/// The expected duration of `job` on `git_ref`, in seconds: the median of its durations in the newest | ||
| 40 | +/// five successful runs on that branch, or in the newest five on any branch when the branch has fewer | ||
| 41 | +/// than `MIN_SAMPLES`. None when neither has enough. | ||
| 42 | +pub fn job_expected(samples: &[JobSample], git_ref: &str, job: &str) -> Option<i64> { | ||
| 43 | + let on_branch: Vec<i64> = samples | ||
| 44 | + .iter() | ||
| 45 | + .filter(|s| s.job == job && s.git_ref == git_ref && s.branch_rank <= 5) | ||
| 46 | + .map(|s| s.secs) | ||
| 47 | + .collect(); | ||
| 48 | + if on_branch.len() >= MIN_SAMPLES { | ||
| 49 | + return Some(median(on_branch)); | ||
| 50 | + } | ||
| 51 | + let any: Vec<i64> = samples | ||
| 52 | + .iter() | ||
| 53 | + .filter(|s| s.job == job && s.repo_rank <= 5) | ||
| 54 | + .map(|s| s.secs) | ||
| 55 | + .collect(); | ||
| 56 | + (any.len() >= MIN_SAMPLES).then(|| median(any)) | ||
| 57 | +} | ||
| 58 | + | ||
| 59 | +/// The median of a list of seconds: the middle one, or the mean of the two middle ones. Zero for none. | ||
| 60 | +fn median(mut secs: Vec<i64>) -> i64 { | ||
| 61 | + secs.sort_unstable(); | ||
| 62 | + let mid = secs.len() / 2; | ||
| 63 | + match secs.len() { | ||
| 64 | + 0 => 0, | ||
| 65 | + n if n % 2 == 1 => secs[mid], | ||
| 66 | + _ => (secs[mid - 1] + secs[mid]) / 2, | ||
| 67 | + } | ||
| 68 | +} | ||
| 69 | + | ||
| 70 | +/// The unix second a run is expected to end, from its steps and the expected duration `expected` gives | ||
| 71 | +/// each job. A finished job ends when it did. A running job is due at its start plus its duration. A job | ||
| 72 | +/// not yet started begins once its needs have ended, or now. None when a job still to run has no | ||
| 73 | +/// expected duration, or the needs form a cycle. | ||
| 74 | +pub fn expected_end( | ||
| 75 | + now: i64, | ||
| 76 | + steps: &[Step], | ||
| 77 | + expected: impl Fn(&str) -> Option<i64>, | ||
| 78 | +) -> Option<i64> { | ||
| 79 | + let names: HashSet<&str> = steps.iter().map(|step| step.name.as_str()).collect(); | ||
| 80 | + let mut ends: HashMap<&str, i64> = HashMap::new(); | ||
| 81 | + let mut pending: Vec<&Step> = steps.iter().collect(); | ||
| 82 | + while !pending.is_empty() { | ||
| 83 | + let mut waiting = Vec::new(); | ||
| 84 | + for &step in &pending { | ||
| 85 | + let ready = step | ||
| 86 | + .needs | ||
| 87 | + .iter() | ||
| 88 | + .all(|need| ends.contains_key(need.as_str()) || !names.contains(need.as_str())); | ||
| 89 | + if !ready { | ||
| 90 | + waiting.push(step); | ||
| 91 | + continue; | ||
| 92 | + } | ||
| 93 | + let end = step_end(now, step, &ends, &expected)?; | ||
| 94 | + ends.insert(step.name.as_str(), end); | ||
| 95 | + } | ||
| 96 | + if waiting.len() == pending.len() { | ||
| 97 | + return None; | ||
| 98 | + } | ||
| 99 | + pending = waiting; | ||
| 100 | + } | ||
| 101 | + ends.values().copied().max() | ||
| 102 | +} | ||
| 103 | + | ||
| 104 | +/// When one step ends, given the ends of the steps placed before it. | ||
| 105 | +fn step_end( | ||
| 106 | + now: i64, | ||
| 107 | + step: &Step, | ||
| 108 | + ends: &HashMap<&str, i64>, | ||
| 109 | + expected: &impl Fn(&str) -> Option<i64>, | ||
| 110 | +) -> Option<i64> { | ||
| 111 | + if step.state.is_terminal() { | ||
| 112 | + return Some(step.finished.unwrap_or(0)); | ||
| 113 | + } | ||
| 114 | + let duration = expected(step.name.as_str())?; | ||
| 115 | + let start = match step.started { | ||
| 116 | + Some(started) => started, | ||
| 117 | + None => step | ||
| 118 | + .needs | ||
| 119 | + .iter() | ||
| 120 | + .filter_map(|need| ends.get(need.as_str()).copied()) | ||
| 121 | + .fold(now, i64::max), | ||
| 122 | + }; | ||
| 123 | + Some(start + duration) | ||
| 124 | +} | ||
| 125 | + | ||
| 126 | +/// The expected end of a run whose jobs are `steps`, on `git_ref`, judged from the `samples` of the | ||
| 127 | +/// repo's successful runs. | ||
| 128 | +pub fn run_end(now: i64, steps: &[Step], samples: &[JobSample], git_ref: &str) -> Option<i64> { | ||
| 129 | + expected_end(now, steps, |name| job_expected(samples, git_ref, name)) | ||
| 130 | +} | ||
| 131 | + | ||
| 132 | +/// How far a run is through its expected total, with `elapsed` and `total` in seconds: the bar's | ||
| 133 | +/// fraction, never past full, and the seconds left. Past the estimate there is no time left. | ||
| 134 | +pub fn progress(elapsed: i64, total: i64) -> (f64, Option<i64>) { | ||
| 135 | + if total <= 0 || elapsed >= total { | ||
| 136 | + return (1.0, None); | ||
| 137 | + } | ||
| 138 | + (elapsed.max(0) as f64 / total as f64, Some(total - elapsed)) | ||
| 139 | +} | ||
| 140 | + | ||
| 141 | +/// A live run's estimate as its page draws it, every value already text. The ticker rewrites the | ||
| 142 | +/// words from the templates. | ||
| 143 | +pub struct Est { | ||
| 144 | + /// The expected total in seconds, counted from the origin the page shows the elapsed time from. | ||
| 145 | + pub expected: String, | ||
| 146 | + /// The bar's fill, 0 to 100. | ||
| 147 | + pub pct: String, | ||
| 148 | + /// The words after the elapsed time: "about 12m left", or "taking longer than usual". | ||
| 149 | + pub phrase: String, | ||
| 150 | + /// The phrase for seconds left, with `{t}` for the time. | ||
| 151 | + pub left: String, | ||
| 152 | + /// The words past the estimate. | ||
| 153 | + pub over: String, | ||
| 154 | + /// The minutes form of a time, with `{m}`. | ||
| 155 | + pub minutes: String, | ||
| 156 | +} | ||
| 157 | + | ||
| 158 | +/// The estimate of a run that began at `origin`, is `now` by the clock, and is expected to end at | ||
| 159 | +/// `end`. | ||
| 160 | +pub fn estimate(lang: Lang, origin: i64, now: i64, end: i64) -> Est { | ||
| 161 | + let total = (end - origin).max(0); | ||
| 162 | + let (fraction, left) = progress(now - origin, total); | ||
| 163 | + let phrase = match left { | ||
| 164 | + Some(secs) => rc::time_left(lang, &left_text(lang, secs)), | ||
| 165 | + None => rc::t(lang, rc::K::TakingLonger).to_owned(), | ||
| 166 | + }; | ||
| 167 | + Est { | ||
| 168 | + expected: total.to_string(), | ||
| 169 | + pct: ((fraction * 100.0).round() as u32).to_string(), | ||
| 170 | + phrase, | ||
| 171 | + left: rc::time_left(lang, "{t}"), | ||
| 172 | + over: rc::t(lang, rc::K::TakingLonger).to_owned(), | ||
| 173 | + minutes: rc::minutes_only(lang, "{m}"), | ||
| 174 | + } | ||
| 175 | +} | ||
| 176 | + | ||
| 177 | +/// Seconds left as the page words them: whole minutes rounded up from a minute, else seconds. | ||
| 178 | +fn left_text(lang: Lang, secs: i64) -> String { | ||
| 179 | + if secs >= 60 { | ||
| 180 | + rc::minutes_only(lang, (secs + 59) / 60) | ||
| 181 | + } else { | ||
| 182 | + rc::duration_seconds(lang, secs) | ||
| 183 | + } | ||
| 184 | +} | ||
| 185 | + | ||
| 186 | +#[cfg(test)] | ||
| 187 | +mod tests { | ||
| 188 | + use super::*; | ||
| 189 | + | ||
| 190 | + fn sample(git_ref: &str, branch_rank: i64, repo_rank: i64, secs: i64) -> JobSample { | ||
| 191 | + JobSample { | ||
| 192 | + git_ref: git_ref.to_owned(), | ||
| 193 | + branch_rank, | ||
| 194 | + repo_rank, | ||
| 195 | + job: "test".to_owned(), | ||
| 196 | + secs, | ||
| 197 | + } | ||
| 198 | + } | ||
| 199 | + | ||
| 200 | + #[test] | ||
| 201 | + fn job_estimate_needs_three_samples_and_falls_back_to_any_branch() { | ||
| 202 | + let two = [sample("main", 1, 1, 60), sample("main", 2, 2, 80)]; | ||
| 203 | + assert_eq!(job_expected(&two, "main", "test"), None); | ||
| 204 | + | ||
| 205 | + let three = [ | ||
| 206 | + sample("main", 1, 1, 60), | ||
| 207 | + sample("main", 2, 2, 100), | ||
| 208 | + sample("main", 3, 3, 90), | ||
| 209 | + ]; | ||
| 210 | + assert_eq!(job_expected(&three, "main", "test"), Some(90)); | ||
| 211 | + | ||
| 212 | + // The branch has two; the repo's newest five on any branch give the median 100. | ||
| 213 | + let fallback = [ | ||
| 214 | + sample("main", 1, 1, 60), | ||
| 215 | + sample("main", 2, 2, 80), | ||
| 216 | + sample("dev", 1, 3, 100), | ||
| 217 | + sample("dev", 2, 4, 120), | ||
| 218 | + sample("dev", 3, 5, 110), | ||
| 219 | + ]; | ||
| 220 | + assert_eq!(job_expected(&fallback, "main", "test"), Some(100)); | ||
| 221 | + } | ||
| 222 | + | ||
| 223 | + #[test] | ||
| 224 | + fn a_queued_job_waits_for_its_need_and_progress_never_goes_negative() { | ||
| 225 | + // a started at 100 and is due at 150; b needs a, so it is due at 150 + 30. | ||
| 226 | + let steps = [ | ||
| 227 | + Step { | ||
| 228 | + name: "a".to_owned(), | ||
| 229 | + needs: Vec::new(), | ||
| 230 | + state: JobState::Running, | ||
| 231 | + started: Some(100), | ||
| 232 | + finished: None, | ||
| 233 | + }, | ||
| 234 | + Step { | ||
| 235 | + name: "b".to_owned(), | ||
| 236 | + needs: vec!["a".to_owned()], | ||
| 237 | + state: JobState::Queued, | ||
| 238 | + started: None, | ||
| 239 | + finished: None, | ||
| 240 | + }, | ||
| 241 | + ]; | ||
| 242 | + let end = expected_end(120, &steps, |name| Some(if name == "a" { 50 } else { 30 })); | ||
| 243 | + assert_eq!(end, Some(180)); | ||
| 244 | + | ||
| 245 | + assert_eq!(progress(30, 60), (0.5, Some(30))); | ||
| 246 | + assert_eq!(progress(90, 60), (1.0, None)); | ||
| 247 | + } | ||
| 248 | +} | ||
crates/forge-web/src/pages/ci_fail.rsadded+181 -0
| @@ -0,0 +1,181 @@ | |||
| 1 | +//! The failure block at the top of a failed run's page: the first failed job, its message, the lines of | ||
| 2 | +//! its log around the first error, and a link to that line in the job page's numbered log. Steps are | ||
| 3 | +//! not stored, so the failed job is the unit. The log is untrusted: its lines are rendered as text. | ||
| 4 | + | ||
| 5 | +use std::ops::Range; | ||
| 6 | + | ||
| 7 | +use topcoat::Result; | ||
| 8 | +use topcoat::view::{View, component, view}; | ||
| 9 | + | ||
| 10 | +use crate::ci::log_path; | ||
| 11 | +use crate::i18n::{ | ||
| 12 | + Lang, | ||
| 13 | + releases_ci::{self as g, K}, | ||
| 14 | +}; | ||
| 15 | +use crate::pages::ci_job::log_tail; | ||
| 16 | +use crate::pages::ci_runs::{job_href, strip_ansi}; | ||
| 17 | +use crate::state::AppState; | ||
| 18 | + | ||
| 19 | +/// Most lines the block shows. | ||
| 20 | +const WINDOW: usize = 30; | ||
| 21 | +/// Lines kept before the first error. | ||
| 22 | +const BEFORE: usize = 5; | ||
| 23 | +/// Lines shown when no line matches an error pattern. | ||
| 24 | +const FALLBACK: usize = 20; | ||
| 25 | +/// Patterns that mark an error line. Matching is case-sensitive, which keeps prose such as "error | ||
| 26 | +/// handling" out. `FAILED` also covers `test result: FAILED`. | ||
| 27 | +const PATTERNS: [&str; 6] = [ | ||
| 28 | + "error:", | ||
| 29 | + "error[E", | ||
| 30 | + "FAILED", | ||
| 31 | + "panicked at", | ||
| 32 | + "npm ERR!", | ||
| 33 | + "fatal:", | ||
| 34 | +]; | ||
| 35 | + | ||
| 36 | +/// The index of the first line that matches an error pattern. | ||
| 37 | +fn first_error(lines: &[String]) -> Option<usize> { | ||
| 38 | + lines | ||
| 39 | + .iter() | ||
| 40 | + .position(|line| PATTERNS.iter().any(|pattern| line.contains(pattern))) | ||
| 41 | +} | ||
| 42 | + | ||
| 43 | +/// The indices of the lines to show for a failed step's log: at most 30 lines, starting 5 lines before | ||
| 44 | +/// the first line that matches an error pattern. With no match, the last 20 lines. | ||
| 45 | +pub(crate) fn error_range(lines: &[String]) -> Range<usize> { | ||
| 46 | + let len = lines.len(); | ||
| 47 | + match first_error(lines) { | ||
| 48 | + Some(hit) => { | ||
| 49 | + let start = hit.saturating_sub(BEFORE).min(len.saturating_sub(WINDOW)); | ||
| 50 | + start..(start + WINDOW).min(len) | ||
| 51 | + } | ||
| 52 | + None => len.saturating_sub(FALLBACK)..len, | ||
| 53 | + } | ||
| 54 | +} | ||
| 55 | + | ||
| 56 | +/// One shown line: its number in the whole job log, its text without ANSI codes, and whether it is | ||
| 57 | +/// the first error. | ||
| 58 | +#[derive(Clone)] | ||
| 59 | +pub(crate) struct FailLine { | ||
| 60 | + no: u64, | ||
| 61 | + text: String, | ||
| 62 | + hit: bool, | ||
| 63 | +} | ||
| 64 | + | ||
| 65 | +/// The values of the failure block, read once per run page. | ||
| 66 | +#[derive(Clone)] | ||
| 67 | +pub(crate) struct FailFirst { | ||
| 68 | + job_name: String, | ||
| 69 | + job_href: String, | ||
| 70 | + message: String, | ||
| 71 | + has_log: bool, | ||
| 72 | + /// The job's number for the first error line, when a line matched. | ||
| 73 | + line_no: Option<u64>, | ||
| 74 | + lines: Vec<FailLine>, | ||
| 75 | +} | ||
| 76 | + | ||
| 77 | +/// Reads the failed job's log tail (the same bounded read as the job page) and picks the lines to show. | ||
| 78 | +pub(crate) async fn read( | ||
| 79 | + state: &AppState, | ||
| 80 | + title: &str, | ||
| 81 | + job_id: &str, | ||
| 82 | + job_name: &str, | ||
| 83 | + message: &str, | ||
| 84 | +) -> Result<FailFirst> { | ||
| 85 | + let tail = log_tail(&log_path(&state.config.data_dir, job_id)).await?; | ||
| 86 | + let mut all: Vec<String> = tail.text.lines().map(strip_ansi).collect(); | ||
| 87 | + while all.last().is_some_and(|line| line.trim().is_empty()) { | ||
| 88 | + all.pop(); | ||
| 89 | + } | ||
| 90 | + let hit = first_error(&all); | ||
| 91 | + let range = error_range(&all); | ||
| 92 | + let start = range.start; | ||
| 93 | + let lines = all[range] | ||
| 94 | + .iter() | ||
| 95 | + .enumerate() | ||
| 96 | + .map(|(k, text)| { | ||
| 97 | + let index = start + k; | ||
| 98 | + FailLine { | ||
| 99 | + no: tail.first_line + index as u64, | ||
| 100 | + text: text.clone(), | ||
| 101 | + hit: hit == Some(index), | ||
| 102 | + } | ||
| 103 | + }) | ||
| 104 | + .collect(); | ||
| 105 | + Ok(FailFirst { | ||
| 106 | + job_name: job_name.to_owned(), | ||
| 107 | + job_href: job_href(title, job_id), | ||
| 108 | + message: message.to_owned(), | ||
| 109 | + has_log: !all.is_empty(), | ||
| 110 | + line_no: hit.map(|index| tail.first_line + index as u64), | ||
| 111 | + lines, | ||
| 112 | + }) | ||
| 113 | +} | ||
| 114 | + | ||
| 115 | +/// The failure block. The job's name links to its page; the first error links to its line there. | ||
| 116 | +#[component] | ||
| 117 | +pub(crate) async fn fail_first_block(lang: Lang, fail: FailFirst) -> Result<impl View> { | ||
| 118 | + let line_href = fail | ||
| 119 | + .line_no | ||
| 120 | + .map(|no| format!("{}#L{no}", fail.job_href)); | ||
| 121 | + Ok(view! { | ||
| 122 | + <section class="fail-first" data-fail-first="true"> | ||
| 123 | + <p class="fail-first-head"> | ||
| 124 | + <span class="fail-first-tag">(g::t(lang, K::FailHeading))</span> | ||
| 125 | + " " <a href=(fail.job_href.as_str())>(fail.job_name.as_str())</a> | ||
| 126 | + </p> | ||
| 127 | + if !fail.message.is_empty() { | ||
| 128 | + <p class="fail-first-msg">(fail.message.as_str())</p> | ||
| 129 | + } | ||
| 130 | + if !fail.has_log { | ||
| 131 | + <p class="muted small">(g::t(lang, K::FailNoLog))</p> | ||
| 132 | + } else { | ||
| 133 | + if let (Some(href), Some(no)) = (line_href.as_ref(), fail.line_no) { | ||
| 134 | + <p class="small"><a href=(href.as_str())>(g::t(lang, K::FailOpenLog))</a> " \u{b7} " (g::t(lang, K::FailLine)) " " (no)</p> | ||
| 135 | + } else { | ||
| 136 | + <p class="muted small">(g::t(lang, K::FailNoError))</p> | ||
| 137 | + } | ||
| 138 | + <div class="fail-first-log"> | ||
| 139 | + for line in fail.lines.iter() { | ||
| 140 | + <div class=(if line.hit { "fail-first-ln fail-first-hit" } else { "fail-first-ln" })><i>(line.no)</i><span>(line.text.as_str())</span></div> | ||
| 141 | + } | ||
| 142 | + </div> | ||
| 143 | + } | ||
| 144 | + </section> | ||
| 145 | + }) | ||
| 146 | +} | ||
| 147 | + | ||
| 148 | +#[cfg(test)] | ||
| 149 | +mod tests { | ||
| 150 | + use super::{FALLBACK, WINDOW, error_range}; | ||
| 151 | + | ||
| 152 | + fn lines(count: usize) -> Vec<String> { | ||
| 153 | + (0..count).map(|i| format!("line {i}")).collect() | ||
| 154 | + } | ||
| 155 | + | ||
| 156 | + #[test] | ||
| 157 | + fn the_first_error_opens_a_window_of_at_most_thirty_lines() { | ||
| 158 | + let mut log = lines(40); | ||
| 159 | + log[12] = "error[E0425]: cannot find value".to_owned(); | ||
| 160 | + log[20] = "error: later one".to_owned(); | ||
| 161 | + let range = error_range(&log); | ||
| 162 | + assert_eq!(range, 7..37); | ||
| 163 | + assert!(range.len() <= WINDOW); | ||
| 164 | + assert!(range.contains(&12)); | ||
| 165 | + } | ||
| 166 | + | ||
| 167 | + #[test] | ||
| 168 | + fn a_match_near_the_end_keeps_a_full_window() { | ||
| 169 | + let mut log = lines(40); | ||
| 170 | + log[39] = "thread 'x' panicked at src/lib.rs:3".to_owned(); | ||
| 171 | + assert_eq!(error_range(&log), 10..40); | ||
| 172 | + } | ||
| 173 | + | ||
| 174 | + #[test] | ||
| 175 | + fn without_an_error_the_last_lines_are_shown() { | ||
| 176 | + let log = lines(100); | ||
| 177 | + assert_eq!(error_range(&log), (100 - FALLBACK)..100); | ||
| 178 | + assert_eq!(error_range(&lines(5)), 0..5); | ||
| 179 | + assert_eq!(error_range(&[]), 0..0); | ||
| 180 | + } | ||
| 181 | +} | ||
crates/forge-web/src/pages/ci_job.rsmodified+6 -6
| @@ -81,11 +81,11 @@ fn whole_utf8_len(buf: &[u8]) -> usize { | |||
| 81 | 81 | ||
| 82 | /// What the job page shows of a log: the text, whether the start was cut, the byte offset just | 82 | /// What the job page shows of a log: the text, whether the start was cut, the byte offset just |
| 83 | /// past the text, and the number of its first line in the whole log. | 83 | /// past the text, and the number of its first line in the whole log. |
| 84 | -struct Tail { | 84 | +pub(crate) struct Tail { |
| 85 | - text: String, | 85 | + pub(crate) text: String, |
| 86 | truncated: bool, | 86 | truncated: bool, |
| 87 | offset: u64, | 87 | offset: u64, |
| 88 | - first_line: u64, | 88 | + pub(crate) first_line: u64, |
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | /// The number of newlines in the first `end` bytes of the file, so a cut log keeps true line numbers. | 91 | /// The number of newlines in the first `end` bytes of the file, so a cut log keeps true line numbers. |
| @@ -112,7 +112,7 @@ async fn newlines_before(path: &Path, end: u64) -> Result<u64> { | |||
| 112 | } | 112 | } |
| 113 | 113 | ||
| 114 | /// The last `TAIL_BYTES` of a log, from a line boundary. A log that does not exist yet is empty. | 114 | /// The last `TAIL_BYTES` of a log, from a line boundary. A log that does not exist yet is empty. |
| 115 | -async fn log_tail(path: &Path) -> Result<Tail> { | 115 | +pub(crate) async fn log_tail(path: &Path) -> Result<Tail> { |
| 116 | let mut file = match tokio::fs::File::open(path).await { | 116 | let mut file = match tokio::fs::File::open(path).await { |
| 117 | Ok(file) => file, | 117 | Ok(file) => file, |
| 118 | Err(e) if e.kind() == std::io::ErrorKind::NotFound => { | 118 | Err(e) if e.kind() == std::io::ErrorKind::NotFound => { |
| @@ -377,7 +377,7 @@ async fn job_body( | |||
| 377 | <div class="ci-actions"> | 377 | <div class="ci-actions"> |
| 378 | <form method="post" action=(action.as_str()) class="inline-form"> | 378 | <form method="post" action=(action.as_str()) class="inline-form"> |
| 379 | <input type="hidden" name="csrf" value=(csrf.as_str())> | 379 | <input type="hidden" name="csrf" value=(csrf.as_str())> |
| 380 | - <button type="submit">(g::t(lang, K::RerunJob))</button> | 380 | + <button type="submit" data-palette-action="post">(g::t(lang, K::RerunJob))</button> |
| 381 | </form> | 381 | </form> |
| 382 | </div> | 382 | </div> |
| 383 | } | 383 | } |
| @@ -393,7 +393,7 @@ async fn job_body( | |||
| 393 | <span class="ci-logcount" data-log-count="true" data-none=(g::t(lang, K::LogNoMatches)) aria-live="polite"></span> | 393 | <span class="ci-logcount" data-log-count="true" data-none=(g::t(lang, K::LogNoMatches)) aria-live="polite"></span> |
| 394 | <button type="button" class="ci-mini" data-log-prev="true" aria-label=(g::t(lang, K::LogPrev)) title=(g::t(lang, K::LogPrev))>"\u{2191}"</button> | 394 | <button type="button" class="ci-mini" data-log-prev="true" aria-label=(g::t(lang, K::LogPrev)) title=(g::t(lang, K::LogPrev))>"\u{2191}"</button> |
| 395 | <button type="button" class="ci-mini" data-log-next="true" aria-label=(g::t(lang, K::LogNext)) title=(g::t(lang, K::LogNext))>"\u{2193}"</button> | 395 | <button type="button" class="ci-mini" data-log-next="true" aria-label=(g::t(lang, K::LogNext)) title=(g::t(lang, K::LogNext))>"\u{2193}"</button> |
| 396 | - <button type="button" class="ci-mini" data-copy-log=(job.log_href.as_str()) data-copied=(g::t(lang, K::CopyDone)) data-failed=(g::t(lang, K::CopyFailed))>(g::t(lang, K::CopyLog))</button> | 396 | + <button type="button" class="ci-mini" data-copy-log=(job.log_href.as_str()) data-palette-action="click" data-copied=(g::t(lang, K::CopyDone)) data-failed=(g::t(lang, K::CopyFailed))>(g::t(lang, K::CopyLog))</button> |
| 397 | <span class="ci-logfold" data-log-fold-box="true" hidden="hidden"> | 397 | <span class="ci-logfold" data-log-fold-box="true" hidden="hidden"> |
| 398 | <button type="button" class="ci-mini" data-log-fold="close">(g::t(lang, K::LogCollapseAll))</button> | 398 | <button type="button" class="ci-mini" data-log-fold="close">(g::t(lang, K::LogCollapseAll))</button> |
| 399 | <button type="button" class="ci-mini" data-log-fold="open">(g::t(lang, K::LogExpandAll))</button> | 399 | <button type="button" class="ci-mini" data-log-fold="open">(g::t(lang, K::LogExpandAll))</button> |
crates/forge-web/src/pages/ci_runs.rsmodified+113 -16
| @@ -13,7 +13,7 @@ use std::future::Future; | |||
| 13 | use std::path::Path; | 13 | use std::path::Path; |
| 14 | use std::time::Duration; | 14 | use std::time::Duration; |
| 15 | 15 | ||
| 16 | -use forge_core::ci::{CiJob, CiRun, JobState, RunState}; | 16 | +use forge_core::ci::{CiJob, CiRun, JobSample, JobState, RunState}; |
| 17 | use forge_core::{Action, Denied, Store, User, authorize}; | 17 | use forge_core::{Action, Denied, Store, User, authorize}; |
| 18 | use forge_git::browse::{RefInfo, RefKind, read_commit}; | 18 | use forge_git::browse::{RefInfo, RefKind, read_commit}; |
| 19 | use futures_util::{Stream, StreamExt, stream}; | 19 | use futures_util::{Stream, StreamExt, stream}; |
| @@ -38,10 +38,13 @@ use crate::i18n::{ | |||
| 38 | self, Lang, | 38 | self, Lang, |
| 39 | releases_ci::{self as g, K}, | 39 | releases_ci::{self as g, K}, |
| 40 | }; | 40 | }; |
| 41 | +use crate::pages::ci_estimate::{self, Est, Step}; | ||
| 42 | +use crate::pages::ci_fail::{self, FailFirst, fail_first_block}; | ||
| 41 | use crate::pages::refs::load_refs; | 43 | use crate::pages::refs::load_refs; |
| 42 | use crate::pages::repo::repo_head; | 44 | use crate::pages::repo::repo_head; |
| 43 | use crate::pages::repo_ctx::{RepoCtx, RepoHead, load_repo, still_readable}; | 45 | use crate::pages::repo_ctx::{RepoCtx, RepoHead, load_repo, still_readable}; |
| 44 | use crate::state::AppState; | 46 | use crate::state::AppState; |
| 47 | +use crate::views::commit_line::{commit_line, headline}; | ||
| 45 | use crate::views::{alert, empty_state, enc, human_size, now_unix, rel_time, relative_time, shell, short_oid}; | 48 | use crate::views::{alert, empty_state, enc, human_size, now_unix, rel_time, relative_time, shell, short_oid}; |
| 46 | 49 | ||
| 47 | path_param!(owner); | 50 | path_param!(owner); |
| @@ -340,6 +343,8 @@ struct RunRow { | |||
| 340 | /// The run's start and the list's scale, which the ticker needs to grow the running segments. | 343 | /// The run's start and the list's scale, which the ticker needs to grow the running segments. |
| 341 | origin: String, | 344 | origin: String, |
| 342 | scale: String, | 345 | scale: String, |
| 346 | + /// The expected total of a running run, from its past runs. None when no estimate can be made. | ||
| 347 | + est: Option<Est>, | ||
| 343 | meta: RowMeta, | 348 | meta: RowMeta, |
| 344 | } | 349 | } |
| 345 | 350 | ||
| @@ -426,6 +431,8 @@ struct RunDetail { | |||
| 426 | duration: String, | 431 | duration: String, |
| 427 | /// Unix seconds the header duration counts from while the run is not finished. | 432 | /// Unix seconds the header duration counts from while the run is not finished. |
| 428 | since: Option<String>, | 433 | since: Option<String>, |
| 434 | + /// The expected total of a running run, from its past runs. | ||
| 435 | + est: Option<Est>, | ||
| 429 | config_error: Option<String>, | 436 | config_error: Option<String>, |
| 430 | action_base: String, | 437 | action_base: String, |
| 431 | can_approve: bool, | 438 | can_approve: bool, |
| @@ -441,6 +448,8 @@ struct RunDetail { | |||
| 441 | zip_href: Option<String>, | 448 | zip_href: Option<String>, |
| 442 | writer_csrf: Option<String>, | 449 | writer_csrf: Option<String>, |
| 443 | gantt: Option<Gantt>, | 450 | gantt: Option<Gantt>, |
| 451 | + /// The failed job and its first error, shown above the timeline of a failed run. | ||
| 452 | + failing: Option<FailFirst>, | ||
| 444 | jobs: Vec<JobLine>, | 453 | jobs: Vec<JobLine>, |
| 445 | } | 454 | } |
| 446 | 455 | ||
| @@ -453,6 +462,8 @@ struct Rect { | |||
| 453 | h: String, | 462 | h: String, |
| 454 | /// How the client's ticker moves this box with the clock: `grow`, `edge`, `follow` or `rest`. | 463 | /// How the client's ticker moves this box with the clock: `grow`, `edge`, `follow` or `rest`. |
| 455 | tick: Option<String>, | 464 | tick: Option<String>, |
| 465 | + /// A list bar's segment key (its job's id): a live swap matches the old and new segment by it. | ||
| 466 | + key: Option<String>, | ||
| 456 | /// A job's box on the timeline: its row (`data-j`), the rows it is linked with (`data-rel`, for | 467 | /// A job's box on the timeline: its row (`data-j`), the rows it is linked with (`data-rel`, for |
| 457 | /// the hover highlight) and its name with what it needs, for hover and screen readers. | 468 | /// the hover highlight) and its name with what it needs, for hover and screen readers. |
| 458 | job: Option<String>, | 469 | job: Option<String>, |
| @@ -469,6 +480,7 @@ impl Rect { | |||
| 469 | w: w.to_string(), | 480 | w: w.to_string(), |
| 470 | h: h.to_string(), | 481 | h: h.to_string(), |
| 471 | tick: None, | 482 | tick: None, |
| 483 | + key: None, | ||
| 472 | job: None, | 484 | job: None, |
| 473 | rel: None, | 485 | rel: None, |
| 474 | title: None, | 486 | title: None, |
| @@ -770,6 +782,7 @@ fn row_bar(jobs: &[Timing], origin: i64, scale: i64, now: i64, running: bool) -> | |||
| 770 | if job.finished.is_none() { | 782 | if job.finished.is_none() { |
| 771 | seg = seg.ticking("grow"); | 783 | seg = seg.ticking("grow"); |
| 772 | } | 784 | } |
| 785 | + seg.key = Some(job.id.clone()); | ||
| 773 | bar.push(seg); | 786 | bar.push(seg); |
| 774 | } | 787 | } |
| 775 | if running { | 788 | if running { |
| @@ -1087,6 +1100,23 @@ fn gantt(jobs: &[Timing], origin: i64, run_end: Option<i64>, now: i64, lang: Lan | |||
| 1087 | g | 1100 | g |
| 1088 | } | 1101 | } |
| 1089 | 1102 | ||
| 1103 | +/// The estimate of a running run: the time its jobs are expected to take, judged from the repo's | ||
| 1104 | +/// samples. None when a job still to run has no estimate yet. | ||
| 1105 | +fn live_est(lang: Lang, run: &CiRun, jobs: &[Timing], samples: &[JobSample], now: i64) -> Option<Est> { | ||
| 1106 | + let steps: Vec<Step> = jobs | ||
| 1107 | + .iter() | ||
| 1108 | + .map(|job| Step { | ||
| 1109 | + name: job.name.clone(), | ||
| 1110 | + needs: job.needs.clone(), | ||
| 1111 | + state: job.state, | ||
| 1112 | + started: job.started, | ||
| 1113 | + finished: job.finished, | ||
| 1114 | + }) | ||
| 1115 | + .collect(); | ||
| 1116 | + let end = ci_estimate::run_end(now, &steps, samples, &run.git_ref)?; | ||
| 1117 | + Some(ci_estimate::estimate(lang, origin_of(run, now), now, end)) | ||
| 1118 | +} | ||
| 1119 | + | ||
| 1090 | /// The timings of a run's jobs, in job order, with runner names from `runners`. | 1120 | /// The timings of a run's jobs, in job order, with runner names from `runners`. |
| 1091 | async fn timings_of( | 1121 | async fn timings_of( |
| 1092 | state: &AppState, | 1122 | state: &AppState, |
| @@ -1165,7 +1195,7 @@ fn row_meta(run: &CiRun, jobs: &[Timing], actor: &str, lang: Lang) -> RowMeta { | |||
| 1165 | } | 1195 | } |
| 1166 | 1196 | ||
| 1167 | /// Drops the ANSI escape sequences and the other control characters (a tab stays) of a log line. | 1197 | /// Drops the ANSI escape sequences and the other control characters (a tab stays) of a log line. |
| 1168 | -fn strip_ansi(line: &str) -> String { | 1198 | +pub(crate) fn strip_ansi(line: &str) -> String { |
| 1169 | let mut out = String::with_capacity(line.len()); | 1199 | let mut out = String::with_capacity(line.len()); |
| 1170 | let mut chars = line.chars().peekable(); | 1200 | let mut chars = line.chars().peekable(); |
| 1171 | while let Some(c) = chars.next() { | 1201 | while let Some(c) = chars.next() { |
| @@ -1259,7 +1289,7 @@ async fn action_button(action: String, csrf: String, label: &'static str) -> Res | |||
| 1259 | Ok(view! { | 1289 | Ok(view! { |
| 1260 | <form method="post" action=(action.as_str()) class="inline-form"> | 1290 | <form method="post" action=(action.as_str()) class="inline-form"> |
| 1261 | <input type="hidden" name="csrf" value=(csrf.as_str())> | 1291 | <input type="hidden" name="csrf" value=(csrf.as_str())> |
| 1262 | - <button type="submit">(label)</button> | 1292 | + <button type="submit" data-palette-action="post">(label)</button> |
| 1263 | </form> | 1293 | </form> |
| 1264 | }) | 1294 | }) |
| 1265 | } | 1295 | } |
| @@ -1334,6 +1364,19 @@ async fn runs_split(cx: &Cx, number: Option<&str>) -> Result<SplitPage> { | |||
| 1334 | for run in runs.iter() { | 1364 | for run in runs.iter() { |
| 1335 | timings.push(timings_of(state, &run.id, &runners, lang).await?); | 1365 | timings.push(timings_of(state, &run.id, &runners, lang).await?); |
| 1336 | } | 1366 | } |
| 1367 | + // The samples of the live runs' branches: one query for the whole page. | ||
| 1368 | + let mut live_refs: Vec<String> = runs | ||
| 1369 | + .iter() | ||
| 1370 | + .filter(|run| run.state == RunState::Running) | ||
| 1371 | + .map(|run| run.git_ref.clone()) | ||
| 1372 | + .collect(); | ||
| 1373 | + live_refs.sort(); | ||
| 1374 | + live_refs.dedup(); | ||
| 1375 | + let samples = if live_refs.is_empty() { | ||
| 1376 | + Vec::new() | ||
| 1377 | + } else { | ||
| 1378 | + state.store.recent_job_samples(&ctx.repo.id, &live_refs).await? | ||
| 1379 | + }; | ||
| 1337 | let spans: Vec<i64> = runs.iter().map(|run| run_span(run, now)).collect(); | 1380 | let spans: Vec<i64> = runs.iter().map(|run| run_span(run, now)).collect(); |
| 1338 | let scale = bar_scale(&spans); | 1381 | let scale = bar_scale(&spans); |
| 1339 | let row_href = |number: i64| { | 1382 | let row_href = |number: i64| { |
| @@ -1347,6 +1390,9 @@ async fn runs_split(cx: &Cx, number: Option<&str>) -> Result<SplitPage> { | |||
| 1347 | .iter() | 1390 | .iter() |
| 1348 | .zip(&timings) | 1391 | .zip(&timings) |
| 1349 | .map(|(run, jobs)| { | 1392 | .map(|(run, jobs)| { |
| 1393 | + let est = (run.state == RunState::Running) | ||
| 1394 | + .then(|| live_est(lang, run, jobs, &samples, now)) | ||
| 1395 | + .flatten(); | ||
| 1350 | let actor = if run.trigger == "schedule" { | 1396 | let actor = if run.trigger == "schedule" { |
| 1351 | String::new() | 1397 | String::new() |
| 1352 | } else { | 1398 | } else { |
| @@ -1376,14 +1422,19 @@ async fn runs_split(cx: &Cx, number: Option<&str>) -> Result<SplitPage> { | |||
| 1376 | scale: scale.to_string(), | 1422 | scale: scale.to_string(), |
| 1377 | // Only a run that has started or finished has a duration. A queued run has none yet. | 1423 | // Only a run that has started or finished has a duration. A queued run has none yet. |
| 1378 | duration: if run_finished(&run.state) || run.state == RunState::Running { | 1424 | duration: if run_finished(&run.state) || run.state == RunState::Running { |
| 1379 | - duration_text( | 1425 | + let took = duration_text( |
| 1380 | lang, | 1426 | lang, |
| 1381 | Some(run.created_at.as_str()), | 1427 | Some(run.created_at.as_str()), |
| 1382 | run.finished_at.as_deref(), | 1428 | run.finished_at.as_deref(), |
| 1383 | - ) | 1429 | + ); |
| 1430 | + match est.as_ref() { | ||
| 1431 | + Some(est) => format!("{took} \u{b7} {}", est.phrase), | ||
| 1432 | + None => took, | ||
| 1433 | + } | ||
| 1384 | } else { | 1434 | } else { |
| 1385 | String::new() | 1435 | String::new() |
| 1386 | }, | 1436 | }, |
| 1437 | + est, | ||
| 1387 | meta: row_meta(run, jobs, &actor, lang), | 1438 | meta: row_meta(run, jobs, &actor, lang), |
| 1388 | } | 1439 | } |
| 1389 | }) | 1440 | }) |
| @@ -1496,6 +1547,15 @@ async fn run_detail( | |||
| 1496 | now: i64, | 1547 | now: i64, |
| 1497 | ) -> Result<RunDetail> { | 1548 | ) -> Result<RunDetail> { |
| 1498 | let jobs = timings_of(state, &run.id, runners, lang).await?; | 1549 | let jobs = timings_of(state, &run.id, runners, lang).await?; |
| 1550 | + let est = if run.state == RunState::Running { | ||
| 1551 | + let samples = state | ||
| 1552 | + .store | ||
| 1553 | + .recent_job_samples(&run.repo_id, std::slice::from_ref(&run.git_ref)) | ||
| 1554 | + .await?; | ||
| 1555 | + live_est(lang, run, &jobs, &samples, now) | ||
| 1556 | + } else { | ||
| 1557 | + None | ||
| 1558 | + }; | ||
| 1499 | let gantt = | 1559 | let gantt = |
| 1500 | (!jobs.is_empty()).then(|| gantt(&jobs, origin_of(run, now), run_end(run, now), now, lang)); | 1560 | (!jobs.is_empty()).then(|| gantt(&jobs, origin_of(run, now), run_end(run, now), now, lang)); |
| 1501 | let writer = header.writer_csrf.is_some(); | 1561 | let writer = header.writer_csrf.is_some(); |
| @@ -1562,6 +1622,15 @@ async fn run_detail( | |||
| 1562 | let zip_href = | 1622 | let zip_href = |
| 1563 | (!artifacts.is_empty()).then(|| format!("{}/artifacts.zip", run_href(title, run.number))); | 1623 | (!artifacts.is_empty()).then(|| format!("{}/artifacts.zip", run_href(title, run.number))); |
| 1564 | let warnings = state.store.run_warnings(&run.id).await?; | 1624 | let warnings = state.store.run_warnings(&run.id).await?; |
| 1625 | + let failing = match jobs | ||
| 1626 | + .iter() | ||
| 1627 | + .find(|job| matches!(job.state, JobState::Failure | JobState::Error)) | ||
| 1628 | + { | ||
| 1629 | + Some(job) if matches!(run.state, RunState::Failure | RunState::Error) => Some( | ||
| 1630 | + ci_fail::read(state, title, &job.id, &job.name, &job.message).await?, | ||
| 1631 | + ), | ||
| 1632 | + _ => None, | ||
| 1633 | + }; | ||
| 1565 | Ok(RunDetail { | 1634 | Ok(RunDetail { |
| 1566 | number: run.number, | 1635 | number: run.number, |
| 1567 | title: header.title, | 1636 | title: header.title, |
| @@ -1574,14 +1643,21 @@ async fn run_detail( | |||
| 1574 | actor: header.actor, | 1643 | actor: header.actor, |
| 1575 | when: age_text(lang, &run.created_at), | 1644 | when: age_text(lang, &run.created_at), |
| 1576 | when_at: run.created_at.clone(), | 1645 | when_at: run.created_at.clone(), |
| 1577 | - duration: duration_text( | 1646 | + duration: { |
| 1578 | - lang, | 1647 | + let took = duration_text( |
| 1579 | - Some(run.created_at.as_str()), | 1648 | + lang, |
| 1580 | - run.finished_at.as_deref(), | 1649 | + Some(run.created_at.as_str()), |
| 1581 | - ), | 1650 | + run.finished_at.as_deref(), |
| 1651 | + ); | ||
| 1652 | + match est.as_ref() { | ||
| 1653 | + Some(est) => format!("{took} \u{b7} {}", est.phrase), | ||
| 1654 | + None => took, | ||
| 1655 | + } | ||
| 1656 | + }, | ||
| 1582 | since: (!run_finished(&run.state) && run.finished_at.is_none()) | 1657 | since: (!run_finished(&run.state) && run.finished_at.is_none()) |
| 1583 | .then(|| unix_of(&run.created_at).map(|at| at.to_string())) | 1658 | .then(|| unix_of(&run.created_at).map(|at| at.to_string())) |
| 1584 | .flatten(), | 1659 | .flatten(), |
| 1660 | + est, | ||
| 1585 | config_error: run.config_error.clone(), | 1661 | config_error: run.config_error.clone(), |
| 1586 | action_base: run_href(title, run.number), | 1662 | action_base: run_href(title, run.number), |
| 1587 | can_approve: header.writer_csrf.is_some() && run.state == RunState::WaitingApproval, | 1663 | can_approve: header.writer_csrf.is_some() && run.state == RunState::WaitingApproval, |
| @@ -1593,6 +1669,7 @@ async fn run_detail( | |||
| 1593 | zip_href, | 1669 | zip_href, |
| 1594 | writer_csrf: header.writer_csrf, | 1670 | writer_csrf: header.writer_csrf, |
| 1595 | gantt, | 1671 | gantt, |
| 1672 | + failing, | ||
| 1596 | jobs: lines, | 1673 | jobs: lines, |
| 1597 | }) | 1674 | }) |
| 1598 | } | 1675 | } |
| @@ -1683,16 +1760,21 @@ async fn runs_body( | |||
| 1683 | <p class="ci-scale">(scale.as_str())</p> | 1760 | <p class="ci-scale">(scale.as_str())</p> |
| 1684 | <ul class="ci-run-list"> | 1761 | <ul class="ci-run-list"> |
| 1685 | for row in rows.iter() { | 1762 | for row in rows.iter() { |
| 1686 | - <li> | 1763 | + <li data-kb-row=""> |
| 1687 | <a class="ci-row" href=(row.href.as_str()) aria-current=(row.current)> | 1764 | <a class="ci-row" href=(row.href.as_str()) aria-current=(row.current)> |
| 1688 | - <span class="ci-row-title">(row.title.as_str())</span> | 1765 | + <span class="ci-row-title">commit_line(subject: row.title.clone())</span> |
| 1689 | <span class="ci-row-line"> | 1766 | <span class="ci-row-line"> |
| 1690 | <svg class="ci-bar" viewBox="0 0 1000 6" preserveAspectRatio="none" aria-hidden="true" data-origin=(row.origin.as_str()) data-scale=(row.scale.as_str())> | 1767 | <svg class="ci-bar" viewBox="0 0 1000 6" preserveAspectRatio="none" aria-hidden="true" data-origin=(row.origin.as_str()) data-scale=(row.scale.as_str())> |
| 1691 | for seg in row.bar.iter() { | 1768 | for seg in row.bar.iter() { |
| 1692 | - <rect class=(seg.class.as_str()) x=(seg.x.as_str()) y=(seg.y.as_str()) width=(seg.w.as_str()) height=(seg.h.as_str()) data-tick=(seg.tick.as_deref())/> | 1769 | + <rect class=(seg.class.as_str()) x=(seg.x.as_str()) y=(seg.y.as_str()) width=(seg.w.as_str()) height=(seg.h.as_str()) data-tick=(seg.tick.as_deref()) data-key=(seg.key.as_deref())/> |
| 1693 | } | 1770 | } |
| 1694 | </svg> | 1771 | </svg> |
| 1695 | - <span class="ci-row-dur" data-since=(row.since.as_deref())>(row.duration.as_str())</span> | 1772 | + if let Some(est) = row.est.as_ref() { |
| 1773 | + <progress class="ci-est" max="100" value=(est.pct.as_str()) data-est="true" data-since=(row.since.as_deref()) data-expected=(est.expected.as_str())></progress> | ||
| 1774 | + <span class="ci-row-dur" data-since=(row.since.as_deref()) data-expected=(est.expected.as_str()) data-left=(est.left.as_str()) data-over=(est.over.as_str()) data-lm=(est.minutes.as_str())>(row.duration.as_str())</span> | ||
| 1775 | + } else { | ||
| 1776 | + <span class="ci-row-dur" data-since=(row.since.as_deref())>(row.duration.as_str())</span> | ||
| 1777 | + } | ||
| 1696 | </span> | 1778 | </span> |
| 1697 | <span class="ci-row-meta">(row.meta.head.as_str())<time datetime=(row.meta.at.as_str()) data-rel="true">(row.meta.age.as_str())</time>(row.meta.hint.as_str())</span> | 1779 | <span class="ci-row-meta">(row.meta.head.as_str())<time datetime=(row.meta.at.as_str()) data-rel="true">(row.meta.age.as_str())</time>(row.meta.hint.as_str())</span> |
| 1698 | </a> | 1780 | </a> |
| @@ -1733,7 +1815,11 @@ async fn runs_body( | |||
| 1733 | </div> | 1815 | </div> |
| 1734 | } | 1816 | } |
| 1735 | </div> | 1817 | </div> |
| 1736 | - <h3 class="ci-run-title">(run.title.as_str())</h3> | 1818 | + <h3 class="ci-run-title">(headline(run.title.as_str()))</h3> |
| 1819 | + <details class="ci-run-message"> | ||
| 1820 | + <summary class="small muted">(crate::i18n::code::t(lang, crate::i18n::code::K::ShowFullMessage))</summary> | ||
| 1821 | + <p class="small">(run.title.as_str())</p> | ||
| 1822 | + </details> | ||
| 1737 | <p class="ci-run-top"> | 1823 | <p class="ci-run-top"> |
| 1738 | <span class=(run.state_class.as_str())>(run.state.as_str())</span> | 1824 | <span class=(run.state_class.as_str())>(run.state.as_str())</span> |
| 1739 | <span class="muted small"> | 1825 | <span class="muted small"> |
| @@ -1743,10 +1829,21 @@ async fn runs_body( | |||
| 1743 | } | 1829 | } |
| 1744 | " \u{b7} " <time datetime=(run.when_at.as_str()) data-rel="true">(run.when.as_str())</time> | 1830 | " \u{b7} " <time datetime=(run.when_at.as_str()) data-rel="true">(run.when.as_str())</time> |
| 1745 | if !run.duration.is_empty() { | 1831 | if !run.duration.is_empty() { |
| 1746 | - " \u{b7} " <span data-since=(run.since.as_deref())>(run.duration.as_str())</span> | 1832 | + " \u{b7} " |
| 1833 | + if let Some(est) = run.est.as_ref() { | ||
| 1834 | + <span data-since=(run.since.as_deref()) data-expected=(est.expected.as_str()) data-left=(est.left.as_str()) data-over=(est.over.as_str()) data-lm=(est.minutes.as_str())>(run.duration.as_str())</span> | ||
| 1835 | + } else { | ||
| 1836 | + <span data-since=(run.since.as_deref())>(run.duration.as_str())</span> | ||
| 1837 | + } | ||
| 1747 | } | 1838 | } |
| 1748 | </span> | 1839 | </span> |
| 1749 | </p> | 1840 | </p> |
| 1841 | + if let Some(est) = run.est.as_ref() { | ||
| 1842 | + <progress class="ci-est ci-est-run" max="100" value=(est.pct.as_str()) data-est="true" data-since=(run.since.as_deref()) data-expected=(est.expected.as_str())></progress> | ||
| 1843 | + } | ||
| 1844 | + if let Some(fail) = run.failing.clone() { | ||
| 1845 | + fail_first_block(lang: lang, fail: fail) | ||
| 1846 | + } | ||
| 1750 | if let Some(message) = run.config_error.as_ref() { | 1847 | if let Some(message) = run.config_error.as_ref() { |
| 1751 | <pre class="ci-config-error">(message.as_str())</pre> | 1848 | <pre class="ci-config-error">(message.as_str())</pre> |
| 1752 | } | 1849 | } |
crates/forge-web/src/pages/commit.rsmodified+29 -2
| @@ -16,6 +16,7 @@ use crate::pages::commits::{SigBadgeView, blocking, iso_time, now_secs, short_oi | |||
| 16 | use crate::pages::ref_live; | 16 | use crate::pages::ref_live; |
| 17 | use crate::pages::repo::repo_head; | 17 | use crate::pages::repo::repo_head; |
| 18 | use crate::pages::repo_ctx::{RawDownload, load_repo}; | 18 | use crate::pages::repo_ctx::{RawDownload, load_repo}; |
| 19 | +use crate::render::commit_message::CommitMessage; | ||
| 19 | use crate::render::emoji::emojify; | 20 | use crate::render::emoji::emojify; |
| 20 | use crate::signatures; | 21 | use crate::signatures; |
| 21 | use crate::state::AppState; | 22 | use crate::state::AppState; |
| @@ -214,6 +215,14 @@ async fn commit_page(cx: &Cx) -> Result<impl View> { | |||
| 214 | let repo_href = format!("/{owner_name}/{repo_name}"); | 215 | let repo_href = format!("/{owner_name}/{repo_name}"); |
| 215 | let tree_href = format!("/{owner_name}/{repo_name}/tree/{}", info.oid); | 216 | let tree_href = format!("/{owner_name}/{repo_name}/tree/{}", info.oid); |
| 216 | let summary = emojify(&info.summary).into_owned(); | 217 | let summary = emojify(&info.summary).into_owned(); |
| 218 | + // A typed subject shows its first clause as the title and its groups as a list below. | ||
| 219 | + let parsed = CommitMessage::parse(&summary); | ||
| 220 | + let heading = match &parsed { | ||
| 221 | + Some(msg) => msg.title(), | ||
| 222 | + None => summary.clone(), | ||
| 223 | + }; | ||
| 224 | + let changes_label = g::t(lang, K::CommitChangesLabel); | ||
| 225 | + let show_full = g::t(lang, K::ShowFullMessage); | ||
| 217 | let full_oid = info.oid.clone(); | 226 | let full_oid = info.oid.clone(); |
| 218 | let message = emojify(&body).into_owned(); | 227 | let message = emojify(&body).into_owned(); |
| 219 | let statuses = state.store.statuses_for(&ctx.repo.id, &full_oid).await?; | 228 | let statuses = state.store.statuses_for(&ctx.repo.id, &full_oid).await?; |
| @@ -234,7 +243,7 @@ async fn commit_page(cx: &Cx) -> Result<impl View> { | |||
| 234 | Ok(view! { | 243 | Ok(view! { |
| 235 | shell(title: title.as_str(), viewer: ctx.viewer.as_ref(), | 244 | shell(title: title.as_str(), viewer: ctx.viewer.as_ref(), |
| 236 | repo_head(head: header) | 245 | repo_head(head: header) |
| 237 | - <h2 class="commit-summary-title">(summary.as_str())</h2> | 246 | + <h2 class="commit-summary-title">(heading.as_str())</h2> |
| 238 | <p class="muted small"><a href=(repo_href.as_str())>(title.as_str())</a></p> | 247 | <p class="muted small"><a href=(repo_href.as_str())>(title.as_str())</a></p> |
| 239 | <section class="card commit-info"> | 248 | <section class="card commit-info"> |
| 240 | <p class="commit-full-oid"> | 249 | <p class="commit-full-oid"> |
| @@ -311,7 +320,25 @@ async fn commit_page(cx: &Cx) -> Result<impl View> { | |||
| 311 | } | 320 | } |
| 312 | <p><a href=(tree_href.as_str())>(g::t(lang, K::BrowseFiles))</a></p> | 321 | <p><a href=(tree_href.as_str())>(g::t(lang, K::BrowseFiles))</a></p> |
| 313 | </section> | 322 | </section> |
| 314 | - if has_body { | 323 | + if let Some(msg) = parsed.as_ref() { |
| 324 | + <ul class="commit-groups" aria-label=(changes_label)> | ||
| 325 | + for group in msg.groups.iter() { | ||
| 326 | + <li class="commit-group"> | ||
| 327 | + <span class="mono commit-kind">(group.kind.as_str())</span> | ||
| 328 | + <ul class="commit-clauses"> | ||
| 329 | + for clause in group.clauses.iter() { | ||
| 330 | + <li>(clause.as_str())</li> | ||
| 331 | + } | ||
| 332 | + </ul> | ||
| 333 | + </li> | ||
| 334 | + } | ||
| 335 | + </ul> | ||
| 336 | + <details class="commit-full-message"> | ||
| 337 | + <summary>(show_full)</summary> | ||
| 338 | + <pre class="code commit-message"><code>(message.as_str())</code></pre> | ||
| 339 | + </details> | ||
| 340 | + } | ||
| 341 | + if parsed.is_none() && has_body { | ||
| 315 | <pre class="code commit-message"><code>(message.as_str())</code></pre> | 342 | <pre class="code commit-message"><code>(message.as_str())</code></pre> |
| 316 | } | 343 | } |
| 317 | <div class="commit-diff fit-pane"> | 344 | <div class="commit-diff fit-pane"> |
crates/forge-web/src/pages/commits.rsmodified+3 -2
| @@ -23,6 +23,7 @@ use crate::pages::repo_ctx::load_repo; | |||
| 23 | use crate::render::emoji::emojify; | 23 | use crate::render::emoji::emojify; |
| 24 | use crate::signatures::{self, SigBadge}; | 24 | use crate::signatures::{self, SigBadge}; |
| 25 | use crate::state::AppState; | 25 | use crate::state::AppState; |
| 26 | +use crate::views::commit_line::commit_line; | ||
| 26 | use crate::views::commit_status::{StatusLang, StatusSummary, commit_status}; | 27 | use crate::views::commit_status::{StatusLang, StatusSummary, commit_status}; |
| 27 | use crate::views::{empty_state, shell}; | 28 | use crate::views::{empty_state, shell}; |
| 28 | 29 | ||
| @@ -296,9 +297,9 @@ async fn commits_page(cx: &Cx) -> Result<impl View> { | |||
| 296 | } else { | 297 | } else { |
| 297 | <ul class="commit-list"> | 298 | <ul class="commit-list"> |
| 298 | for row in rows.iter() { | 299 | for row in rows.iter() { |
| 299 | - <li class="commit-row"> | 300 | + <li class="commit-row" data-kb-row=""> |
| 300 | <div class="commit-main"> | 301 | <div class="commit-main"> |
| 301 | - <a class="commit-summary" href=(row.commit_href.as_str())>(row.summary.as_str())</a> | 302 | + <a class="commit-summary" href=(row.commit_href.as_str())>commit_line(subject: row.summary.clone())</a> |
| 302 | <div class="commit-meta muted small"> | 303 | <div class="commit-meta muted small"> |
| 303 | <span class="commit-author">(row.author.as_str())</span> | 304 | <span class="commit-author">(row.author.as_str())</span> |
| 304 | if !row.email.is_empty() { | 305 | if !row.email.is_empty() { |
crates/forge-web/src/pages/compare.rsmodified+2 -1
| @@ -36,6 +36,7 @@ use crate::pages::repo::repo_head; | |||
| 36 | use crate::pages::repo_ctx::{RepoCtx, load_repo}; | 36 | use crate::pages::repo_ctx::{RepoCtx, load_repo}; |
| 37 | use crate::state::AppState; | 37 | use crate::state::AppState; |
| 38 | use crate::templates; | 38 | use crate::templates; |
| 39 | +use crate::views::commit_line::commit_line; | ||
| 39 | use crate::views::diff::{DiffLang, DiffOpts, LIMITS, diff_section}; | 40 | use crate::views::diff::{DiffLang, DiffOpts, LIMITS, diff_section}; |
| 40 | use crate::views::{alert, empty_state, repo_href, shell, user_facing_message}; | 41 | use crate::views::{alert, empty_state, repo_href, shell, user_facing_message}; |
| 41 | use crate::webhooks::emit::{Sender, emit_pull}; | 42 | use crate::webhooks::emit::{Sender, emit_pull}; |
| @@ -346,7 +347,7 @@ async fn compare_view( | |||
| 346 | for row in rows.iter() { | 347 | for row in rows.iter() { |
| 347 | <li class="commit-row"> | 348 | <li class="commit-row"> |
| 348 | <div class="commit-main"> | 349 | <div class="commit-main"> |
| 349 | - <a class="commit-summary" href=(row.commit_href.as_str())>(row.summary.as_str())</a> | 350 | + <a class="commit-summary" href=(row.commit_href.as_str())>commit_line(subject: row.summary.clone())</a> |
| 350 | <div class="commit-meta muted small"> | 351 | <div class="commit-meta muted small"> |
| 351 | <span class="commit-author">(row.author.as_str())</span> | 352 | <span class="commit-author">(row.author.as_str())</span> |
| 352 | if !row.email.is_empty() { | 353 | if !row.email.is_empty() { |
crates/forge-web/src/pages/finder.rsmodified+1 -1
| @@ -36,7 +36,7 @@ pub async fn file_finder( | |||
| 36 | let src = repo_href(&owner, &repo, "paths", &ref_name); | 36 | let src = repo_href(&owner, &repo, "paths", &ref_name); |
| 37 | let base = format!("{}/", repo_href(&owner, &repo, "blob", &ref_name)); | 37 | let base = format!("{}/", repo_href(&owner, &repo, "blob", &ref_name)); |
| 38 | Ok(view! { | 38 | Ok(view! { |
| 39 | - <button type="button" class="button finder-open" data-finder-open="" title=(b::t(lang, b::K::FinderHint))> | 39 | + <button type="button" class="button finder-open" data-finder-open="" data-palette-action="click" title=(b::t(lang, b::K::FinderHint))> |
| 40 | (b::t(lang, b::K::GoToFile)) | 40 | (b::t(lang, b::K::GoToFile)) |
| 41 | <kbd>"t"</kbd> | 41 | <kbd>"t"</kbd> |
| 42 | </button> | 42 | </button> |
crates/forge-web/src/pages/issue_parts.rsmodified+3 -3
| @@ -1271,10 +1271,10 @@ pub(crate) async fn comment_form( | |||
| 1271 | <button type="submit" class="primary" name="action" value="comment">(g::t(lang, K::Comment))</button> | 1271 | <button type="submit" class="primary" name="action" value="comment">(g::t(lang, K::Comment))</button> |
| 1272 | if can_close { | 1272 | if can_close { |
| 1273 | if open { | 1273 | if open { |
| 1274 | - <button type="submit" name="action" value="close_completed" formaction=(state_action.as_str())>(g::t(lang, K::CloseCompleted))</button> | 1274 | + <button type="submit" name="action" value="close_completed" formaction=(state_action.as_str()) data-palette-action="post">(g::t(lang, K::CloseCompleted))</button> |
| 1275 | - <button type="submit" name="action" value="close_not_planned" formaction=(state_action.as_str())>(g::t(lang, K::CloseNotPlanned))</button> | 1275 | + <button type="submit" name="action" value="close_not_planned" formaction=(state_action.as_str()) data-palette-action="post">(g::t(lang, K::CloseNotPlanned))</button> |
| 1276 | } else { | 1276 | } else { |
| 1277 | - <button type="submit" name="action" value="reopen" formaction=(state_action.as_str())>(g::t(lang, K::ReopenWithComment))</button> | 1277 | + <button type="submit" name="action" value="reopen" formaction=(state_action.as_str()) data-palette-action="post">(g::t(lang, K::ReopenWithComment))</button> |
| 1278 | } | 1278 | } |
| 1279 | } | 1279 | } |
| 1280 | </div> | 1280 | </div> |
crates/forge-web/src/pages/issues_list.rsmodified+3 -3
| @@ -508,7 +508,7 @@ async fn issues_list_page(cx: &Cx) -> Result<impl View> { | |||
| 508 | <a class="button" href=(milestones_href.as_str())>(g::t(lang, K::Milestones))</a> | 508 | <a class="button" href=(milestones_href.as_str())>(g::t(lang, K::Milestones))</a> |
| 509 | </nav> | 509 | </nav> |
| 510 | if can_create { | 510 | if can_create { |
| 511 | - <a class="button" href=(new_href.as_str())>(g::t(lang, K::NewIssue))</a> | 511 | + <a class="button" href=(new_href.as_str()) data-palette-action="go">(g::t(lang, K::NewIssue))</a> |
| 512 | } | 512 | } |
| 513 | </div> | 513 | </div> |
| 514 | </div> | 514 | </div> |
| @@ -554,14 +554,14 @@ async fn issues_list_page(cx: &Cx) -> Result<impl View> { | |||
| 554 | } else { | 554 | } else { |
| 555 | empty_state(title: empty_text, | 555 | empty_state(title: empty_text, |
| 556 | if can_create { | 556 | if can_create { |
| 557 | - <a class="button primary" href=(new_href.as_str())>(g::t(lang, K::NewIssue))</a> | 557 | + <a class="button primary" href=(new_href.as_str()) data-palette-action="go">(g::t(lang, K::NewIssue))</a> |
| 558 | } | 558 | } |
| 559 | ) | 559 | ) |
| 560 | } | 560 | } |
| 561 | } else { | 561 | } else { |
| 562 | <ul class="issue-list"> | 562 | <ul class="issue-list"> |
| 563 | for row in rows.iter() { | 563 | for row in rows.iter() { |
| 564 | - <li class="issue-row"> | 564 | + <li class="issue-row" data-kb-row=""> |
| 565 | <span class=(row.state_class) role="img" aria-label=(row.state_label)></span> | 565 | <span class=(row.state_class) role="img" aria-label=(row.state_label)></span> |
| 566 | <div class="issue-main"> | 566 | <div class="issue-main"> |
| 567 | <div class="issue-title-line"> | 567 | <div class="issue-title-line"> |
crates/forge-web/src/pages/mod.rsmodified+3 -0
| @@ -27,6 +27,8 @@ pub mod branches; | |||
| 27 | #[cfg(test)] | 27 | #[cfg(test)] |
| 28 | mod browse_tests; | 28 | mod browse_tests; |
| 29 | pub mod ci_badge; | 29 | pub mod ci_badge; |
| 30 | +pub mod ci_estimate; | ||
| 31 | +pub mod ci_fail; | ||
| 30 | pub mod ci_job; | 32 | pub mod ci_job; |
| 31 | pub mod ci_runs; | 33 | pub mod ci_runs; |
| 32 | #[cfg(test)] | 34 | #[cfg(test)] |
| @@ -69,6 +71,7 @@ pub mod login; | |||
| 69 | pub mod media; | 71 | pub mod media; |
| 70 | pub mod merge_queue; | 72 | pub mod merge_queue; |
| 71 | pub mod milestones_page; | 73 | pub mod milestones_page; |
| 74 | +pub mod needs_you; | ||
| 72 | pub mod new_repo; | 75 | pub mod new_repo; |
| 73 | pub mod not_found_page; | 76 | pub mod not_found_page; |
| 74 | pub mod notifications; | 77 | pub mod notifications; |
crates/forge-web/src/pages/needs_you.rsadded+276 -0
| @@ -0,0 +1,276 @@ | |||
| 1 | +//! `/needs-you`: one signed-in page listing what is waiting on the viewer. Five sections, each hidden | ||
| 2 | +//! when empty: their failed CI runs, review requests, their own pull requests with a review verdict, | ||
| 3 | +//! assigned issues and unread mentions. Every row comes from a store query that applies the viewer's | ||
| 4 | +//! repo access, except review requests, which are checked per repo here as `/review-requests` does. | ||
| 5 | +//! `/needs-you/events` wakes the page on the viewer's review-request and inbox topics. | ||
| 6 | + | ||
| 7 | +use forge_core::authz::{Action, authorize}; | ||
| 8 | +use forge_core::store::needs::Verdict; | ||
| 9 | +use forge_core::{Reason, User}; | ||
| 10 | +use topcoat::Result; | ||
| 11 | +use topcoat::context::{Cx, app_context}; | ||
| 12 | +use topcoat::router::response::Response; | ||
| 13 | +use topcoat::router::{Body, StatusCode, page, route}; | ||
| 14 | +use topcoat::view::{View, component, view}; | ||
| 15 | + | ||
| 16 | +use crate::auth::{current_user, require_user}; | ||
| 17 | +use crate::i18n::authoring::{self as ga}; | ||
| 18 | +use crate::i18n::needs::{self as ni, K}; | ||
| 19 | +use crate::i18n::{self, Lang}; | ||
| 20 | +use crate::live::{Topic, stream_wakes}; | ||
| 21 | +use crate::pages::ci_runs::run_href; | ||
| 22 | +use crate::state::AppState; | ||
| 23 | +use crate::views::{empty_state, rel_time, repo_href, shell}; | ||
| 24 | + | ||
| 25 | +/// Most rows one section lists. | ||
| 26 | +const SECTION_ROWS: usize = 8; | ||
| 27 | + | ||
| 28 | +/// How many waiting inbox rows are read before the mentions are picked out of them. | ||
| 29 | +const WAITING_READ: u64 = 200; | ||
| 30 | + | ||
| 31 | +/// One row of a section. | ||
| 32 | +pub(crate) struct NeedRow { | ||
| 33 | + href: String, | ||
| 34 | + title: String, | ||
| 35 | + detail: String, | ||
| 36 | + badge: Option<&'static str>, | ||
| 37 | + stamp: String, | ||
| 38 | +} | ||
| 39 | + | ||
| 40 | +/// One section: its heading, at most `SECTION_ROWS` rows, and the link to its full list if it has one. | ||
| 41 | +pub(crate) struct NeedSection { | ||
| 42 | + heading: &'static str, | ||
| 43 | + more: Option<(&'static str, &'static str)>, | ||
| 44 | + rows: Vec<NeedRow>, | ||
| 45 | +} | ||
| 46 | + | ||
| 47 | +/// The sections that have rows, in page order. | ||
| 48 | +async fn load_sections(state: &AppState, user: &User, lang: Lang) -> Result<Vec<NeedSection>> { | ||
| 49 | + let mut sections = Vec::new(); | ||
| 50 | + let limit = SECTION_ROWS as i64; | ||
| 51 | + | ||
| 52 | + let runs = state.store.failing_runs(&user.id, limit).await?; | ||
| 53 | + if !runs.is_empty() { | ||
| 54 | + sections.push(NeedSection { | ||
| 55 | + heading: ni::t(lang, K::FailedRuns), | ||
| 56 | + more: None, | ||
| 57 | + rows: runs | ||
| 58 | + .iter() | ||
| 59 | + .map(|run| { | ||
| 60 | + let title = format!("{}/{}", run.owner, run.repo); | ||
| 61 | + NeedRow { | ||
| 62 | + href: run_href(&title, run.number), | ||
| 63 | + title: format!("{title} #{}", run.number), | ||
| 64 | + detail: run.git_ref.clone(), | ||
| 65 | + badge: None, | ||
| 66 | + stamp: run.created_at.clone(), | ||
| 67 | + } | ||
| 68 | + }) | ||
| 69 | + .collect(), | ||
| 70 | + }); | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + let mut reviews = Vec::new(); | ||
| 74 | + for item in state.store.review_requests_for_user(&user.id).await? { | ||
| 75 | + if reviews.len() >= SECTION_ROWS { | ||
| 76 | + break; | ||
| 77 | + } | ||
| 78 | + // A repo the viewer can no longer read is not listed. | ||
| 79 | + let Some(repo) = state | ||
| 80 | + .store | ||
| 81 | + .repo_by_owner_and_name(&item.repo_owner, &item.repo_name) | ||
| 82 | + .await? | ||
| 83 | + else { | ||
| 84 | + continue; | ||
| 85 | + }; | ||
| 86 | + let role = state.store.collaborator_role(&repo.id, &user.id).await?; | ||
| 87 | + let org_role = state | ||
| 88 | + .store | ||
| 89 | + .org_repo_role(&repo.owner_id, &user.id, &repo.id) | ||
| 90 | + .await?; | ||
| 91 | + if authorize(Some(user), &repo, role, org_role, Action::Read).is_err() { | ||
| 92 | + continue; | ||
| 93 | + } | ||
| 94 | + reviews.push(NeedRow { | ||
| 95 | + href: repo_href( | ||
| 96 | + &item.repo_owner, | ||
| 97 | + &item.repo_name, | ||
| 98 | + "pulls", | ||
| 99 | + &item.number.to_string(), | ||
| 100 | + ), | ||
| 101 | + title: item.title.clone(), | ||
| 102 | + detail: format!( | ||
| 103 | + "{}/{} #{} · {}", | ||
| 104 | + item.repo_owner, | ||
| 105 | + item.repo_name, | ||
| 106 | + item.number, | ||
| 107 | + ga::requested_by(lang, &item.requested_by) | ||
| 108 | + ), | ||
| 109 | + badge: None, | ||
| 110 | + stamp: item.created_at.clone(), | ||
| 111 | + }); | ||
| 112 | + } | ||
| 113 | + if !reviews.is_empty() { | ||
| 114 | + sections.push(NeedSection { | ||
| 115 | + heading: ni::t(lang, K::ReviewsRequested), | ||
| 116 | + more: Some(("/review-requests", ni::t(lang, K::AllReviewRequests))), | ||
| 117 | + rows: reviews, | ||
| 118 | + }); | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + let pulls = state | ||
| 122 | + .store | ||
| 123 | + .own_pulls_with_verdict(&user.id, SECTION_ROWS) | ||
| 124 | + .await?; | ||
| 125 | + if !pulls.is_empty() { | ||
| 126 | + sections.push(NeedSection { | ||
| 127 | + heading: ni::t(lang, K::YourPulls), | ||
| 128 | + more: None, | ||
| 129 | + rows: pulls | ||
| 130 | + .iter() | ||
| 131 | + .map(|pull| NeedRow { | ||
| 132 | + href: repo_href(&pull.owner, &pull.repo, "pulls", &pull.number.to_string()), | ||
| 133 | + title: pull.title.clone(), | ||
| 134 | + detail: format!("{}/{} #{}", pull.owner, pull.repo, pull.number), | ||
| 135 | + badge: Some(match pull.verdict { | ||
| 136 | + Verdict::ChangesRequested => ni::t(lang, K::ChangesRequested), | ||
| 137 | + Verdict::Approved => ni::t(lang, K::Approved), | ||
| 138 | + }), | ||
| 139 | + stamp: pull.updated_at.clone(), | ||
| 140 | + }) | ||
| 141 | + .collect(), | ||
| 142 | + }); | ||
| 143 | + } | ||
| 144 | + | ||
| 145 | + let issues = state.store.assigned_issues(&user.id, limit).await?; | ||
| 146 | + if !issues.is_empty() { | ||
| 147 | + sections.push(NeedSection { | ||
| 148 | + heading: ni::t(lang, K::AssignedIssues), | ||
| 149 | + more: None, | ||
| 150 | + rows: issues | ||
| 151 | + .iter() | ||
| 152 | + .map(|issue| NeedRow { | ||
| 153 | + href: repo_href( | ||
| 154 | + &issue.owner, | ||
| 155 | + &issue.repo, | ||
| 156 | + "issues", | ||
| 157 | + &issue.number.to_string(), | ||
| 158 | + ), | ||
| 159 | + title: issue.title.clone(), | ||
| 160 | + detail: format!("{}/{} #{}", issue.owner, issue.repo, issue.number), | ||
| 161 | + badge: None, | ||
| 162 | + stamp: issue.updated_at.clone(), | ||
| 163 | + }) | ||
| 164 | + .collect(), | ||
| 165 | + }); | ||
| 166 | + } | ||
| 167 | + | ||
| 168 | + let mentions: Vec<_> = state | ||
| 169 | + .store | ||
| 170 | + .waiting_on(&user.id, WAITING_READ) | ||
| 171 | + .await? | ||
| 172 | + .into_iter() | ||
| 173 | + .filter(|item| matches!(item.reason, Reason::Mention)) | ||
| 174 | + .take(SECTION_ROWS) | ||
| 175 | + .collect(); | ||
| 176 | + if !mentions.is_empty() { | ||
| 177 | + sections.push(NeedSection { | ||
| 178 | + heading: ni::t(lang, K::Mentions), | ||
| 179 | + more: None, | ||
| 180 | + rows: mentions | ||
| 181 | + .iter() | ||
| 182 | + .map(|item| { | ||
| 183 | + let section = if item.is_pull { "pulls" } else { "issues" }; | ||
| 184 | + NeedRow { | ||
| 185 | + href: repo_href(&item.owner, &item.repo, section, &item.number.to_string()), | ||
| 186 | + title: item.title.clone(), | ||
| 187 | + detail: format!("{}/{} #{}", item.owner, item.repo, item.number), | ||
| 188 | + badge: None, | ||
| 189 | + stamp: item.updated_at.clone(), | ||
| 190 | + } | ||
| 191 | + }) | ||
| 192 | + .collect(), | ||
| 193 | + }); | ||
| 194 | + } | ||
| 195 | + | ||
| 196 | + Ok(sections) | ||
| 197 | +} | ||
| 198 | + | ||
| 199 | +/// One section of the page: its head, its rows as a compact list, and its full-list link. | ||
| 200 | +#[component] | ||
| 201 | +pub(crate) async fn need_section(lang: Lang, section: NeedSection) -> Result<impl View> { | ||
| 202 | + let NeedSection { | ||
| 203 | + heading, | ||
| 204 | + more, | ||
| 205 | + rows, | ||
| 206 | + } = section; | ||
| 207 | + Ok(view! { | ||
| 208 | + <section class="card needs-section"> | ||
| 209 | + <h2 class="needs-head">(heading)</h2> | ||
| 210 | + <ul class="notif-list"> | ||
| 211 | + for row in rows.iter() { | ||
| 212 | + <li class="notif-row"> | ||
| 213 | + if let Some(badge) = row.badge { | ||
| 214 | + <span class="badge">(badge)</span> | ||
| 215 | + } | ||
| 216 | + <a class="notif-title" href=(row.href.as_str())>(row.title.as_str())</a> | ||
| 217 | + <span class="muted small">(row.detail.as_str())</span> | ||
| 218 | + <span class="muted small">rel_time(lang: lang, stamp: row.stamp.as_str())</span> | ||
| 219 | + </li> | ||
| 220 | + } | ||
| 221 | + </ul> | ||
| 222 | + if let Some((href, text)) = more { | ||
| 223 | + <a class="needs-more small" href=(href)>(text)</a> | ||
| 224 | + } | ||
| 225 | + </section> | ||
| 226 | + }) | ||
| 227 | +} | ||
| 228 | + | ||
| 229 | +/// The page's sections, the only ones with rows, or the one-line empty state. | ||
| 230 | +#[page("/needs-you")] | ||
| 231 | +async fn needs_you(cx: &Cx) -> Result<impl View> { | ||
| 232 | + let viewer = require_user(cx).await?; | ||
| 233 | + let state = app_context::<AppState>(cx); | ||
| 234 | + let user = &viewer.0; | ||
| 235 | + let lang = i18n::lang(cx, Some(user)); | ||
| 236 | + let sections = load_sections(state, user, lang).await?; | ||
| 237 | + let empty = sections.is_empty(); | ||
| 238 | + let heading = ni::t(lang, K::NeedsYou); | ||
| 239 | + Ok(view! { | ||
| 240 | + shell(title: heading, viewer: Some(&viewer), | ||
| 241 | + <section class="page-head" data-live="/needs-you/events"> | ||
| 242 | + <h1>(heading)</h1> | ||
| 243 | + </section> | ||
| 244 | + if empty { | ||
| 245 | + empty_state(title: ni::t(lang, K::AllClear)) | ||
| 246 | + } | ||
| 247 | + if !empty { | ||
| 248 | + <div class="needs-grid"> | ||
| 249 | + for section in sections.into_iter() { | ||
| 250 | + need_section(lang: lang, section: section) | ||
| 251 | + } | ||
| 252 | + </div> | ||
| 253 | + } | ||
| 254 | + ) | ||
| 255 | + }) | ||
| 256 | +} | ||
| 257 | + | ||
| 258 | +/// The page's stream: a wake on the viewer's review-request or inbox topic. Anonymous visitors get | ||
| 259 | +/// a bare 401. | ||
| 260 | +#[route(GET "/needs-you/events")] | ||
| 261 | +async fn needs_you_events(cx: &Cx) -> Result<Response> { | ||
| 262 | + let Some((user, _)) = current_user(cx).await? else { | ||
| 263 | + let mut res = Response::new(Body::empty()); | ||
| 264 | + *res.status_mut() = StatusCode::UNAUTHORIZED; | ||
| 265 | + return Ok(res); | ||
| 266 | + }; | ||
| 267 | + let state = app_context::<AppState>(cx); | ||
| 268 | + stream_wakes( | ||
| 269 | + cx, | ||
| 270 | + &state.live, | ||
| 271 | + &[ | ||
| 272 | + Topic::ReviewRequests(user.id.clone()), | ||
| 273 | + Topic::Inbox(user.id), | ||
| 274 | + ], | ||
| 275 | + ) | ||
| 276 | +} | ||
crates/forge-web/src/pages/notifications.rsmodified+2 -2
| @@ -1157,7 +1157,7 @@ async fn inbox_list( | |||
| 1157 | </header> | 1157 | </header> |
| 1158 | <ul class="notif-list"> | 1158 | <ul class="notif-list"> |
| 1159 | for row in group.rows.into_iter() { | 1159 | for row in group.rows.into_iter() { |
| 1160 | - <li class=(row.item_class)> | 1160 | + <li class=(row.item_class) data-kb-row=""> |
| 1161 | <span class=(row.icon_class) aria-hidden="true"></span> | 1161 | <span class=(row.icon_class) aria-hidden="true"></span> |
| 1162 | <span class="notif-sr">(row.kind_label)</span> | 1162 | <span class="notif-sr">(row.kind_label)</span> |
| 1163 | <a class="notif-title" href=(row.open_href.as_str())>(row.title_line.as_str())</a> | 1163 | <a class="notif-title" href=(row.open_href.as_str())>(row.title_line.as_str())</a> |
| @@ -1257,7 +1257,7 @@ pub(crate) async fn watch_form( | |||
| 1257 | <form method="post" action=(action.as_str()) class="watch-option-form"> | 1257 | <form method="post" action=(action.as_str()) class="watch-option-form"> |
| 1258 | csrf_field(token: csrf.as_str()) | 1258 | csrf_field(token: csrf.as_str()) |
| 1259 | <input type="hidden" name="level" value="watching"> | 1259 | <input type="hidden" name="level" value="watching"> |
| 1260 | - <button type="submit" class=(cls_watching)> | 1260 | + <button type="submit" class=(cls_watching) data-palette-action="post" data-palette-label=(g::t(lang, K::OptWatching))> |
| 1261 | <span class="watch-option-title">(g::t(lang, K::OptWatching))</span> | 1261 | <span class="watch-option-title">(g::t(lang, K::OptWatching))</span> |
| 1262 | <span class="watch-option-desc">(g::t(lang, K::WatchDescWatching))</span> | 1262 | <span class="watch-option-desc">(g::t(lang, K::WatchDescWatching))</span> |
| 1263 | </button> | 1263 | </button> |
crates/forge-web/src/pages/palette.rsmodified+3 -1
| @@ -4,7 +4,9 @@ | |||
| 4 | //! settings and admin pages. Those pages come from the same lists the navigation is built from | 4 | //! settings and admin pages. Those pages come from the same lists the navigation is built from |
| 5 | //! (`views::profile_items`, `views::global_items`, `views::settings_items`, `views::admin_items`), | 5 | //! (`views::profile_items`, `views::global_items`, `views::settings_items`, `views::admin_items`), |
| 6 | //! so a page the sidebar or a tab bar links to is found here too. Each href is listed once, the | 6 | //! so a page the sidebar or a tab bar links to is found here too. Each href is listed once, the |
| 7 | -//! first time it appears. The palette itself, its filtering and keys live in `assets/nav.js`. | 7 | +//! first time it appears. The palette itself, its filtering and keys live in `assets/nav.js`. The |
| 8 | +//! actions of the page it is opened on are not listed here: a control marked `data-palette-action` | ||
| 9 | +//! is rendered only for a viewer who may use it, and the palette reads those controls from the page. | ||
| 8 | 10 | ||
| 9 | use std::collections::HashSet; | 11 | use std::collections::HashSet; |
| 10 | 12 | ||
crates/forge-web/src/pages/pull_files.rsmodified+230 -8
| @@ -7,30 +7,35 @@ | |||
| 7 | use std::collections::HashMap; | 7 | use std::collections::HashMap; |
| 8 | use std::sync::Arc; | 8 | use std::sync::Arc; |
| 9 | 9 | ||
| 10 | -use forge_core::{Action, IssueState, Side, Thread, authorize}; | 10 | +use forge_core::{Action, IssueState, PullRequest, Side, Thread, authorize}; |
| 11 | use forge_git::command::ObjectSource; | 11 | use forge_git::command::ObjectSource; |
| 12 | -use forge_git::history::CommitDiff; | 12 | +use forge_git::history::{CommitDiff, DiffStatus, FileDiff}; |
| 13 | -use forge_git::pulls::range_diff_files_ws; | 13 | +use forge_git::pulls::{blob_at, range_diff_files_ws}; |
| 14 | +use serde::Deserialize; | ||
| 14 | use topcoat::Result; | 15 | use topcoat::Result; |
| 15 | use topcoat::context::{Cx, app_context}; | 16 | use topcoat::context::{Cx, app_context}; |
| 16 | -use topcoat::router::error::not_found; | 17 | +use topcoat::router::content::Form; |
| 18 | +use topcoat::router::error::{SeeOther, not_found, see_other}; | ||
| 17 | use topcoat::router::request::uri; | 19 | use topcoat::router::request::uri; |
| 18 | -use topcoat::router::{page, path_param}; | 20 | +use topcoat::router::{page, path_param, route}; |
| 19 | use topcoat::view::{View, component, view}; | 21 | use topcoat::view::{View, component, view}; |
| 20 | 22 | ||
| 23 | +use crate::auth::require_user; | ||
| 21 | use crate::i18n::pulls::{self as g, K}; | 24 | use crate::i18n::pulls::{self as g, K}; |
| 22 | use crate::i18n::{self, Lang}; | 25 | use crate::i18n::{self, Lang}; |
| 23 | use crate::pages::edit_history::thread_edit_counts; | 26 | use crate::pages::edit_history::thread_edit_counts; |
| 24 | -use crate::pages::issue_parts::{csrf_of, may_converse, parse_number, triage, viewer}; | 27 | +use crate::pages::issue_parts::{ |
| 28 | + check_write, csrf_of, may_converse, parse_number, triage, viewer, | ||
| 29 | +}; | ||
| 25 | use crate::pages::pull_reviews::{error_text_in, pull_diff, suggest_states}; | 30 | use crate::pages::pull_reviews::{error_text_in, pull_diff, suggest_states}; |
| 26 | use crate::pages::pull_view::{commits_of, frame_in, is_merged, pull_header, pull_subnav_in}; | 31 | use crate::pages::pull_view::{commits_of, frame_in, is_merged, pull_header, pull_subnav_in}; |
| 27 | use crate::pages::repo::repo_head; | 32 | use crate::pages::repo::repo_head; |
| 28 | -use crate::pages::repo_ctx::load_repo; | 33 | +use crate::pages::repo_ctx::{RepoCtx, load_repo}; |
| 29 | use crate::pages::tree::link_context; | 34 | use crate::pages::tree::link_context; |
| 30 | use crate::state::AppState; | 35 | use crate::state::AppState; |
| 31 | use crate::views::diff::{DiffLang, DiffOpts, LIMITS, LineComments, diff_section}; | 36 | use crate::views::diff::{DiffLang, DiffOpts, LIMITS, LineComments, diff_section}; |
| 32 | use crate::views::review_thread::ThreadCtx; | 37 | use crate::views::review_thread::ThreadCtx; |
| 33 | -use crate::views::{alert, shell}; | 38 | +use crate::views::{alert, repo_href, shell}; |
| 34 | 39 | ||
| 35 | path_param!(owner); | 40 | path_param!(owner); |
| 36 | path_param!(repo); | 41 | path_param!(repo); |
| @@ -73,6 +78,204 @@ fn file_index(diff: &CommitDiff, path: &str) -> Option<usize> { | |||
| 73 | .position(|f| f.new_path.as_deref() == Some(path) || f.old_path.as_deref() == Some(path)) | 78 | .position(|f| f.new_path.as_deref() == Some(path) || f.old_path.as_deref() == Some(path)) |
| 74 | } | 79 | } |
| 75 | 80 | ||
| 81 | +/// The path a file's Viewed mark is kept under: its new path, or the old one when it was deleted. | ||
| 82 | +fn mark_path(file: &FileDiff) -> Option<&str> { | ||
| 83 | + if file.status == DiffStatus::Deleted { | ||
| 84 | + file.old_path.as_deref() | ||
| 85 | + } else { | ||
| 86 | + file.new_path.as_deref().or(file.old_path.as_deref()) | ||
| 87 | + } | ||
| 88 | +} | ||
| 89 | + | ||
| 90 | +/// The file's heading in the diff, as `diff_section` writes it: `old → new` for a rename. | ||
| 91 | +fn file_label(file: &FileDiff) -> String { | ||
| 92 | + match (&file.old_path, &file.new_path) { | ||
| 93 | + (Some(old), Some(new)) if old != new => format!("{old} → {new}"), | ||
| 94 | + (_, Some(new)) => new.clone(), | ||
| 95 | + (Some(old), None) => old.clone(), | ||
| 96 | + (None, None) => String::new(), | ||
| 97 | + } | ||
| 98 | +} | ||
| 99 | + | ||
| 100 | +/// Where a file's mark stands for the viewer. | ||
| 101 | +#[derive(Clone, Copy, PartialEq, Eq)] | ||
| 102 | +enum MarkState { | ||
| 103 | + /// Marked at the file's current blob. | ||
| 104 | + Viewed, | ||
| 105 | + /// Marked at an older blob: the file changed since. | ||
| 106 | + Changed, | ||
| 107 | + Unviewed, | ||
| 108 | +} | ||
| 109 | + | ||
| 110 | +impl MarkState { | ||
| 111 | + fn name(self) -> &'static str { | ||
| 112 | + match self { | ||
| 113 | + MarkState::Viewed => "viewed", | ||
| 114 | + MarkState::Changed => "changed", | ||
| 115 | + MarkState::Unviewed => "unviewed", | ||
| 116 | + } | ||
| 117 | + } | ||
| 118 | +} | ||
| 119 | + | ||
| 120 | +/// One file of the Viewed panel. | ||
| 121 | +struct ViewedRow { | ||
| 122 | + path: String, | ||
| 123 | + /// The heading `diff_section` gives the file, to find its section on the page. | ||
| 124 | + label: String, | ||
| 125 | + state: MarkState, | ||
| 126 | +} | ||
| 127 | + | ||
| 128 | +/// Everything the Viewed panel needs. `None` on the page for a signed-out viewer. | ||
| 129 | +struct ViewedPanel { | ||
| 130 | + rows: Vec<ViewedRow>, | ||
| 131 | + pr_href: String, | ||
| 132 | + csrf: String, | ||
| 133 | + archived: bool, | ||
| 134 | +} | ||
| 135 | + | ||
| 136 | +/// One row per file of the full diff. A mark counts only while its blob is the file's blob at the | ||
| 137 | +/// head, so a file a later push changed shows as changed. | ||
| 138 | +async fn viewed_rows( | ||
| 139 | + state: &AppState, | ||
| 140 | + ctx: &RepoCtx, | ||
| 141 | + pr: &PullRequest, | ||
| 142 | + diff: &CommitDiff, | ||
| 143 | + marks: &HashMap<String, String>, | ||
| 144 | +) -> Result<Vec<ViewedRow>> { | ||
| 145 | + let mut rows = Vec::new(); | ||
| 146 | + for file in &diff.files { | ||
| 147 | + let Some(path) = mark_path(file) else { | ||
| 148 | + continue; | ||
| 149 | + }; | ||
| 150 | + let blob = blob_at(&state.git, &ctx.path, &pr.head_oid, path) | ||
| 151 | + .await? | ||
| 152 | + .unwrap_or_default(); | ||
| 153 | + let mark = match marks.get(path) { | ||
| 154 | + Some(marked) if *marked == blob => MarkState::Viewed, | ||
| 155 | + Some(_) => MarkState::Changed, | ||
| 156 | + None => MarkState::Unviewed, | ||
| 157 | + }; | ||
| 158 | + rows.push(ViewedRow { | ||
| 159 | + path: path.to_owned(), | ||
| 160 | + label: file_label(file), | ||
| 161 | + state: mark, | ||
| 162 | + }); | ||
| 163 | + } | ||
| 164 | + Ok(rows) | ||
| 165 | +} | ||
| 166 | + | ||
| 167 | +/// The Viewed panel: `N of M viewed` with a thin bar, then one row per file with its checkbox. | ||
| 168 | +/// The checkbox posts to the pull's `viewed` route from nav.js and shows the new state only after | ||
| 169 | +/// the server answered; a changed file says so. Collapsing viewed files is done by nav.js too. | ||
| 170 | +#[component] | ||
| 171 | +async fn viewed_panel(lang: Lang, panel: ViewedPanel) -> Result<impl View> { | ||
| 172 | + let total = panel.rows.len(); | ||
| 173 | + let done = panel | ||
| 174 | + .rows | ||
| 175 | + .iter() | ||
| 176 | + .filter(|row| row.state == MarkState::Viewed) | ||
| 177 | + .count(); | ||
| 178 | + let count = g::viewed_count(lang, done, total); | ||
| 179 | + let width = if total == 0 { | ||
| 180 | + "width:0%".to_owned() | ||
| 181 | + } else { | ||
| 182 | + format!("width:{:.1}%", done as f64 * 100.0 / total as f64) | ||
| 183 | + }; | ||
| 184 | + let action = format!("{}/viewed", panel.pr_href); | ||
| 185 | + let csrf = panel.csrf; | ||
| 186 | + let archived = panel.archived; | ||
| 187 | + let mark = g::t(lang, K::ViewedMark); | ||
| 188 | + let changed = g::t(lang, K::ChangedSinceViewed); | ||
| 189 | + Ok(view! { | ||
| 190 | + <section class="card viewed-panel" data-viewed-panel="" data-action=(action.as_str()) data-csrf=(csrf.as_str())> | ||
| 191 | + <div class="viewed-head"> | ||
| 192 | + <h2>(g::t(lang, K::ViewedFiles))</h2> | ||
| 193 | + <span class="viewed-count">(count.as_str())</span> | ||
| 194 | + </div> | ||
| 195 | + <div class="viewed-bar"><b style=(width.as_str())></b></div> | ||
| 196 | + <p class="muted viewed-hint">(g::t(lang, K::ViewedHint))</p> | ||
| 197 | + <ul class="viewed-list"> | ||
| 198 | + for row in panel.rows.into_iter() { | ||
| 199 | + <li data-viewed-row="" data-state=(row.state.name()) data-label=(row.label.as_str())> | ||
| 200 | + if archived { | ||
| 201 | + <span class="viewed-path">(row.path.as_str())</span> | ||
| 202 | + } else { | ||
| 203 | + <label class="viewed-item"> | ||
| 204 | + if row.state == MarkState::Viewed { | ||
| 205 | + <input type="checkbox" checked="" data-viewed-toggle="" data-path=(row.path.as_str()) title=(mark)> | ||
| 206 | + } else { | ||
| 207 | + <input type="checkbox" data-viewed-toggle="" data-path=(row.path.as_str()) title=(mark)> | ||
| 208 | + } | ||
| 209 | + <span class="viewed-path">(row.path.as_str())</span> | ||
| 210 | + </label> | ||
| 211 | + } | ||
| 212 | + if row.state == MarkState::Changed { | ||
| 213 | + <span class="viewed-note">(changed)</span> | ||
| 214 | + } | ||
| 215 | + </li> | ||
| 216 | + } | ||
| 217 | + </ul> | ||
| 218 | + </section> | ||
| 219 | + }) | ||
| 220 | +} | ||
| 221 | + | ||
| 222 | +/// The Viewed form body: `viewed` is `1` to mark the file, anything else clears the mark. | ||
| 223 | +#[derive(Deserialize)] | ||
| 224 | +struct ViewedForm { | ||
| 225 | + csrf: String, | ||
| 226 | + path: String, | ||
| 227 | + viewed: String, | ||
| 228 | +} | ||
| 229 | + | ||
| 230 | +/// Marks or clears the viewer's Viewed mark on one file. The blob is read from the head here, never | ||
| 231 | +/// taken from the form, so a mark always names the file as it is now. A path that is not a file of | ||
| 232 | +/// the pull request changes nothing. The repo and pull lookups match the Files page, so an | ||
| 233 | +/// unreadable repo answers with the same not-found. | ||
| 234 | +#[route(POST "/{owner}/{repo}/pulls/{number}/viewed")] | ||
| 235 | +async fn viewed_post(cx: &Cx, Form(form): Form<ViewedForm>) -> Result<SeeOther> { | ||
| 236 | + let number = parse_number(path_param::<Number>(cx))?; | ||
| 237 | + let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?; | ||
| 238 | + let (user, session) = require_user(cx).await?; | ||
| 239 | + check_write(&ctx, &session, &form.csrf)?; | ||
| 240 | + let state = app_context::<AppState>(cx); | ||
| 241 | + let pr = match state.store.pull_by_number(&ctx.repo.id, number).await? { | ||
| 242 | + Some(pr) => pr, | ||
| 243 | + None => return Err(not_found().into()), | ||
| 244 | + }; | ||
| 245 | + let files = format!( | ||
| 246 | + "{}/files", | ||
| 247 | + repo_href( | ||
| 248 | + &ctx.repo.owner_name, | ||
| 249 | + &ctx.repo.name, | ||
| 250 | + "pulls", | ||
| 251 | + &number.to_string() | ||
| 252 | + ) | ||
| 253 | + ); | ||
| 254 | + let diff = pull_diff(state, &ctx, &pr).await?; | ||
| 255 | + let listed = diff | ||
| 256 | + .files | ||
| 257 | + .iter() | ||
| 258 | + .any(|file| mark_path(file) == Some(form.path.as_str())); | ||
| 259 | + if !listed { | ||
| 260 | + return Ok(see_other(files)); | ||
| 261 | + } | ||
| 262 | + if form.viewed == "1" { | ||
| 263 | + let blob = blob_at(&state.git, &ctx.path, &pr.head_oid, &form.path) | ||
| 264 | + .await? | ||
| 265 | + .unwrap_or_default(); | ||
| 266 | + state | ||
| 267 | + .store | ||
| 268 | + .set_pull_file_viewed(&user.id, &pr.issue.id, &form.path, &blob) | ||
| 269 | + .await?; | ||
| 270 | + } else { | ||
| 271 | + state | ||
| 272 | + .store | ||
| 273 | + .clear_pull_file_viewed(&user.id, &pr.issue.id, &form.path) | ||
| 274 | + .await?; | ||
| 275 | + } | ||
| 276 | + Ok(see_other(files)) | ||
| 277 | +} | ||
| 278 | + | ||
| 76 | /// The review bar: the viewer's pending comment count, a summary, the review type and Submit, | 279 | /// The review bar: the viewer's pending comment count, a summary, the review type and Submit, |
| 77 | /// plus Discard. The PR author can only comment, so approve and request changes are left out. | 280 | /// plus Discard. The PR author can only comment, so approve and request changes are left out. |
| 78 | #[component] | 281 | #[component] |
| @@ -131,6 +334,22 @@ async fn pull_files(cx: &Cx) -> Result<impl View> { | |||
| 131 | let full_diff = pull_diff(state, &ctx, &pr).await?; | 334 | let full_diff = pull_diff(state, &ctx, &pr).await?; |
| 132 | let frame = frame_in(lang, state, &ctx, &pr, commit_count, full_diff.files.len()).await?; | 335 | let frame = frame_in(lang, state, &ctx, &pr, commit_count, full_diff.files.len()).await?; |
| 133 | let opts = DiffOpts::from_cx(cx, None).await?; | 336 | let opts = DiffOpts::from_cx(cx, None).await?; |
| 337 | + // The Viewed panel lists the full diff, so it is built before `diff` may shrink below. | ||
| 338 | + let panel = match viewer(&ctx) { | ||
| 339 | + Some(user) => { | ||
| 340 | + let marks = state | ||
| 341 | + .store | ||
| 342 | + .pull_viewed_files(&user.id, &pr.issue.id) | ||
| 343 | + .await?; | ||
| 344 | + Some(ViewedPanel { | ||
| 345 | + rows: viewed_rows(state, &ctx, &pr, &full_diff, &marks).await?, | ||
| 346 | + pr_href: frame.href.clone(), | ||
| 347 | + csrf: csrf_of(&ctx), | ||
| 348 | + archived: ctx.repo.archived, | ||
| 349 | + }) | ||
| 350 | + } | ||
| 351 | + None => None, | ||
| 352 | + }; | ||
| 134 | // With whitespace ignored the file list can shrink, so file indexes differ from the comment | 353 | // With whitespace ignored the file list can shrink, so file indexes differ from the comment |
| 135 | // routes' view. Existing threads still show; new inline comments wait for the full diff. | 354 | // routes' view. Existing threads still show; new inline comments wait for the full diff. |
| 136 | let diff = if opts.ignore_ws { | 355 | let diff = if opts.ignore_ws { |
| @@ -231,6 +450,9 @@ async fn pull_files(cx: &Cx) -> Result<impl View> { | |||
| 231 | if can_review { | 450 | if can_review { |
| 232 | review_bar(lang: lang, pr_href: href.clone(), csrf: csrf.clone(), pending: pending, is_author: is_author) | 451 | review_bar(lang: lang, pr_href: href.clone(), csrf: csrf.clone(), pending: pending, is_author: is_author) |
| 233 | } | 452 | } |
| 453 | + if let Some(panel) = panel { | ||
| 454 | + viewed_panel(lang: lang, panel: panel) | ||
| 455 | + } | ||
| 234 | diff_section(diff: &diff, owner: owner.as_str(), repo: name.as_str(), | 456 | diff_section(diff: &diff, owner: owner.as_str(), repo: name.as_str(), |
| 235 | oid: pr.head_oid.as_str(), parent: parent.as_deref(), | 457 | oid: pr.head_oid.as_str(), parent: parent.as_deref(), |
| 236 | subject: g::t(lang, K::ThisPullRequest), lang: DiffLang(lang), comments: comments, opts: opts) | 458 | subject: g::t(lang, K::ThisPullRequest), lang: DiffLang(lang), comments: comments, opts: opts) |
crates/forge-web/src/pages/pulls_list.rsmodified+3 -3
| @@ -275,7 +275,7 @@ async fn pulls_list_page(cx: &Cx) -> Result<impl View> { | |||
| 275 | <div class="issue-tools"> | 275 | <div class="issue-tools"> |
| 276 | <a class="issue-tab-link" href=(queue_href.as_str())>(mq::t(lang, mq::K::MergeQueueTitle))</a> | 276 | <a class="issue-tab-link" href=(queue_href.as_str())>(mq::t(lang, mq::K::MergeQueueTitle))</a> |
| 277 | if can_create { | 277 | if can_create { |
| 278 | - <a class="button" href=(compare_href.as_str())>(g::t(lang, K::NewPullRequest))</a> | 278 | + <a class="button" href=(compare_href.as_str()) data-palette-action="go">(g::t(lang, K::NewPullRequest))</a> |
| 279 | } | 279 | } |
| 280 | </div> | 280 | </div> |
| 281 | </div> | 281 | </div> |
| @@ -309,7 +309,7 @@ async fn pulls_list_page(cx: &Cx) -> Result<impl View> { | |||
| 309 | } else if open_count + closed_count == 0 { | 309 | } else if open_count + closed_count == 0 { |
| 310 | empty_state(title: empty_text, | 310 | empty_state(title: empty_text, |
| 311 | if can_create { | 311 | if can_create { |
| 312 | - <a class="button primary" href=(compare_href.as_str())>(g::t(lang, K::NewPullRequest))</a> | 312 | + <a class="button primary" href=(compare_href.as_str()) data-palette-action="go">(g::t(lang, K::NewPullRequest))</a> |
| 313 | } | 313 | } |
| 314 | ) | 314 | ) |
| 315 | } else { | 315 | } else { |
| @@ -318,7 +318,7 @@ async fn pulls_list_page(cx: &Cx) -> Result<impl View> { | |||
| 318 | } else { | 318 | } else { |
| 319 | <ul class="issue-list"> | 319 | <ul class="issue-list"> |
| 320 | for row in rows.iter() { | 320 | for row in rows.iter() { |
| 321 | - <li class="issue-row"> | 321 | + <li class="issue-row" data-kb-row=""> |
| 322 | <span class=(row.state_class) role="img" aria-label=(row.state_label)></span> | 322 | <span class=(row.state_class) role="img" aria-label=(row.state_label)></span> |
| 323 | <div class="issue-main"> | 323 | <div class="issue-main"> |
| 324 | <div class="issue-title-line"> | 324 | <div class="issue-title-line"> |
crates/forge-web/src/pages/refs.rsmodified+2 -1
| @@ -18,6 +18,7 @@ use crate::pages::ref_live; | |||
| 18 | use crate::pages::repo::repo_head; | 18 | use crate::pages::repo::repo_head; |
| 19 | use crate::pages::repo_ctx::{RepoCtx, load_repo}; | 19 | use crate::pages::repo_ctx::{RepoCtx, load_repo}; |
| 20 | use crate::pages::tree::{LastCommit, last_commit_view}; | 20 | use crate::pages::tree::{LastCommit, last_commit_view}; |
| 21 | +use crate::views::commit_line::commit_line; | ||
| 21 | use crate::views::{RefLink, empty_state, now_unix, repo_href, shell}; | 22 | use crate::views::{RefLink, empty_state, now_unix, repo_href, shell}; |
| 22 | 23 | ||
| 23 | path_param!(owner); | 24 | path_param!(owner); |
| @@ -131,7 +132,7 @@ async fn refs_table(rows: Vec<RefRow>, kind_label: &str, lang: Lang) -> Result<i | |||
| 131 | </span> | 132 | </span> |
| 132 | </td> | 133 | </td> |
| 133 | if let Some(last) = row.last { | 134 | if let Some(last) = row.last { |
| 134 | - <td class="tree-commit"><a href=(last.href)>(last.summary)</a></td> | 135 | + <td class="tree-commit"><a href=(last.href)>commit_line(subject: last.summary.clone())</a></td> |
| 135 | <td class="age"> | 136 | <td class="age"> |
| 136 | <time datetime=(last.iso.clone()) title=(last.absolute)>(last.age)</time> | 137 | <time datetime=(last.iso.clone()) title=(last.absolute)>(last.age)</time> |
| 137 | </td> | 138 | </td> |
crates/forge-web/src/pages/repo.rsmodified+1 -1
| @@ -187,7 +187,7 @@ pub async fn repo_head(head: RepoHead) -> Result<impl View> { | |||
| 187 | if let Some((action, label, csrf)) = star_control { | 187 | if let Some((action, label, csrf)) = star_control { |
| 188 | <form method="post" action=(action.as_str()) class="star-form"> | 188 | <form method="post" action=(action.as_str()) class="star-form"> |
| 189 | <input type="hidden" name="csrf" value=(csrf.as_str())> | 189 | <input type="hidden" name="csrf" value=(csrf.as_str())> |
| 190 | - <button type="submit" class="star-button">(label.as_str())</button> | 190 | + <button type="submit" class="star-button" data-palette-action="post">(label.as_str())</button> |
| 191 | </form> | 191 | </form> |
| 192 | } else { | 192 | } else { |
| 193 | <span class="muted" aria-label=(g::t(lang, K::StarsAria))>(anon_count.as_str())</span> | 193 | <span class="muted" aria-label=(g::t(lang, K::StarsAria))>(anon_count.as_str())</span> |
crates/forge-web/src/pages/repo_side.rsmodified+44 -5
| @@ -17,6 +17,7 @@ use topcoat::view::{View, component, view}; | |||
| 17 | 17 | ||
| 18 | use crate::i18n::Lang; | 18 | use crate::i18n::Lang; |
| 19 | use crate::i18n::releases_ci as rc; | 19 | use crate::i18n::releases_ci as rc; |
| 20 | +use crate::pages::ci_estimate::{self, Est, Step}; | ||
| 20 | use crate::pages::ci_runs::{duration_templates, duration_text, run_href, state_text}; | 21 | use crate::pages::ci_runs::{duration_templates, duration_text, run_href, state_text}; |
| 21 | use crate::pages::packages::PackageLink; | 22 | use crate::pages::packages::PackageLink; |
| 22 | use crate::pages::passkeys::s; | 23 | use crate::pages::passkeys::s; |
| @@ -124,6 +125,8 @@ pub struct RunRow { | |||
| 124 | pub pre: Option<String>, | 125 | pub pre: Option<String>, |
| 125 | /// The right-hand text, or the elapsed time of a run still going. | 126 | /// The right-hand text, or the elapsed time of a run still going. |
| 126 | pub label: String, | 127 | pub label: String, |
| 128 | + /// The expected total of a running run, from its past runs. When set, the bar is its fill. | ||
| 129 | + pub est: Option<Est>, | ||
| 127 | pub title: String, | 130 | pub title: String, |
| 128 | } | 131 | } |
| 129 | 132 | ||
| @@ -167,7 +170,7 @@ pub async fn run_rows(state: &AppState, lang: Lang, repo: &Repo) -> Result<Vec<R | |||
| 167 | .strip_prefix("refs/heads/") | 170 | .strip_prefix("refs/heads/") |
| 168 | .or_else(|| run.git_ref.strip_prefix("refs/tags/")) | 171 | .or_else(|| run.git_ref.strip_prefix("refs/tags/")) |
| 169 | .unwrap_or(&run.git_ref); | 172 | .unwrap_or(&run.git_ref); |
| 170 | - let (bar, since, pre, label) = if matches!(run.state, RunState::Running | RunState::Queued) | 173 | + let (bar, since, pre, label, est) = if matches!(run.state, RunState::Running | RunState::Queued) |
| 171 | { | 174 | { |
| 172 | let current = jobs | 175 | let current = jobs |
| 173 | .iter() | 176 | .iter() |
| @@ -183,11 +186,40 @@ pub async fn run_rows(state: &AppState, lang: Lang, repo: &Repo) -> Result<Vec<R | |||
| 183 | // A sliver shows even before the first job is done. | 186 | // A sliver shows even before the first job is done. |
| 184 | let fill = if done == 0 { 0.2 } else { done as f64 }; | 187 | let fill = if done == 0 { 0.2 } else { done as f64 }; |
| 185 | let since_stamp = started.unwrap_or(run.created_at.as_str()); | 188 | let since_stamp = started.unwrap_or(run.created_at.as_str()); |
| 189 | + let took = duration_text(lang, Some(since_stamp), None); | ||
| 190 | + let est = if run.state == RunState::Running { | ||
| 191 | + let samples = state | ||
| 192 | + .store | ||
| 193 | + .recent_job_samples(&repo.id, std::slice::from_ref(&run.git_ref)) | ||
| 194 | + .await?; | ||
| 195 | + let steps: Vec<Step> = jobs | ||
| 196 | + .iter() | ||
| 197 | + .map(|job| Step { | ||
| 198 | + name: job.name.clone(), | ||
| 199 | + needs: ci_estimate::needs_of(&job.spec_json), | ||
| 200 | + state: job.state, | ||
| 201 | + started: job.started_at.as_deref().and_then(unix), | ||
| 202 | + finished: job.finished_at.as_deref().and_then(unix), | ||
| 203 | + }) | ||
| 204 | + .collect(); | ||
| 205 | + let now = now_unix(); | ||
| 206 | + unix(since_stamp).and_then(|origin| { | ||
| 207 | + let end = ci_estimate::run_end(now, &steps, &samples, &run.git_ref)?; | ||
| 208 | + Some(ci_estimate::estimate(lang, origin, now, end)) | ||
| 209 | + }) | ||
| 210 | + } else { | ||
| 211 | + None | ||
| 212 | + }; | ||
| 213 | + let label = match est.as_ref() { | ||
| 214 | + Some(est) => format!("{took} \u{b7} {}", est.phrase), | ||
| 215 | + None => took, | ||
| 216 | + }; | ||
| 186 | ( | 217 | ( |
| 187 | Some((format!("{fill}"), total.max(1).to_string())), | 218 | Some((format!("{fill}"), total.max(1).to_string())), |
| 188 | unix(since_stamp).map(|secs| secs.to_string()), | 219 | unix(since_stamp).map(|secs| secs.to_string()), |
| 189 | (!current.is_empty()).then(|| format!("{current} \u{b7} ")), | 220 | (!current.is_empty()).then(|| format!("{current} \u{b7} ")), |
| 190 | - duration_text(lang, Some(since_stamp), None), | 221 | + label, |
| 222 | + est, | ||
| 191 | ) | 223 | ) |
| 192 | } else { | 224 | } else { |
| 193 | let failed = jobs | 225 | let failed = jobs |
| @@ -212,7 +244,7 @@ pub async fn run_rows(state: &AppState, lang: Lang, repo: &Repo) -> Result<Vec<R | |||
| 212 | } else { | 244 | } else { |
| 213 | format!("{word} \u{b7} {took}") | 245 | format!("{word} \u{b7} {took}") |
| 214 | }; | 246 | }; |
| 215 | - (None, None, None, label) | 247 | + (None, None, None, label, None) |
| 216 | }; | 248 | }; |
| 217 | rows.push(RunRow { | 249 | rows.push(RunRow { |
| 218 | href: run_href(&title, run.number), | 250 | href: run_href(&title, run.number), |
| @@ -222,6 +254,7 @@ pub async fn run_rows(state: &AppState, lang: Lang, repo: &Repo) -> Result<Vec<R | |||
| 222 | since, | 254 | since, |
| 223 | pre, | 255 | pre, |
| 224 | label, | 256 | label, |
| 257 | + est, | ||
| 225 | title: format!( | 258 | title: format!( |
| 226 | "{}: {done}/{total} \u{b7} {branch} \u{b7} {}", | 259 | "{}: {done}/{total} \u{b7} {branch} \u{b7} {}", |
| 227 | s(lang, "Jobs passed", "Geçen işler"), | 260 | s(lang, "Jobs passed", "Geçen işler"), |
| @@ -354,12 +387,18 @@ pub async fn repo_ci_line(lang: Lang, runs: Vec<RunRow>, ci_href: String) -> Res | |||
| 354 | <a class="side-run-link" href=(run.href.as_str()) title=(run.title.as_str())> | 387 | <a class="side-run-link" href=(run.href.as_str()) title=(run.title.as_str())> |
| 355 | <span class=(run.dot)></span> | 388 | <span class=(run.dot)></span> |
| 356 | <span class="side-run-name">(format!("CI #{}", run.number))</span> | 389 | <span class="side-run-name">(format!("CI #{}", run.number))</span> |
| 357 | - if let Some((value, max)) = run.bar.as_ref() { | 390 | + if let Some(est) = run.est.as_ref() { |
| 391 | + <progress class="side-run-bar" max="100" value=(est.pct.as_str()) data-est="true" data-since=(run.since.as_deref()) data-expected=(est.expected.as_str())></progress> | ||
| 392 | + } else if let Some((value, max)) = run.bar.as_ref() { | ||
| 358 | <progress class="side-run-bar" value=(value.as_str()) max=(max.as_str())></progress> | 393 | <progress class="side-run-bar" value=(value.as_str()) max=(max.as_str())></progress> |
| 359 | } | 394 | } |
| 360 | <span class="side-run-text muted"> | 395 | <span class="side-run-text muted"> |
| 361 | if let Some(since) = run.since.as_deref() { | 396 | if let Some(since) = run.since.as_deref() { |
| 362 | - <span data-since=(since) data-pre=(run.pre.as_deref())>(run.label.as_str())</span> | 397 | + if let Some(est) = run.est.as_ref() { |
| 398 | + <span data-since=(since) data-pre=(run.pre.as_deref()) data-expected=(est.expected.as_str()) data-left=(est.left.as_str()) data-over=(est.over.as_str()) data-lm=(est.minutes.as_str())>(run.label.as_str())</span> | ||
| 399 | + } else { | ||
| 400 | + <span data-since=(since) data-pre=(run.pre.as_deref())>(run.label.as_str())</span> | ||
| 401 | + } | ||
| 363 | } else { | 402 | } else { |
| 364 | (run.label.as_str()) | 403 | (run.label.as_str()) |
| 365 | } | 404 | } |
crates/forge-web/src/pages/settings_appearance.rsmodified+118 -3
| @@ -4,8 +4,11 @@ | |||
| 4 | //! saves at once, so the form has no Save button. Anonymous visitors set the theme from the footer | 4 | //! saves at once, so the form has no Save button. Anonymous visitors set the theme from the footer |
| 5 | //! instead (see `pages/theme_cookie.rs`). Every POST checks the CSRF token first. | 5 | //! instead (see `pages/theme_cookie.rs`). Every POST checks the CSRF token first. |
| 6 | 6 | ||
| 7 | +use std::collections::HashMap; | ||
| 8 | + | ||
| 7 | use forge_core::AuditAction; | 9 | use forge_core::AuditAction; |
| 8 | use forge_core::store::ui_prefs::{SIDEBAR_SIDES, THEMES}; | 10 | use forge_core::store::ui_prefs::{SIDEBAR_SIDES, THEMES}; |
| 11 | +use forge_core::store::user_prefs::{DENSITIES, DENSITY, SOUND, SOUND_VALUES}; | ||
| 9 | use forge_core::{Error as CoreError, Session, Store, User}; | 12 | use forge_core::{Error as CoreError, Session, Store, User}; |
| 10 | use serde::{Deserialize, Deserializer}; | 13 | use serde::{Deserialize, Deserializer}; |
| 11 | use topcoat::Result; | 14 | use topcoat::Result; |
| @@ -67,6 +70,11 @@ struct AppearanceForm { | |||
| 67 | base_dark: Option<String>, | 70 | base_dark: Option<String>, |
| 68 | #[serde(default, deserialize_with = "present_string")] | 71 | #[serde(default, deserialize_with = "present_string")] |
| 69 | sidebar_side: Option<String>, | 72 | sidebar_side: Option<String>, |
| 73 | + /// Sent by the density buttons and the sound switch only. Absent keeps the stored value. | ||
| 74 | + #[serde(default, deserialize_with = "present_string")] | ||
| 75 | + density: Option<String>, | ||
| 76 | + #[serde(default, deserialize_with = "present_string")] | ||
| 77 | + sound: Option<String>, | ||
| 70 | } | 78 | } |
| 71 | 79 | ||
| 72 | struct Choice { | 80 | struct Choice { |
| @@ -161,6 +169,22 @@ struct AppearancePage { | |||
| 161 | light: ColourGroup, | 169 | light: ColourGroup, |
| 162 | dark: ColourGroup, | 170 | dark: ColourGroup, |
| 163 | sidebar: Vec<Choice>, | 171 | sidebar: Vec<Choice>, |
| 172 | + density: Vec<Choice>, | ||
| 173 | + /// Whether the run-finished tone is on: the sound switch's checked state. | ||
| 174 | + sound_on: bool, | ||
| 175 | +} | ||
| 176 | + | ||
| 177 | +/// The `data-density` value the shell puts on `<html>`: `compact` only. Comfortable is the | ||
| 178 | +/// default, so it has no attribute. `None` for a signed-out visitor, who gets browser storage. | ||
| 179 | +pub fn density_attr(prefs: Option<&HashMap<String, String>>) -> Option<&'static str> { | ||
| 180 | + let stored = prefs.and_then(|p| p.get(DENSITY))?; | ||
| 181 | + (stored == "compact").then_some("compact") | ||
| 182 | +} | ||
| 183 | + | ||
| 184 | +/// The `data-sound` value the shell puts on `<html>`: `on` when the viewer wants the tone. | ||
| 185 | +pub fn sound_attr(prefs: Option<&HashMap<String, String>>) -> Option<&'static str> { | ||
| 186 | + let stored = prefs.and_then(|p| p.get(SOUND))?; | ||
| 187 | + (stored == "on").then_some("on") | ||
| 164 | } | 188 | } |
| 165 | 189 | ||
| 166 | /// The label of a sidebar side. | 190 | /// The label of a sidebar side. |
| @@ -421,13 +445,16 @@ async fn appearance_body(page: AppearancePage) -> Result<impl View> { | |||
| 421 | light, | 445 | light, |
| 422 | dark, | 446 | dark, |
| 423 | sidebar, | 447 | sidebar, |
| 448 | + density, | ||
| 449 | + sound_on, | ||
| 424 | } = page; | 450 | } = page; |
| 425 | Ok(view! { | 451 | Ok(view! { |
| 426 | <div class="settings-layout"> | 452 | <div class="settings-layout"> |
| 427 | <section class="page-head"> | 453 | <section class="page-head"> |
| 428 | <h1>(g::t(lang, K::Appearance))</h1> | 454 | <h1>(g::t(lang, K::Appearance))</h1> |
| 429 | </section> | 455 | </section> |
| 430 | - <form method="post" action="/settings/appearance" class="appearance" data-appearance="true"> | 456 | + <div class="appearance-page"> |
| 457 | + <form id="appearance-form" method="post" action="/settings/appearance" class="appearance" data-appearance="true"> | ||
| 431 | <input type="hidden" name="csrf" value=(csrf.as_str())> | 458 | <input type="hidden" name="csrf" value=(csrf.as_str())> |
| 432 | <div class="appearance-top"> | 459 | <div class="appearance-top"> |
| 433 | <label> | 460 | <label> |
| @@ -458,6 +485,28 @@ async fn appearance_body(page: AppearancePage) -> Result<impl View> { | |||
| 458 | } | 485 | } |
| 459 | </div> | 486 | </div> |
| 460 | </fieldset> | 487 | </fieldset> |
| 488 | + <fieldset class="side-picker density-picker"> | ||
| 489 | + <legend>(g::t(lang, K::DensityLabel))</legend> | ||
| 490 | + <div class="segmented snippet-segmented" role="group"> | ||
| 491 | + for choice in density.into_iter() { | ||
| 492 | + <label class="segment"> | ||
| 493 | + <input type="radio" name="density" value=(choice.value) checked=(choice.selected) data-autosubmit="true"> | ||
| 494 | + <span>(choice.label)</span> | ||
| 495 | + </label> | ||
| 496 | + } | ||
| 497 | + </div> | ||
| 498 | + <small class="muted">(g::t(lang, K::DensityHelp))</small> | ||
| 499 | + </fieldset> | ||
| 500 | + <fieldset class="side-picker sound-toggle"> | ||
| 501 | + <legend>(g::t(lang, K::SoundLabel))</legend> | ||
| 502 | + <div class="sound-row"> | ||
| 503 | + <span>(g::t(lang, K::SoundSwitch))</span> | ||
| 504 | + <label class="sound-switch"> | ||
| 505 | + <input type="checkbox" name="sound" value="on" checked=(sound_on) data-autosubmit="true" aria-label=(g::t(lang, K::SoundSwitch))> | ||
| 506 | + <span class="sound-track"><span class="sound-knob"></span></span> | ||
| 507 | + </label> | ||
| 508 | + </div> | ||
| 509 | + </fieldset> | ||
| 461 | </div> | 510 | </div> |
| 462 | <fieldset class="card colour-group" data-colour-group="true" data-tab=(tab)> | 511 | <fieldset class="card colour-group" data-colour-group="true" data-tab=(tab)> |
| 463 | <legend>(colours)</legend> | 512 | <legend>(colours)</legend> |
| @@ -473,6 +522,19 @@ async fn appearance_body(page: AppearancePage) -> Result<impl View> { | |||
| 473 | colour_panel(group: dark) | 522 | colour_panel(group: dark) |
| 474 | </fieldset> | 523 | </fieldset> |
| 475 | </form> | 524 | </form> |
| 525 | + <section class="card sound-card" aria-label=(g::t(lang, K::SoundLabel))> | ||
| 526 | + <p class="muted small">(g::t(lang, K::SoundOwnRuns)) " · " (g::t(lang, K::SoundFootOwn))</p> | ||
| 527 | + <div class="sound-row"> | ||
| 528 | + <span class="sound-name">(g::t(lang, K::SoundPassed)) <span class="muted">(g::t(lang, K::SoundPassedNote))</span></span> | ||
| 529 | + <button type="button" class="btn" data-sound-play="passed">(g::t(lang, K::SoundPlay))</button> | ||
| 530 | + </div> | ||
| 531 | + <div class="sound-row"> | ||
| 532 | + <span class="sound-name">(g::t(lang, K::SoundFailed)) <span class="muted">(g::t(lang, K::SoundFailedNote))</span></span> | ||
| 533 | + <button type="button" class="btn" data-sound-play="failed">(g::t(lang, K::SoundPlay))</button> | ||
| 534 | + </div> | ||
| 535 | + <p class="muted small">(g::t(lang, K::SoundFootTones))</p> | ||
| 536 | + </section> | ||
| 537 | + </div> | ||
| 476 | </div> | 538 | </div> |
| 477 | }) | 539 | }) |
| 478 | } | 540 | } |
| @@ -526,8 +588,13 @@ pub fn sidebar_stored(stored: &str) -> &'static str { | |||
| 526 | 588 | ||
| 527 | /// Builds the page for a viewer. Each choice shows the stored value, or the default when the | 589 | /// Builds the page for a viewer. Each choice shows the stored value, or the default when the |
| 528 | /// stored id is no longer offered, which is what the page renders on `<html>` too. | 590 | /// stored id is no longer offered, which is what the page renders on `<html>` too. |
| 529 | -fn page_for(viewer: &(User, Session), lang: Lang) -> AppearancePage { | 591 | +fn page_for(viewer: &(User, Session), lang: Lang, prefs: &HashMap<String, String>) -> AppearancePage { |
| 530 | let user = &viewer.0; | 592 | let user = &viewer.0; |
| 593 | + let density = match prefs.get(DENSITY).map(String::as_str) { | ||
| 594 | + Some("compact") => "compact", | ||
| 595 | + _ => "comfortable", | ||
| 596 | + }; | ||
| 597 | + let sound_on = prefs.get(SOUND).is_some_and(|v| v == "on"); | ||
| 531 | // The tab that opens first is the dark colours for a dark theme. The page script moves it to | 598 | // The tab that opens first is the dark colours for a dark theme. The page script moves it to |
| 532 | // the one the viewer sees when the theme follows the system. | 599 | // the one the viewer sees when the theme follows the system. |
| 533 | let tab = if user.theme == "dark" { | 600 | let tab = if user.theme == "dark" { |
| @@ -550,6 +617,32 @@ fn page_for(viewer: &(User, Session), lang: Lang) -> AppearancePage { | |||
| 550 | sidebar: choices(SIDEBAR_CODES, sidebar_stored(&user.sidebar_side), |code| { | 617 | sidebar: choices(SIDEBAR_CODES, sidebar_stored(&user.sidebar_side), |code| { |
| 551 | sidebar_label(lang, code) | 618 | sidebar_label(lang, code) |
| 552 | }), | 619 | }), |
| 620 | + density: choices(DENSITIES, density, |code| density_label(lang, code)), | ||
| 621 | + sound_on, | ||
| 622 | + } | ||
| 623 | +} | ||
| 624 | + | ||
| 625 | +/// The label of a row density: Comfortable or Compact. | ||
| 626 | +fn density_label(lang: Lang, code: &str) -> &'static str { | ||
| 627 | + if code == "compact" { | ||
| 628 | + g::t(lang, K::DensityCompact) | ||
| 629 | + } else { | ||
| 630 | + g::t(lang, K::DensityComfortable) | ||
| 631 | + } | ||
| 632 | +} | ||
| 633 | + | ||
| 634 | +/// A density or sound value a save stores. Absent (`None`) stores nothing. A present value must | ||
| 635 | +/// be one offered, so an empty or unknown value is rejected. | ||
| 636 | +fn pref_choice( | ||
| 637 | + lang: Lang, | ||
| 638 | + posted: Option<&str>, | ||
| 639 | + offered: &[&str], | ||
| 640 | + refused: K, | ||
| 641 | +) -> forge_core::Result<Option<String>> { | ||
| 642 | + match posted { | ||
| 643 | + None => Ok(None), | ||
| 644 | + Some(value) if offered.contains(&value) => Ok(Some(value.to_owned())), | ||
| 645 | + Some(_) => Err(CoreError::Invalid(g::t(lang, refused).into())), | ||
| 553 | } | 646 | } |
| 554 | } | 647 | } |
| 555 | 648 | ||
| @@ -557,7 +650,11 @@ fn page_for(viewer: &(User, Session), lang: Lang) -> AppearancePage { | |||
| 557 | async fn appearance_page(cx: &Cx) -> Result<impl View> { | 650 | async fn appearance_page(cx: &Cx) -> Result<impl View> { |
| 558 | let viewer = require_user(cx).await?; | 651 | let viewer = require_user(cx).await?; |
| 559 | let lang = i18n::lang(cx, Some(&viewer.0)); | 652 | let lang = i18n::lang(cx, Some(&viewer.0)); |
| 560 | - let page = page_for(&viewer, lang); | 653 | + let prefs = app_context::<AppState>(cx) |
| 654 | + .store | ||
| 655 | + .user_prefs(&viewer.0.id) | ||
| 656 | + .await?; | ||
| 657 | + let page = page_for(&viewer, lang, &prefs); | ||
| 561 | Ok(view! { | 658 | Ok(view! { |
| 562 | shell(title: g::t(lang, K::Appearance), viewer: Some(&viewer), appearance_body(page: page)) | 659 | shell(title: g::t(lang, K::Appearance), viewer: Some(&viewer), appearance_body(page: page)) |
| 563 | }) | 660 | }) |
| @@ -576,10 +673,26 @@ async fn appearance_save(cx: &Cx, Form(form): Form<AppearanceForm>) -> Result<Se | |||
| 576 | let base_light = base_choice(lang, form.base_light.as_deref(), &user.base_light)?; | 673 | let base_light = base_choice(lang, form.base_light.as_deref(), &user.base_light)?; |
| 577 | let base_dark = base_choice(lang, form.base_dark.as_deref(), &user.base_dark)?; | 674 | let base_dark = base_choice(lang, form.base_dark.as_deref(), &user.base_dark)?; |
| 578 | let sidebar_side = sidebar_choice(lang, form.sidebar_side.as_deref(), &user.sidebar_side)?; | 675 | let sidebar_side = sidebar_choice(lang, form.sidebar_side.as_deref(), &user.sidebar_side)?; |
| 676 | + let density = pref_choice(lang, form.density.as_deref(), DENSITIES, K::ChooseDensity)?; | ||
| 677 | + // An unchecked switch posts nothing. Every post of this form carries the density radio, so | ||
| 678 | + // a missing `sound` with `density` present means off. A post without `density` (an older | ||
| 679 | + // form, or the parts that save alone) leaves the stored sound alone. | ||
| 680 | + let posted_sound = match (&form.density, &form.sound) { | ||
| 681 | + (Some(_), None) => Some("off"), | ||
| 682 | + (_, Some(value)) => Some(value.as_str()), | ||
| 683 | + (None, None) => None, | ||
| 684 | + }; | ||
| 685 | + let sound = pref_choice(lang, posted_sound, SOUND_VALUES, K::ChooseSound)?; | ||
| 579 | store | 686 | store |
| 580 | .set_ui_prefs(&user.id, &form.theme, &form.language) | 687 | .set_ui_prefs(&user.id, &form.theme, &form.language) |
| 581 | .await?; | 688 | .await?; |
| 582 | store.set_sidebar_side(&user.id, &sidebar_side).await?; | 689 | store.set_sidebar_side(&user.id, &sidebar_side).await?; |
| 690 | + if let Some(value) = &density { | ||
| 691 | + store.set_user_pref(&user.id, DENSITY, value).await?; | ||
| 692 | + } | ||
| 693 | + if let Some(value) = &sound { | ||
| 694 | + store.set_user_pref(&user.id, SOUND, value).await?; | ||
| 695 | + } | ||
| 583 | store | 696 | store |
| 584 | .set_colours( | 697 | .set_colours( |
| 585 | &user.id, | 698 | &user.id, |
| @@ -607,6 +720,8 @@ async fn appearance_save(cx: &Cx, Form(form): Form<AppearanceForm>) -> Result<Se | |||
| 607 | "base_light": base_light, | 720 | "base_light": base_light, |
| 608 | "base_dark": base_dark, | 721 | "base_dark": base_dark, |
| 609 | "sidebar_side": sidebar_side, | 722 | "sidebar_side": sidebar_side, |
| 723 | + "density": density, | ||
| 724 | + "sound": sound, | ||
| 610 | }), | 725 | }), |
| 611 | ) | 726 | ) |
| 612 | .await; | 727 | .await; |
crates/forge-web/src/pages/tree.rsmodified+2 -1
| @@ -28,6 +28,7 @@ use crate::raw::raw_url; | |||
| 28 | use crate::render::emoji::emojify; | 28 | use crate::render::emoji::emojify; |
| 29 | use crate::render::markdown::{LinkContext, render_markdown}; | 29 | use crate::render::markdown::{LinkContext, render_markdown}; |
| 30 | use crate::state::AppState; | 30 | use crate::state::AppState; |
| 31 | +use crate::views::commit_line::commit_line; | ||
| 31 | use crate::views::{ | 32 | use crate::views::{ |
| 32 | Crumb, avatar_url, breadcrumb, display_name, iso_time, now_unix, ref_selector, relative_time, | 33 | Crumb, avatar_url, breadcrumb, display_name, iso_time, now_unix, ref_selector, relative_time, |
| 33 | repo_href, shell, short_oid, user_href, | 34 | repo_href, shell, short_oid, user_href, |
| @@ -476,7 +477,7 @@ pub async fn tree_table( | |||
| 476 | </span> | 477 | </span> |
| 477 | </td> | 478 | </td> |
| 478 | if let Some(last) = row.last { | 479 | if let Some(last) = row.last { |
| 479 | - <td class="tree-commit"><a href=(last.href)>(last.summary)</a></td> | 480 | + <td class="tree-commit"><a href=(last.href)>commit_line(subject: last.summary.clone())</a></td> |
| 480 | <td class="age"> | 481 | <td class="age"> |
| 481 | <time data-rel="true" datetime=(last.iso.clone()) title=(last.absolute)>(last.age)</time> | 482 | <time data-rel="true" datetime=(last.iso.clone()) title=(last.absolute)>(last.age)</time> |
| 482 | </td> | 483 | </td> |
crates/forge-web/src/render/commit_message.rsadded+213 -0
| @@ -0,0 +1,213 @@ | |||
| 1 | +//! Splits a commit subject into typed clause groups (`✨ feat: a; 🐛 fix: b`). | ||
| 2 | +//! | ||
| 3 | +//! Clauses are separated by `;` followed by whitespace or the end, except inside backticks. | ||
| 4 | +//! A clause that starts with a known type (after an optional emoji or `:shortcode:`) opens or | ||
| 5 | +//! extends that type's group. Other clauses join the most recent group. | ||
| 6 | +//! | ||
| 7 | +//! Pure string handling, no rendering. Subjects that do not start with a known type are `None`. | ||
| 8 | + | ||
| 9 | +/// Commit types recognised at the start of a clause. | ||
| 10 | +const KINDS: &[&str] = &[ | ||
| 11 | + "feat", "fix", "style", "ci", "perf", "harden", "refactor", "test", "docs", "ui", "ux", "i18n", | ||
| 12 | + "lint", "deps", "db", "chore", "build", "revert", | ||
| 13 | +]; | ||
| 14 | + | ||
| 15 | +/// The clauses of one commit type, in the order they appear in the subject. | ||
| 16 | +#[derive(Debug, Clone, PartialEq, Eq)] | ||
| 17 | +pub struct ClauseGroup { | ||
| 18 | + pub kind: String, | ||
| 19 | + pub clauses: Vec<String>, | ||
| 20 | +} | ||
| 21 | + | ||
| 22 | +/// A parsed commit subject, with one group per type in order of first appearance. | ||
| 23 | +#[derive(Debug, Clone, PartialEq, Eq)] | ||
| 24 | +pub struct CommitMessage { | ||
| 25 | + pub groups: Vec<ClauseGroup>, | ||
| 26 | +} | ||
| 27 | + | ||
| 28 | +impl CommitMessage { | ||
| 29 | + /// None unless the subject starts with a known type; such subjects render as today. | ||
| 30 | + pub fn parse(subject: &str) -> Option<Self> { | ||
| 31 | + let mut groups: Vec<ClauseGroup> = Vec::new(); | ||
| 32 | + let mut seen_first = false; | ||
| 33 | + for segment in split_clauses(subject) { | ||
| 34 | + let clause = segment.trim(); | ||
| 35 | + let clause = clause.strip_suffix('.').unwrap_or(clause); | ||
| 36 | + if clause.is_empty() { | ||
| 37 | + continue; | ||
| 38 | + } | ||
| 39 | + let typed = split_type(clause); | ||
| 40 | + if !seen_first { | ||
| 41 | + seen_first = true; | ||
| 42 | + if typed.is_none() { | ||
| 43 | + return None; | ||
| 44 | + } | ||
| 45 | + } | ||
| 46 | + match typed { | ||
| 47 | + Some((kind, text)) => { | ||
| 48 | + if text.is_empty() { | ||
| 49 | + continue; | ||
| 50 | + } | ||
| 51 | + let index = match groups.iter().position(|group| group.kind == kind) { | ||
| 52 | + Some(index) => index, | ||
| 53 | + None => { | ||
| 54 | + groups.push(ClauseGroup { | ||
| 55 | + kind: kind.to_string(), | ||
| 56 | + clauses: Vec::new(), | ||
| 57 | + }); | ||
| 58 | + groups.len() - 1 | ||
| 59 | + } | ||
| 60 | + }; | ||
| 61 | + groups[index].clauses.push(text.to_string()); | ||
| 62 | + } | ||
| 63 | + None => { | ||
| 64 | + if let Some(group) = groups.last_mut() { | ||
| 65 | + group.clauses.push(clause.to_string()); | ||
| 66 | + } | ||
| 67 | + } | ||
| 68 | + } | ||
| 69 | + } | ||
| 70 | + if groups.is_empty() { | ||
| 71 | + return None; | ||
| 72 | + } | ||
| 73 | + Some(Self { groups }) | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + /// The type of the first group. | ||
| 77 | + pub fn kind(&self) -> &str { | ||
| 78 | + self.groups.first().map_or("", |group| group.kind.as_str()) | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + /// The first clause, with its first letter uppercased when it is a lowercase letter. | ||
| 82 | + pub fn title(&self) -> String { | ||
| 83 | + let first = self | ||
| 84 | + .groups | ||
| 85 | + .first() | ||
| 86 | + .and_then(|group| group.clauses.first()) | ||
| 87 | + .map_or("", String::as_str); | ||
| 88 | + let mut chars = first.chars(); | ||
| 89 | + match chars.next() { | ||
| 90 | + Some(c) if c.is_lowercase() => c.to_uppercase().chain(chars).collect(), | ||
| 91 | + _ => first.to_string(), | ||
| 92 | + } | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + /// The number of clauses after the first. | ||
| 96 | + pub fn extra(&self) -> usize { | ||
| 97 | + self.groups | ||
| 98 | + .iter() | ||
| 99 | + .map(|group| group.clauses.len()) | ||
| 100 | + .sum::<usize>() | ||
| 101 | + .saturating_sub(1) | ||
| 102 | + } | ||
| 103 | +} | ||
| 104 | + | ||
| 105 | +/// Splits at `;` followed by whitespace or the end, outside backticks. | ||
| 106 | +fn split_clauses(subject: &str) -> Vec<&str> { | ||
| 107 | + let mut out = Vec::new(); | ||
| 108 | + let mut start = 0; | ||
| 109 | + let mut in_ticks = false; | ||
| 110 | + let mut chars = subject.char_indices().peekable(); | ||
| 111 | + while let Some((i, c)) = chars.next() { | ||
| 112 | + match c { | ||
| 113 | + '`' => in_ticks = !in_ticks, | ||
| 114 | + ';' if !in_ticks && chars.peek().is_none_or(|&(_, next)| next.is_whitespace()) => { | ||
| 115 | + out.push(&subject[start..i]); | ||
| 116 | + start = i + 1; | ||
| 117 | + } | ||
| 118 | + _ => {} | ||
| 119 | + } | ||
| 120 | + } | ||
| 121 | + out.push(&subject[start..]); | ||
| 122 | + out | ||
| 123 | +} | ||
| 124 | + | ||
| 125 | +/// Drops an optional leading `:shortcode:` or emoji (a non-alphanumeric run followed by a space). | ||
| 126 | +fn strip_marker(clause: &str) -> &str { | ||
| 127 | + if let Some(rest) = clause.strip_prefix(':') { | ||
| 128 | + if let Some(end) = rest.find(':') { | ||
| 129 | + let name = &rest[..end]; | ||
| 130 | + let valid = !name.is_empty() | ||
| 131 | + && name | ||
| 132 | + .bytes() | ||
| 133 | + .all(|b| b.is_ascii_lowercase() || b.is_ascii_digit() || b"_+-".contains(&b)); | ||
| 134 | + if valid && let Some(after) = rest[end + 1..].strip_prefix(' ') { | ||
| 135 | + return after.trim_start(); | ||
| 136 | + } | ||
| 137 | + } | ||
| 138 | + return clause; | ||
| 139 | + } | ||
| 140 | + if let Some(space) = clause.find(' ') { | ||
| 141 | + let prefix = &clause[..space]; | ||
| 142 | + if !prefix.is_empty() && prefix.chars().all(|c| !c.is_alphanumeric()) { | ||
| 143 | + return clause[space + 1..].trim_start(); | ||
| 144 | + } | ||
| 145 | + } | ||
| 146 | + clause | ||
| 147 | +} | ||
| 148 | + | ||
| 149 | +/// The known type and the clause text, for `type: text`, `type(scope): text` or `type!: text`. | ||
| 150 | +fn split_type(clause: &str) -> Option<(&'static str, &str)> { | ||
| 151 | + let rest = strip_marker(clause); | ||
| 152 | + let word_len = rest.bytes().take_while(u8::is_ascii_lowercase).count(); | ||
| 153 | + let kind = KINDS.iter().copied().find(|kind| *kind == &rest[..word_len])?; | ||
| 154 | + let mut tail = &rest[word_len..]; | ||
| 155 | + if let Some(after) = tail.strip_prefix('(') { | ||
| 156 | + let close = after.find(')')?; | ||
| 157 | + tail = &after[close + 1..]; | ||
| 158 | + } | ||
| 159 | + tail = tail.strip_prefix('!').unwrap_or(tail); | ||
| 160 | + let text = tail.strip_prefix(':')?; | ||
| 161 | + if !text.is_empty() && !text.starts_with(' ') { | ||
| 162 | + return None; | ||
| 163 | + } | ||
| 164 | + Some((kind, text.trim())) | ||
| 165 | +} | ||
| 166 | + | ||
| 167 | +#[cfg(test)] | ||
| 168 | +mod tests { | ||
| 169 | + use super::*; | ||
| 170 | + | ||
| 171 | + #[test] | ||
| 172 | + fn commit_message_splits_multi_group_subject() { | ||
| 173 | + let message = CommitMessage::parse( | ||
| 174 | + "✨ feat: the tab bar is built from lists, so X; Explore moves to a link; \ | ||
| 175 | + 💄 style: pages fit the window; an overview is redesigned; 🐛 fix: the bell opens once", | ||
| 176 | + ) | ||
| 177 | + .expect("typed subject"); | ||
| 178 | + assert_eq!(message.kind(), "feat"); | ||
| 179 | + assert_eq!(message.extra(), 4); | ||
| 180 | + assert_eq!(message.title(), "The tab bar is built from lists, so X"); | ||
| 181 | + let kinds: Vec<&str> = message.groups.iter().map(|g| g.kind.as_str()).collect(); | ||
| 182 | + assert_eq!(kinds, ["feat", "style", "fix"]); | ||
| 183 | + assert_eq!(message.groups[0].clauses.len(), 2); | ||
| 184 | + } | ||
| 185 | + | ||
| 186 | + #[test] | ||
| 187 | + fn commit_message_plain_subject_is_none() { | ||
| 188 | + assert_eq!(CommitMessage::parse("Update the readme"), None); | ||
| 189 | + } | ||
| 190 | + | ||
| 191 | + #[test] | ||
| 192 | + fn commit_message_keeps_semicolon_in_backticks() { | ||
| 193 | + let message = CommitMessage::parse("🐛 fix: keep `a; b` as one clause; ✨ feat: x") | ||
| 194 | + .expect("typed subject"); | ||
| 195 | + assert_eq!(message.groups[0].kind, "fix"); | ||
| 196 | + assert_eq!(message.groups[0].clauses[0], "keep `a; b` as one clause"); | ||
| 197 | + } | ||
| 198 | + | ||
| 199 | + #[test] | ||
| 200 | + fn commit_message_knows_chore_build_revert() { | ||
| 201 | + for subject in ["chore: a", "build(ci): b", "revert: c"] { | ||
| 202 | + assert!(CommitMessage::parse(subject).is_some(), "{subject}"); | ||
| 203 | + } | ||
| 204 | + } | ||
| 205 | + | ||
| 206 | + #[test] | ||
| 207 | + fn commit_message_repeated_kind_merges() { | ||
| 208 | + let message = CommitMessage::parse("✨ feat: a; fix: b; feat: c.").expect("typed subject"); | ||
| 209 | + assert_eq!(message.groups.len(), 2); | ||
| 210 | + assert_eq!(message.groups[0].clauses, ["a", "c"]); | ||
| 211 | + assert_eq!(message.groups[1].clauses, ["b"]); | ||
| 212 | + } | ||
| 213 | +} | ||
crates/forge-web/src/render/mod.rsmodified+1 -0
| @@ -1,5 +1,6 @@ | |||
| 1 | //! Pure rendering helpers: markdown and syntax highlighting. | 1 | //! Pure rendering helpers: markdown and syntax highlighting. |
| 2 | 2 | ||
| 3 | +pub mod commit_message; | ||
| 3 | pub mod emoji; | 4 | pub mod emoji; |
| 4 | pub mod highlight; | 5 | pub mod highlight; |
| 5 | pub mod markdown; | 6 | pub mod markdown; |
crates/forge-web/src/views/commit_line.rsadded+50 -0
| @@ -0,0 +1,50 @@ | |||
| 1 | +//! A commit subject on one line, shared by every list that shows subjects one per row: the commit | ||
| 2 | +//! list, compare, branches, the tree's last-commit cells, blame and the CI runs. A subject that | ||
| 3 | +//! parses shows its first clause with a neutral type tag and a muted count of the clauses after | ||
| 4 | +//! it. Any other subject shows as it always did. The full subject is the `title` attribute. | ||
| 5 | + | ||
| 6 | +use topcoat::Result; | ||
| 7 | +use topcoat::view::{View, component, view}; | ||
| 8 | + | ||
| 9 | +use crate::render::commit_message::CommitMessage; | ||
| 10 | +use crate::render::emoji::emojify; | ||
| 11 | + | ||
| 12 | +/// The first clause of a subject, or the emojified subject when it does not parse. For text that | ||
| 13 | +/// is not rendered through `commit_line`, such as a heading. | ||
| 14 | +pub fn headline(subject: &str) -> String { | ||
| 15 | + let emojified = emojify(subject); | ||
| 16 | + match CommitMessage::parse(&emojified) { | ||
| 17 | + Some(message) => message.title(), | ||
| 18 | + None => emojified.into_owned(), | ||
| 19 | + } | ||
| 20 | +} | ||
| 21 | + | ||
| 22 | +/// One subject on one line, truncated by CSS. `no_tag` drops the type tag where the column is | ||
| 23 | +/// too narrow for it (blame). | ||
| 24 | +#[component] | ||
| 25 | +pub async fn commit_line(subject: String, #[default] no_tag: bool) -> Result<impl View> { | ||
| 26 | + let emojified = emojify(&subject).into_owned(); | ||
| 27 | + let parsed = CommitMessage::parse(&emojified); | ||
| 28 | + let has_tag = parsed.is_some() && !no_tag; | ||
| 29 | + let kind = parsed | ||
| 30 | + .as_ref() | ||
| 31 | + .map_or_else(String::new, |message| message.kind().to_string()); | ||
| 32 | + let extra = parsed.as_ref().map_or(0, CommitMessage::extra); | ||
| 33 | + let has_extra = extra > 0; | ||
| 34 | + let extra_text = format!("+{extra}"); | ||
| 35 | + let text = match &parsed { | ||
| 36 | + Some(message) => message.title(), | ||
| 37 | + None => emojified.clone(), | ||
| 38 | + }; | ||
| 39 | + Ok(view! { | ||
| 40 | + <span class="commit-line" title=(emojified.as_str())> | ||
| 41 | + if has_tag { | ||
| 42 | + <span class="commit-line-kind">(kind.as_str())</span> | ||
| 43 | + } | ||
| 44 | + <span class="commit-line-text">(text.as_str())</span> | ||
| 45 | + if has_extra { | ||
| 46 | + <span class="commit-line-extra">(extra_text.as_str())</span> | ||
| 47 | + } | ||
| 48 | + </span> | ||
| 49 | + }) | ||
| 50 | +} | ||
crates/forge-web/src/views/mod.rsmodified+12 -2
| @@ -1,6 +1,7 @@ | |||
| 1 | //! Shared page chrome: the HTML shell (header, nav, user menu) and form helpers as components, | 1 | //! Shared page chrome: the HTML shell (header, nav, user menu) and form helpers as components, |
| 2 | //! the stylesheet link and the security-headers layer. `view!` escapes text and attribute values. | 2 | //! the stylesheet link and the security-headers layer. `view!` escapes text and attribute values. |
| 3 | 3 | ||
| 4 | +pub mod commit_line; | ||
| 4 | pub mod commit_status; | 5 | pub mod commit_status; |
| 5 | pub mod diff; | 6 | pub mod diff; |
| 6 | pub mod heatmap; | 7 | pub mod heatmap; |
| @@ -451,6 +452,8 @@ pub async fn shell( | |||
| 451 | .as_ref() | 452 | .as_ref() |
| 452 | .and_then(|p| p.get(CORNER_POS)) | 453 | .and_then(|p| p.get(CORNER_POS)) |
| 453 | .and_then(|v| clean_pref(CORNER_POS, v).ok().flatten()); | 454 | .and_then(|v| clean_pref(CORNER_POS, v).ok().flatten()); |
| 455 | + let density_attr = crate::pages::settings_appearance::density_attr(prefs.as_ref()); | ||
| 456 | + let sound_attr = crate::pages::settings_appearance::sound_attr(prefs.as_ref()); | ||
| 454 | let banner_back = back.clone().unwrap_or_else(|| "/".to_owned()); | 457 | let banner_back = back.clone().unwrap_or_else(|| "/".to_owned()); |
| 455 | let dismiss_label = crate::i18n::accounts::t(lang, crate::i18n::accounts::A::Dismiss); | 458 | let dismiss_label = crate::i18n::accounts::t(lang, crate::i18n::accounts::A::Dismiss); |
| 456 | // The admin area and the user settings swap the global links for their own list. Signed-in only. | 459 | // The admin area and the user settings swap the global links for their own list. Signed-in only. |
| @@ -596,7 +599,7 @@ pub async fn shell( | |||
| 596 | }); | 599 | }); |
| 597 | Ok(view! { | 600 | Ok(view! { |
| 598 | <!DOCTYPE html> | 601 | <!DOCTYPE html> |
| 599 | - <html lang=(lang.code()) data-theme=(theme_attr) data-accent-light=(accent_light_id) data-accent-dark=(accent_dark_id) data-base-light=(base_light_id) data-base-dark=(base_dark_id) data-sidebar=(sidebar_side) data-rel-words=(rel_words_attr.as_str()) data-rel-now=(rel_now_attr.as_str())> | 602 | + <html lang=(lang.code()) data-theme=(theme_attr) data-density=(density_attr) data-sound=(sound_attr)data-accent-light=(accent_light_id) data-accent-dark=(accent_dark_id) data-base-light=(base_light_id) data-base-dark=(base_dark_id) data-sidebar=(sidebar_side) data-rel-words=(rel_words_attr.as_str()) data-rel-now=(rel_now_attr.as_str())> |
| 600 | <head> | 603 | <head> |
| 601 | <meta charset="utf-8"> | 604 | <meta charset="utf-8"> |
| 602 | <meta name="viewport" content="width=device-width, initial-scale=1"> | 605 | <meta name="viewport" content="width=device-width, initial-scale=1"> |
| @@ -653,7 +656,9 @@ pub async fn shell( | |||
| 653 | data-orgs=(o::t(lang, OK::Organizations)) data-pages=(br::t(lang, br::K::PalettePages)) | 656 | data-orgs=(o::t(lang, OK::Organizations)) data-pages=(br::t(lang, br::K::PalettePages)) |
| 654 | data-empty=(br::t(lang, br::K::PaletteNoMatches)) data-loading=(br::t(lang, br::K::PaletteLoading)) | 657 | data-empty=(br::t(lang, br::K::PaletteNoMatches)) data-loading=(br::t(lang, br::K::PaletteLoading)) |
| 655 | data-failed=(br::t(lang, br::K::PaletteFailed)) data-hint=(br::t(lang, br::K::FinderHint)) | 658 | data-failed=(br::t(lang, br::K::PaletteFailed)) data-hint=(br::t(lang, br::K::FinderHint)) |
| 656 | - data-search-label=(search_for_label) data-files=(br::t(lang, br::K::PaletteFiles))> | 659 | + data-search-label=(search_for_label) data-files=(br::t(lang, br::K::PaletteFiles)) |
| 660 | + data-actions=(br::t(lang, br::K::PaletteActions)) data-done=(br::t(lang, br::K::PaletteDone)) | ||
| 661 | + data-action-failed=(br::t(lang, br::K::PaletteActionFailed))> | ||
| 657 | <span class="pathbar-hint">(br::t(lang, br::K::PathbarHint))</span> | 662 | <span class="pathbar-hint">(br::t(lang, br::K::PathbarHint))</span> |
| 658 | <kbd>"Ctrl K"</kbd> | 663 | <kbd>"Ctrl K"</kbd> |
| 659 | </button> | 664 | </button> |
| @@ -918,6 +923,11 @@ pub fn global_items(lang: Lang, can_create_org: bool) -> Vec<NavItem> { | |||
| 918 | item("explore", "/explore", t(lang, Key::Explore)), | 923 | item("explore", "/explore", t(lang, Key::Explore)), |
| 919 | item("notifications", "/notifications", t(lang, Key::Notifications)), | 924 | item("notifications", "/notifications", t(lang, Key::Notifications)), |
| 920 | item("reviews", "/review-requests", au::t(lang, AuK::ReviewRequests)), | 925 | item("reviews", "/review-requests", au::t(lang, AuK::ReviewRequests)), |
| 926 | + item( | ||
| 927 | + "needs-you", | ||
| 928 | + "/needs-you", | ||
| 929 | + crate::i18n::needs::t(lang, crate::i18n::needs::K::NeedsYou), | ||
| 930 | + ), | ||
| 921 | item("new", "/new", t(lang, Key::NewRepository)), | 931 | item("new", "/new", t(lang, Key::NewRepository)), |
| 922 | item("import", "/new/import", mg::t(lang, MGK::ImportTitle)), | 932 | item("import", "/new/import", mg::t(lang, MGK::ImportTitle)), |
| 923 | ]; | 933 | ]; |
crates/forge-web/src/views/repo_list.rsmodified+1 -1
| @@ -52,7 +52,7 @@ pub async fn repo_rows(rows: Vec<RepoRow>, lang: Lang) -> Result<impl View> { | |||
| 52 | Ok(view! { | 52 | Ok(view! { |
| 53 | <ul class="repo-list"> | 53 | <ul class="repo-list"> |
| 54 | for row in rows.into_iter() { | 54 | for row in rows.into_iter() { |
| 55 | - <li class="repo-item"> | 55 | + <li class="repo-item" data-kb-row=""> |
| 56 | <div class="repo-item-head"> | 56 | <div class="repo-item-head"> |
| 57 | <a class="repo-name" href=(row.href.as_str())>(row.title.as_str())</a> | 57 | <a class="repo-name" href=(row.href.as_str())>(row.title.as_str())</a> |
| 58 | <span class=(badge_class(row.visibility))>(i18n::visibility_label(lang, row.visibility))</span> | 58 | <span class=(badge_class(row.visibility))>(i18n::visibility_label(lang, row.visibility))</span> |
style/_ci_estimate.scssadded+40 -0
| @@ -0,0 +1,40 @@ | |||
| 1 | +// The time-left bar of a running CI run: the elapsed share of its expected total. It fills with the | ||
| 2 | +// heat colour, the same as the repo home's CI bar, and stays full once the run is past its estimate. | ||
| 3 | + | ||
| 4 | +progress.ci-est { | ||
| 5 | + -webkit-appearance: none; | ||
| 6 | + appearance: none; | ||
| 7 | + flex: 0 0 96px; | ||
| 8 | + box-sizing: border-box; | ||
| 9 | + width: 96px; | ||
| 10 | + height: 4px; | ||
| 11 | + margin: 0; | ||
| 12 | + border: 0; | ||
| 13 | + border-radius: 2px; | ||
| 14 | + overflow: hidden; | ||
| 15 | + background: var(--border); | ||
| 16 | + color: var(--heat-3); | ||
| 17 | + | ||
| 18 | + &::-webkit-progress-bar { | ||
| 19 | + background: var(--border); | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + &::-webkit-progress-value { | ||
| 23 | + border-radius: 2px; | ||
| 24 | + background: linear-gradient(90deg, var(--heat-2), var(--heat-3), var(--heat-4)); | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + &::-moz-progress-bar { | ||
| 28 | + border-radius: 2px; | ||
| 29 | + background: linear-gradient(90deg, var(--heat-2), var(--heat-3), var(--heat-4)); | ||
| 30 | + } | ||
| 31 | +} | ||
| 32 | + | ||
| 33 | +progress.ci-est-run { | ||
| 34 | + display: block; | ||
| 35 | + flex: none; | ||
| 36 | + width: 100%; | ||
| 37 | + max-width: 320px; | ||
| 38 | + height: 4px; | ||
| 39 | + margin-top: 8px; | ||
| 40 | +} | ||
style/_commit_line.scssadded+39 -0
| @@ -0,0 +1,39 @@ | |||
| 1 | +// One-line commit subjects (views/commit_line.rs). The tag and the count are neutral; the text | ||
| 2 | +// truncates with an ellipsis and the full subject is the element's title. | ||
| 3 | + | ||
| 4 | +.commit-line { | ||
| 5 | + display: flex; | ||
| 6 | + align-items: baseline; | ||
| 7 | + gap: 6px; | ||
| 8 | + min-width: 0; | ||
| 9 | + max-width: 100%; | ||
| 10 | +} | ||
| 11 | + | ||
| 12 | +.commit-line-kind { | ||
| 13 | + flex: none; | ||
| 14 | + font-family: var(--mono); | ||
| 15 | + font-size: 12px; | ||
| 16 | + color: var(--muted); | ||
| 17 | +} | ||
| 18 | + | ||
| 19 | +.commit-line-text { | ||
| 20 | + min-width: 0; | ||
| 21 | + overflow: hidden; | ||
| 22 | + text-overflow: ellipsis; | ||
| 23 | + white-space: nowrap; | ||
| 24 | +} | ||
| 25 | + | ||
| 26 | +.commit-line-extra { | ||
| 27 | + flex: none; | ||
| 28 | + font-size: 12px; | ||
| 29 | + color: var(--muted); | ||
| 30 | +} | ||
| 31 | + | ||
| 32 | +.ci-run-message { | ||
| 33 | + margin: 4px 0 8px; | ||
| 34 | + | ||
| 35 | + p { | ||
| 36 | + margin: 4px 0 0; | ||
| 37 | + overflow-wrap: anywhere; | ||
| 38 | + } | ||
| 39 | +} | ||
style/_commit_page.scssadded+62 -0
| @@ -0,0 +1,62 @@ | |||
| 1 | +// Commit page: a typed subject's groups as a compact list under the commit card. The list caps | ||
| 2 | +// its own height and scrolls, so the diff below keeps its place on one screen. | ||
| 3 | + | ||
| 4 | +// The commit card flows its rows (oid, checks, author, committer, parent, browse) side by side and | ||
| 5 | +// wraps, so the header is as short as its content allows and the diff pane gets the rest. | ||
| 6 | +.commit-info { | ||
| 7 | + flex-direction: row; | ||
| 8 | + flex-wrap: wrap; | ||
| 9 | + align-items: center; | ||
| 10 | + gap: 4px 16px; | ||
| 11 | + | ||
| 12 | + > .commit-full-oid { | ||
| 13 | + margin: 0; | ||
| 14 | + } | ||
| 15 | +} | ||
| 16 | + | ||
| 17 | +.commit-groups { | ||
| 18 | + list-style: none; | ||
| 19 | + margin: 8px 0 0; | ||
| 20 | + padding: 0; | ||
| 21 | + max-height: min(30dvh, 9rem); | ||
| 22 | + overflow: auto; | ||
| 23 | + border-top: 1px solid var(--border); | ||
| 24 | +} | ||
| 25 | + | ||
| 26 | +.commit-group { | ||
| 27 | + display: grid; | ||
| 28 | + grid-template-columns: 64px minmax(0, 1fr); | ||
| 29 | + column-gap: 12px; | ||
| 30 | + padding: 5px 0; | ||
| 31 | + border-bottom: 1px solid var(--border); | ||
| 32 | +} | ||
| 33 | + | ||
| 34 | +.commit-kind { | ||
| 35 | + color: var(--muted); | ||
| 36 | + font-size: 13px; | ||
| 37 | + line-height: 1.4; | ||
| 38 | +} | ||
| 39 | + | ||
| 40 | +.commit-clauses { | ||
| 41 | + list-style: none; | ||
| 42 | + margin: 0; | ||
| 43 | + padding: 0; | ||
| 44 | + min-width: 0; | ||
| 45 | + | ||
| 46 | + > li { | ||
| 47 | + font-size: 13px; | ||
| 48 | + line-height: 1.4; | ||
| 49 | + padding: 1px 0; | ||
| 50 | + overflow-wrap: anywhere; | ||
| 51 | + } | ||
| 52 | +} | ||
| 53 | + | ||
| 54 | +.commit-full-message { | ||
| 55 | + margin-top: 8px; | ||
| 56 | + | ||
| 57 | + > summary { | ||
| 58 | + cursor: pointer; | ||
| 59 | + color: var(--muted); | ||
| 60 | + font-size: 13px; | ||
| 61 | + } | ||
| 62 | +} | ||
style/_density.scssadded+176 -0
| @@ -0,0 +1,176 @@ | |||
| 1 | +// Row density: Comfortable (the default) or Compact. The shell puts `data-density="compact"` on | ||
| 2 | +// <html> from the viewer's account (signed-out visitors: nav.js reads localStorage). Comfortable | ||
| 3 | +// keeps every element's own padding. Compact sets four tokens, and the shared list, table and | ||
| 4 | +// pane classes read them, so no page repeats the numbers. | ||
| 5 | + | ||
| 6 | +:root[data-density="compact"] { | ||
| 7 | + --row-pad-y: 6px; // top and bottom padding of a list row | ||
| 8 | + --cell-pad-y: 5px; // top and bottom padding of a table cell | ||
| 9 | + --head-pad-y: 4px; // top and bottom padding of a table heading | ||
| 10 | + --pane-pad: 12px; // padding of a card or a one-screen pane | ||
| 11 | +} | ||
| 12 | + | ||
| 13 | +:root[data-density="compact"] { | ||
| 14 | + .item, | ||
| 15 | + .repo-item, | ||
| 16 | + .notif-row, | ||
| 17 | + .ci-row, | ||
| 18 | + .runner-row, | ||
| 19 | + .security-row { | ||
| 20 | + padding-top: var(--row-pad-y); | ||
| 21 | + padding-bottom: var(--row-pad-y); | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + .table th, | ||
| 25 | + .table td { | ||
| 26 | + padding-top: var(--cell-pad-y); | ||
| 27 | + padding-bottom: var(--cell-pad-y); | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + .table th { | ||
| 31 | + padding-top: var(--head-pad-y); | ||
| 32 | + padding-bottom: var(--head-pad-y); | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + .card, | ||
| 36 | + .fit-pane { | ||
| 37 | + padding: var(--pane-pad); | ||
| 38 | + } | ||
| 39 | +} | ||
| 40 | + | ||
| 41 | +// Appearance page layout. Below 1100px the parts stack: general controls, then the sound card, then | ||
| 42 | +// the colours. From 1100px: general controls and the sound card on the left, colours on the right, | ||
| 43 | +// so the page fits one screen. The form is `display: contents` so its two blocks join this grid. | ||
| 44 | +// The sound card sits outside the form: its Play buttons must not be inside it. | ||
| 45 | +.appearance-page { | ||
| 46 | + display: flex; | ||
| 47 | + flex-direction: column; | ||
| 48 | + gap: 16px; | ||
| 49 | + min-width: 0; | ||
| 50 | + | ||
| 51 | + > form.appearance { | ||
| 52 | + display: contents; | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + .appearance-top { | ||
| 56 | + order: 1; | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + .sound-card { | ||
| 60 | + order: 2; | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + .colour-group { | ||
| 64 | + order: 3; | ||
| 65 | + } | ||
| 66 | +} | ||
| 67 | + | ||
| 68 | +@media (min-width: 1100px) { | ||
| 69 | + .appearance-page { | ||
| 70 | + display: grid; | ||
| 71 | + grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); | ||
| 72 | + align-items: start; | ||
| 73 | + gap: 16px 24px; | ||
| 74 | + | ||
| 75 | + .appearance-top { | ||
| 76 | + grid-column: 1; | ||
| 77 | + grid-row: 1; | ||
| 78 | + grid-template-columns: repeat(2, minmax(0, 1fr)); | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + .sound-card { | ||
| 82 | + grid-column: 1; | ||
| 83 | + grid-row: 2; | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + .colour-group { | ||
| 87 | + grid-column: 2; | ||
| 88 | + grid-row: 1 / span 2; | ||
| 89 | + } | ||
| 90 | + } | ||
| 91 | +} | ||
| 92 | + | ||
| 93 | +// Settings: the sound card. The density radios use the sidebar side's segmented pill. | ||
| 94 | +.sound-card { | ||
| 95 | + display: grid; | ||
| 96 | + gap: 8px; | ||
| 97 | + | ||
| 98 | + > p { | ||
| 99 | + margin: 0; | ||
| 100 | + } | ||
| 101 | +} | ||
| 102 | + | ||
| 103 | +// A sound-row's name and its quiet note sit on one line, with a gap rather than a typed space. | ||
| 104 | +.sound-name { | ||
| 105 | + display: flex; | ||
| 106 | + flex-wrap: wrap; | ||
| 107 | + gap: 6px; | ||
| 108 | +} | ||
| 109 | + | ||
| 110 | +.sound-toggle .sound-row { | ||
| 111 | + height: var(--control-h); | ||
| 112 | + min-height: 0; | ||
| 113 | +} | ||
| 114 | + | ||
| 115 | +.sound-row { | ||
| 116 | + display: flex; | ||
| 117 | + align-items: center; | ||
| 118 | + justify-content: space-between; | ||
| 119 | + gap: 16px; | ||
| 120 | + min-height: 36px; | ||
| 121 | +} | ||
| 122 | + | ||
| 123 | +// The switch is a checkbox, visually hidden, with its track and knob drawn beside it. | ||
| 124 | +.sound-switch { | ||
| 125 | + position: relative; | ||
| 126 | + flex: none; | ||
| 127 | + display: block; | ||
| 128 | + width: 36px; | ||
| 129 | + height: 20px; | ||
| 130 | + | ||
| 131 | + input[type="checkbox"] { | ||
| 132 | + position: absolute; | ||
| 133 | + width: 1px; | ||
| 134 | + height: 1px; | ||
| 135 | + margin: 0; | ||
| 136 | + opacity: 0; | ||
| 137 | + } | ||
| 138 | +} | ||
| 139 | + | ||
| 140 | +.sound-track { | ||
| 141 | + position: absolute; | ||
| 142 | + inset: 0; | ||
| 143 | + border-radius: 10px; | ||
| 144 | + background: var(--border); | ||
| 145 | + cursor: pointer; | ||
| 146 | +} | ||
| 147 | + | ||
| 148 | +.sound-switch input:checked + .sound-track { | ||
| 149 | + background: var(--accent); | ||
| 150 | +} | ||
| 151 | + | ||
| 152 | +.sound-knob { | ||
| 153 | + position: absolute; | ||
| 154 | + top: 2px; | ||
| 155 | + left: 2px; | ||
| 156 | + width: 16px; | ||
| 157 | + height: 16px; | ||
| 158 | + border-radius: 50%; | ||
| 159 | + background: var(--surface); | ||
| 160 | + transition: transform 0.15s ease; | ||
| 161 | +} | ||
| 162 | + | ||
| 163 | +.sound-switch input:checked + .sound-track > .sound-knob { | ||
| 164 | + transform: translateX(16px); | ||
| 165 | +} | ||
| 166 | + | ||
| 167 | +.sound-switch input:focus-visible + .sound-track { | ||
| 168 | + outline: 2px solid var(--accent); | ||
| 169 | + outline-offset: 2px; | ||
| 170 | +} | ||
| 171 | + | ||
| 172 | +@media (prefers-reduced-motion: reduce) { | ||
| 173 | + .sound-knob { | ||
| 174 | + transition: none; | ||
| 175 | + } | ||
| 176 | +} | ||
style/_fail_first.scssadded+77 -0
| @@ -0,0 +1,77 @@ | |||
| 1 | +// The failure block at the top of a failed run's page (pages/ci_fail.rs). Failure red is fixed; the | ||
| 2 | +// block uses the page's own tokens and stays neutral apart from the first error line. | ||
| 3 | + | ||
| 4 | +.fail-first { | ||
| 5 | + display: flex; | ||
| 6 | + flex-direction: column; | ||
| 7 | + gap: 6px; | ||
| 8 | + margin: 12px 0; | ||
| 9 | + padding: 12px 14px; | ||
| 10 | + border-radius: var(--radius-md); | ||
| 11 | + background: var(--surface); | ||
| 12 | + border-left: 3px solid var(--bad); | ||
| 13 | +} | ||
| 14 | + | ||
| 15 | +.fail-first-head { | ||
| 16 | + margin: 0; | ||
| 17 | + font-weight: 600; | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +.fail-first-tag { | ||
| 21 | + color: var(--bad); | ||
| 22 | + margin-right: 4px; | ||
| 23 | +} | ||
| 24 | + | ||
| 25 | +.fail-first-msg { | ||
| 26 | + margin: 0; | ||
| 27 | + font-family: var(--mono); | ||
| 28 | + font-size: 0.85rem; | ||
| 29 | + color: var(--bad); | ||
| 30 | + white-space: pre-wrap; | ||
| 31 | + word-break: break-word; | ||
| 32 | +} | ||
| 33 | + | ||
| 34 | +.fail-first-log { | ||
| 35 | + max-height: 22rem; | ||
| 36 | + overflow: auto; | ||
| 37 | + margin-top: 4px; | ||
| 38 | + border-radius: var(--radius-md); | ||
| 39 | + background: var(--bg); | ||
| 40 | + font-family: var(--mono); | ||
| 41 | + font-size: 0.8rem; | ||
| 42 | + line-height: 1.5; | ||
| 43 | +} | ||
| 44 | + | ||
| 45 | +.fail-first-ln { | ||
| 46 | + display: grid; | ||
| 47 | + grid-template-columns: 4.5em 1fr; | ||
| 48 | + white-space: pre; | ||
| 49 | + overflow-x: auto; | ||
| 50 | + | ||
| 51 | + > i { | ||
| 52 | + font-style: normal; | ||
| 53 | + text-align: right; | ||
| 54 | + padding-right: 1em; | ||
| 55 | + opacity: 0.6; | ||
| 56 | + user-select: none; | ||
| 57 | + } | ||
| 58 | +} | ||
| 59 | + | ||
| 60 | +.fail-first-hit { | ||
| 61 | + background: color-mix(in srgb, var(--bad) 16%, transparent); | ||
| 62 | +} | ||
| 63 | + | ||
| 64 | +@media (prefers-reduced-motion: no-preference) { | ||
| 65 | + .fail-first { | ||
| 66 | + animation: fail-first-in 180ms ease-out both; | ||
| 67 | + } | ||
| 68 | +} | ||
| 69 | + | ||
| 70 | +@keyframes fail-first-in { | ||
| 71 | + from { | ||
| 72 | + opacity: 0; | ||
| 73 | + } | ||
| 74 | + to { | ||
| 75 | + opacity: 1; | ||
| 76 | + } | ||
| 77 | +} | ||
style/_keyboard.scssadded+47 -0
| @@ -0,0 +1,47 @@ | |||
| 1 | +// Keyboard rows: the row j and k select (a raised surface and an accent bar on its left edge), and | ||
| 2 | +// the keys dialog that ? opens. Both are set by nav.js; the dialog reads its strings from nav.js too. | ||
| 3 | + | ||
| 4 | +[data-kb-row].kb-sel { | ||
| 5 | + background: var(--surface-2); | ||
| 6 | + box-shadow: inset 2px 0 0 var(--accent); | ||
| 7 | +} | ||
| 8 | + | ||
| 9 | +dialog.kb-help { | ||
| 10 | + width: min(340px, calc(100vw - 32px)); | ||
| 11 | + padding: 18px 20px; | ||
| 12 | + color: var(--text); | ||
| 13 | + background: var(--surface); | ||
| 14 | + border: 1px solid var(--border-strong); | ||
| 15 | + border-radius: var(--radius-lg); | ||
| 16 | + box-shadow: var(--shadow); | ||
| 17 | + | ||
| 18 | + &::backdrop { | ||
| 19 | + background: rgba(20, 24, 22, 0.45); | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + h2 { | ||
| 23 | + margin: 0 0 12px; | ||
| 24 | + font-size: 15px; | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + dl { | ||
| 28 | + display: grid; | ||
| 29 | + grid-template-columns: auto 1fr; | ||
| 30 | + gap: 8px 16px; | ||
| 31 | + margin: 0 0 16px; | ||
| 32 | + font-size: 13px; | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + dt { | ||
| 36 | + align-self: center; | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + dd { | ||
| 40 | + margin: 0; | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + form { | ||
| 44 | + display: flex; | ||
| 45 | + justify-content: flex-end; | ||
| 46 | + } | ||
| 47 | +} | ||
style/_live_motion.scssadded+35 -0
| @@ -0,0 +1,35 @@ | |||
| 1 | +// Live motion: a running job's bar grows and a new log chunk fades in, calmly, when the server sends | ||
| 2 | +// a change. Both run only on a live swap or a log chunk, never on first render. Reduced motion holds | ||
| 3 | +// everything still; the scripts also skip setting these up under reduced motion. | ||
| 4 | + | ||
| 5 | +// A list bar's segment that the live swap carries from its old width to the server's width. nav.js | ||
| 6 | +// adds the class, sets the old width inline, then the new one, and removes both once it has run. | ||
| 7 | +.ci-seg.live-grow { | ||
| 8 | + transition: width 600ms ease-out; | ||
| 9 | +} | ||
| 10 | + | ||
| 11 | +// A chunk of streamed log lines: the lines it added fade in and rise a little. nav.js wraps them in | ||
| 12 | +// `.ll-chunk` and unwraps the wrapper after the animation, so the log keeps its flat line structure. | ||
| 13 | +.ll-chunk { | ||
| 14 | + animation: ll-chunk-in 180ms ease-out; | ||
| 15 | +} | ||
| 16 | + | ||
| 17 | +@keyframes ll-chunk-in { | ||
| 18 | + from { | ||
| 19 | + opacity: 0; | ||
| 20 | + transform: translateY(4px); | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + to { | ||
| 24 | + opacity: 1; | ||
| 25 | + transform: none; | ||
| 26 | + } | ||
| 27 | +} | ||
| 28 | + | ||
| 29 | +@media (prefers-reduced-motion: reduce) { | ||
| 30 | + .ci-seg.live-grow, | ||
| 31 | + .ll-chunk { | ||
| 32 | + transition: none; | ||
| 33 | + animation: none; | ||
| 34 | + } | ||
| 35 | +} | ||
style/_needs.scssadded+48 -0
| @@ -0,0 +1,48 @@ | |||
| 1 | +// The /needs-you page: sections in two columns on wide windows, each a card with a mono head and | ||
| 2 | +// the notification list rows. Colours and fonts come from the repo's tokens. | ||
| 3 | + | ||
| 4 | +.needs-grid { | ||
| 5 | + display: grid; | ||
| 6 | + gap: 12px; | ||
| 7 | + align-items: start; | ||
| 8 | +} | ||
| 9 | + | ||
| 10 | +.needs-section { | ||
| 11 | + margin-bottom: 0; | ||
| 12 | + padding: 0; | ||
| 13 | + overflow: hidden; | ||
| 14 | +} | ||
| 15 | + | ||
| 16 | +.needs-head { | ||
| 17 | + margin: 0; | ||
| 18 | + padding: 10px 14px; | ||
| 19 | + border-bottom: 1px solid var(--border); | ||
| 20 | + font-family: var(--mono); | ||
| 21 | + font-size: 12px; | ||
| 22 | + font-weight: 500; | ||
| 23 | + letter-spacing: 0.04em; | ||
| 24 | + text-transform: uppercase; | ||
| 25 | + color: var(--muted); | ||
| 26 | +} | ||
| 27 | + | ||
| 28 | +.needs-section .notif-row { | ||
| 29 | + padding: 0.5rem 0.9rem; | ||
| 30 | +} | ||
| 31 | + | ||
| 32 | +.needs-more { | ||
| 33 | + display: block; | ||
| 34 | + padding: 8px 14px; | ||
| 35 | + color: var(--muted); | ||
| 36 | + text-decoration: none; | ||
| 37 | + | ||
| 38 | + &:hover { | ||
| 39 | + color: var(--text); | ||
| 40 | + text-decoration: underline; | ||
| 41 | + } | ||
| 42 | +} | ||
| 43 | + | ||
| 44 | +@media (min-width: 900px) { | ||
| 45 | + .needs-grid { | ||
| 46 | + grid-template-columns: repeat(2, minmax(0, 1fr)); | ||
| 47 | + } | ||
| 48 | +} | ||
style/_palette.scssmodified+9 -0
| @@ -125,6 +125,15 @@ dialog.palette { | |||
| 125 | margin: 0; | 125 | margin: 0; |
| 126 | padding: 8px 12px; | 126 | padding: 8px 12px; |
| 127 | border-top: 1px solid var(--border); | 127 | border-top: 1px solid var(--border); |
| 128 | + | ||
| 129 | + // A sent action: done in the ok colour, a refusal in the failure colour. | ||
| 130 | + &.is-ok { | ||
| 131 | + color: var(--ok); | ||
| 132 | + } | ||
| 133 | + | ||
| 134 | + &.is-bad { | ||
| 135 | + color: var(--bad); | ||
| 136 | + } | ||
| 128 | } | 137 | } |
| 129 | 138 | ||
| 130 | // Phones: the palette spans the screen width and sits at the top, with larger rows to tap. | 139 | // Phones: the palette spans the screen width and sits at the top, with larger rows to tap. |
style/_pull.scssmodified+2 -2
| @@ -407,7 +407,7 @@ | |||
| 407 | } | 407 | } |
| 408 | 408 | ||
| 409 | &.status-pending > .status-icon { | 409 | &.status-pending > .status-icon { |
| 410 | - color: var(--warn); | 410 | + color: var(--heat-3); |
| 411 | } | 411 | } |
| 412 | } | 412 | } |
| 413 | 413 | ||
| @@ -421,7 +421,7 @@ | |||
| 421 | } | 421 | } |
| 422 | 422 | ||
| 423 | &.status-pending { | 423 | &.status-pending { |
| 424 | - color: var(--warn); | 424 | + color: var(--heat-3); |
| 425 | } | 425 | } |
| 426 | } | 426 | } |
| 427 | 427 | ||
style/_review_flow.scssadded+130 -0
| @@ -0,0 +1,130 @@ | |||
| 1 | +// The Viewed panel on a pull request's Files tab, and the collapse of viewed files. Neutral | ||
| 2 | +// throughout: the bar fills in the muted tone and never takes the accent. | ||
| 3 | + | ||
| 4 | +.viewed-panel { | ||
| 5 | + display: flex; | ||
| 6 | + flex-direction: column; | ||
| 7 | + gap: 10px; | ||
| 8 | + min-width: 0; | ||
| 9 | + margin-bottom: 14px; | ||
| 10 | + padding: 14px 16px; | ||
| 11 | +} | ||
| 12 | + | ||
| 13 | +.viewed-head { | ||
| 14 | + display: flex; | ||
| 15 | + align-items: baseline; | ||
| 16 | + justify-content: space-between; | ||
| 17 | + gap: 12px; | ||
| 18 | + | ||
| 19 | + h2 { | ||
| 20 | + margin: 0; | ||
| 21 | + font-size: 15px; | ||
| 22 | + } | ||
| 23 | +} | ||
| 24 | + | ||
| 25 | +.viewed-count { | ||
| 26 | + font-family: var(--mono); | ||
| 27 | + font-size: 12px; | ||
| 28 | + color: var(--muted); | ||
| 29 | + white-space: nowrap; | ||
| 30 | +} | ||
| 31 | + | ||
| 32 | +.viewed-bar { | ||
| 33 | + height: 4px; | ||
| 34 | + overflow: hidden; | ||
| 35 | + border-radius: var(--radius-full); | ||
| 36 | + background: var(--surface-2); | ||
| 37 | + | ||
| 38 | + b { | ||
| 39 | + display: block; | ||
| 40 | + height: 100%; | ||
| 41 | + background: var(--muted); | ||
| 42 | + transition: width 0.2s ease; | ||
| 43 | + } | ||
| 44 | +} | ||
| 45 | + | ||
| 46 | +.viewed-hint { | ||
| 47 | + margin: 0; | ||
| 48 | + font-size: 12.5px; | ||
| 49 | +} | ||
| 50 | + | ||
| 51 | +// A long list scrolls inside its own pane, so the page itself still fits one screen. | ||
| 52 | +.viewed-list { | ||
| 53 | + max-height: 220px; | ||
| 54 | + margin: 0; | ||
| 55 | + padding: 0; | ||
| 56 | + overflow-y: auto; | ||
| 57 | + list-style: none; | ||
| 58 | + | ||
| 59 | + li { | ||
| 60 | + display: flex; | ||
| 61 | + align-items: center; | ||
| 62 | + gap: 10px; | ||
| 63 | + min-width: 0; | ||
| 64 | + min-height: 30px; | ||
| 65 | + box-shadow: inset 0 -1px var(--border-strong); | ||
| 66 | + | ||
| 67 | + &.is-focus { | ||
| 68 | + background: var(--surface-2); | ||
| 69 | + } | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + li[data-state="viewed"] .viewed-path { | ||
| 73 | + color: var(--muted); | ||
| 74 | + } | ||
| 75 | +} | ||
| 76 | + | ||
| 77 | +.viewed-item { | ||
| 78 | + display: flex; | ||
| 79 | + flex: 1; | ||
| 80 | + align-items: center; | ||
| 81 | + gap: 10px; | ||
| 82 | + min-width: 0; | ||
| 83 | + cursor: pointer; | ||
| 84 | + | ||
| 85 | + input[type="checkbox"] { | ||
| 86 | + flex: none; | ||
| 87 | + margin: 0; | ||
| 88 | + accent-color: var(--text); | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + input[type="checkbox"]:disabled { | ||
| 92 | + cursor: progress; | ||
| 93 | + } | ||
| 94 | +} | ||
| 95 | + | ||
| 96 | +.viewed-path { | ||
| 97 | + min-width: 0; | ||
| 98 | + overflow: hidden; | ||
| 99 | + font-family: var(--mono); | ||
| 100 | + font-size: 12.5px; | ||
| 101 | + text-overflow: ellipsis; | ||
| 102 | + white-space: nowrap; | ||
| 103 | +} | ||
| 104 | + | ||
| 105 | +.viewed-note { | ||
| 106 | + flex: none; | ||
| 107 | + font-size: 12px; | ||
| 108 | + font-weight: 600; | ||
| 109 | + color: var(--text); | ||
| 110 | + white-space: nowrap; | ||
| 111 | +} | ||
| 112 | + | ||
| 113 | +// A viewed file keeps its heading and drops its diff until the reader opens it again by | ||
| 114 | +// unmarking it. nav.js sets is-viewed on the section once the page has loaded. | ||
| 115 | +.diff-file.is-viewed { | ||
| 116 | + > .diff-file-body, | ||
| 117 | + > .diff-collapsed { | ||
| 118 | + display: none; | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + > .diff-file-header { | ||
| 122 | + opacity: 0.6; | ||
| 123 | + } | ||
| 124 | +} | ||
| 125 | + | ||
| 126 | +@media (prefers-reduced-motion: reduce) { | ||
| 127 | + .viewed-bar b { | ||
| 128 | + transition: none; | ||
| 129 | + } | ||
| 130 | +} | ||
style/main.scssmodified+20 -6
| @@ -4376,7 +4376,7 @@ span.reaction { | |||
| 4376 | } | 4376 | } |
| 4377 | 4377 | ||
| 4378 | &.status-pending { | 4378 | &.status-pending { |
| 4379 | - color: var(--warning); | 4379 | + color: var(--heat-3); |
| 4380 | } | 4380 | } |
| 4381 | } | 4381 | } |
| 4382 | 4382 | ||
| @@ -4446,7 +4446,7 @@ span.reaction { | |||
| 4446 | } | 4446 | } |
| 4447 | 4447 | ||
| 4448 | &.status-pending > .status-icon { | 4448 | &.status-pending > .status-icon { |
| 4449 | - color: var(--warning); | 4449 | + color: var(--heat-3); |
| 4450 | } | 4450 | } |
| 4451 | 4451 | ||
| 4452 | .checks-details { | 4452 | .checks-details { |
| @@ -4899,13 +4899,18 @@ span.reaction { | |||
| 4899 | } | 4899 | } |
| 4900 | 4900 | ||
| 4901 | &.ci-queued, | 4901 | &.ci-queued, |
| 4902 | - &.ci-running, | ||
| 4903 | &.ci-blocked, | 4902 | &.ci-blocked, |
| 4904 | &.ci-waiting_approval { | 4903 | &.ci-waiting_approval { |
| 4905 | background: var(--private-bg); | 4904 | background: var(--private-bg); |
| 4906 | color: var(--warning); | 4905 | color: var(--warning); |
| 4907 | } | 4906 | } |
| 4908 | 4907 | ||
| 4908 | + // A running state takes the accent through the heat tokens, like the running repo chip. | ||
| 4909 | + &.ci-running { | ||
| 4910 | + background: color-mix(in srgb, var(--heat-3) 14%, transparent); | ||
| 4911 | + color: var(--heat-3); | ||
| 4912 | + } | ||
| 4913 | + | ||
| 4909 | &.ci-failure, | 4914 | &.ci-failure, |
| 4910 | &.ci-error { | 4915 | &.ci-error { |
| 4911 | background: var(--danger-bg); | 4916 | background: var(--danger-bg); |
| @@ -5960,7 +5965,7 @@ html.js form.runner-load[data-dirty-form][data-dirty] .runner-save { | |||
| 5960 | } | 5965 | } |
| 5961 | 5966 | ||
| 5962 | &.ci-run { | 5967 | &.ci-run { |
| 5963 | - fill: var(--warn); | 5968 | + fill: var(--heat-3); |
| 5964 | } | 5969 | } |
| 5965 | 5970 | ||
| 5966 | &.ci-muted { | 5971 | &.ci-muted { |
| @@ -6075,7 +6080,7 @@ html.js form.runner-load[data-dirty-form][data-dirty] .runner-save { | |||
| 6075 | } | 6080 | } |
| 6076 | 6081 | ||
| 6077 | &.ci-run { | 6082 | &.ci-run { |
| 6078 | - fill: var(--warn); | 6083 | + fill: var(--heat-3); |
| 6079 | } | 6084 | } |
| 6080 | 6085 | ||
| 6081 | &.ci-muted { | 6086 | &.ci-muted { |
| @@ -6306,7 +6311,7 @@ button.ci-stopping { | |||
| 6306 | } | 6311 | } |
| 6307 | 6312 | ||
| 6308 | &.ci-running { | 6313 | &.ci-running { |
| 6309 | - color: var(--warn); | 6314 | + color: var(--heat-3); |
| 6310 | } | 6315 | } |
| 6311 | } | 6316 | } |
| 6312 | 6317 | ||
| @@ -7926,11 +7931,14 @@ button.ci-job-last { | |||
| 7926 | @import "hooks"; | 7931 | @import "hooks"; |
| 7927 | @import "admin_rows"; | 7932 | @import "admin_rows"; |
| 7928 | @import "motion"; | 7933 | @import "motion"; |
| 7934 | +@import "live_motion"; | ||
| 7929 | @import "empty"; | 7935 | @import "empty"; |
| 7936 | +@import "needs"; | ||
| 7930 | @import "feedback"; | 7937 | @import "feedback"; |
| 7931 | @import "drafts"; | 7938 | @import "drafts"; |
| 7932 | @import "palette"; | 7939 | @import "palette"; |
| 7933 | @import "select_search"; | 7940 | @import "select_search"; |
| 7941 | +@import "fail_first"; | ||
| 7934 | 7942 | ||
| 7935 | // A monospace value with its Copy button on the right; long values wrap inside the box. | 7943 | // A monospace value with its Copy button on the right; long values wrap inside the box. |
| 7936 | .copy-box { | 7944 | .copy-box { |
| @@ -8011,3 +8019,9 @@ button.ci-job-last { | |||
| 8011 | } | 8019 | } |
| 8012 | } | 8020 | } |
| 8013 | @import "repo_side"; | 8021 | @import "repo_side"; |
| 8022 | +@import "ci_estimate"; | ||
| 8023 | +@import "density"; | ||
| 8024 | +@import "keyboard"; | ||
| 8025 | +@import "review_flow"; | ||
| 8026 | +@import "commit_page"; | ||
| 8027 | +@import "commit_line"; | ||