From 3d53dfd79c35bd64433757f7d43e1e649f438e7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 27 Oct 2026 18:22:35 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20a=20day's=20contributions?= =?UTF-8?q?=20group=20pushes=20to=20one=20branch=20into=20a=20row=20that?= =?UTF-8?q?=20opens=20to=20list=20them?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/forge-web/src/i18n/misc.rs | 15 +++ crates/forge-web/src/views/heatmap.rs | 140 ++++++++++++++++++++++---- style/_heatmap.scss | 42 ++++++++ 3 files changed, 177 insertions(+), 20 deletions(-) diff --git a/crates/forge-web/src/i18n/misc.rs b/crates/forge-web/src/i18n/misc.rs index 414c720..6addd83 100644 --- a/crates/forge-web/src/i18n/misc.rs +++ b/crates/forge-web/src/i18n/misc.rs @@ -765,6 +765,21 @@ pub fn day_item_words( } } +/// The words either side of a grouped row for `count` pushes to one branch, e.g. `Pushed 7 times to +/// main in` with the repo as the link. The link is the repo, as for a single push. +pub fn push_group_words(lang: Lang, branch: &str, count: usize) -> (String, String) { + match lang { + Lang::En => ( + format!("Pushed {count} times to {branch} in"), + String::new(), + ), + Lang::Tr => ( + String::new(), + format!("deposunda {branch} dalına {count} gönderim"), + ), + } +} + /// The activity line for an inbox row: the verb, then the actor when there is one. English reads /// "opened by tahinli"; Turkish reads "tahinli tarafından açıldı", or "Açıldı" with no actor. pub fn activity_line(lang: Lang, verb: K, actor: Option<&str>) -> String { diff --git a/crates/forge-web/src/views/heatmap.rs b/crates/forge-web/src/views/heatmap.rs index 099ee93..82f9d96 100644 --- a/crates/forge-web/src/views/heatmap.rs +++ b/crates/forge-web/src/views/heatmap.rs @@ -194,10 +194,18 @@ struct DayRow { relative: String, } -/// The selected day's heading and rows, ready for the view. +/// One entry in the selected day's list: a single contribution, or a group of pushes to one branch +/// of one repo. `row` is the entry's own line (for a group, its newest push, with the count), and +/// `pushes` lists the group's pushes, newest first; it is empty for a single contribution. +struct DayEntry { + row: DayRow, + pushes: Vec, +} + +/// The selected day's heading and entries, ready for the view. struct DayView { heading: String, - rows: Vec, + rows: Vec, } /// The link for a calendar day: the day's contributions below the calendar, or back to the @@ -213,14 +221,22 @@ fn day_href(date: (i64, i64, i64), selected: bool) -> String { } } +/// The repo an item landed in, as `owner/name`. +fn item_repo(item: &ContributionItem) -> String { + format!("{}/{}", item.repo_owner, item.repo_name) +} + +/// The branch a push went to: its ref without `refs/heads/`. Empty for everything else. +fn item_branch(item: &ContributionItem) -> &str { + item.ref_name + .strip_prefix("refs/heads/") + .unwrap_or(&item.ref_name) +} + /// The row for one contribution in the selected day's list. fn day_row(lang: Lang, item: &ContributionItem, now: i64) -> DayRow { - let repo = format!("{}/{}", item.repo_owner, item.repo_name); - let branch = item - .ref_name - .strip_prefix("refs/heads/") - .unwrap_or(&item.ref_name); - let (before, after) = g::day_item_words(lang, item.kind, branch, &repo); + let repo = item_repo(item); + let (before, after) = g::day_item_words(lang, item.kind, item_branch(item), &repo); let (href, link) = match item.kind { ContributionKind::Push => (format!("/{repo}"), repo.clone()), ContributionKind::Issue | ContributionKind::Comment => ( @@ -250,6 +266,43 @@ fn day_row(lang: Lang, item: &ContributionItem, now: i64) -> DayRow { } } +/// The selected day's entries, newest first. Pushes to one branch of one repo are grouped under the +/// newest of them; every other contribution is its own entry. The items come newest first, so the +/// first push met for a branch is its most recent one, and the entries keep that order. +fn day_entries(lang: Lang, items: &[ContributionItem], now: i64) -> Vec { + let mut groups: Vec> = Vec::new(); + let mut push_group: HashMap<(String, String), usize> = HashMap::new(); + for item in items { + if item.kind == ContributionKind::Push { + let key = (item_repo(item), item_branch(item).to_owned()); + if let Some(&index) = push_group.get(&key) { + groups[index].push(item); + continue; + } + push_group.insert(key, groups.len()); + } + groups.push(vec![item]); + } + groups + .into_iter() + .map(|group| { + let newest = group[0]; + if group.len() == 1 { + return DayEntry { + row: day_row(lang, newest, now), + pushes: Vec::new(), + }; + } + let mut row = day_row(lang, newest, now); + (row.before, row.after) = g::push_group_words(lang, item_branch(newest), group.len()); + DayEntry { + row, + pushes: group.iter().map(|item| day_row(lang, item, now)).collect(), + } + }) + .collect() +} + /// The contribution card: heading and date range, the four stats, the month labels and the /// 53-week grid, then the motivating line and the Less/More legend, then the selected day's /// contributions when a day is picked. @@ -293,11 +346,7 @@ pub async fn contribution_calendar( lang, &g::date_text(lang, detail.date.0, detail.date.1, detail.date.2), ), - rows: detail - .items - .iter() - .map(|item| day_row(lang, item, now)) - .collect(), + rows: day_entries(lang, &detail.items, now), }); // Month labels: one slot per column, empty where no label starts. @@ -411,13 +460,36 @@ pub async fn contribution_calendar(

(empty_day)

} else {
    - for row in day.rows.into_iter() { -
  • - (row.before.as_str()) - (row.link.as_str()) - (row.after.as_str()) - -
  • + for entry in day.rows.into_iter() { + if entry.pushes.is_empty() { +
  • + (entry.row.before.as_str()) + (entry.row.link.as_str()) + (entry.row.after.as_str()) + +
  • + } else { +
  • +
    + + (entry.row.before.as_str()) + (entry.row.link.as_str()) + (entry.row.after.as_str()) + + +
      + for push in entry.pushes.into_iter() { +
    • + (push.before.as_str()) + (push.link.as_str()) + (push.after.as_str()) + +
    • + } +
    +
    +
  • + } }
} @@ -596,6 +668,34 @@ mod tests { assert_eq!(civil_from_days(days_from_civil(2000, 2, 29)), (2000, 2, 29)); } + #[test] + fn pushes_to_one_branch_group_under_the_newest() { + let item = |kind, ref_name: &str, at: &str| ContributionItem { + kind, + repo_owner: "Tahinli".to_owned(), + repo_name: "forge".to_owned(), + created_at: at.to_owned(), + ref_name: ref_name.to_owned(), + number: 0, + title: String::new(), + commit: String::new(), + }; + let push = |branch: &str, at: &str| item(ContributionKind::Push, branch, at); + let items = [ + push("refs/heads/main", "2026-10-16T12:00:00Z"), + push("refs/heads/main", "2026-10-16T11:00:00Z"), + item(ContributionKind::Issue, "", "2026-10-16T10:30:00Z"), + push("refs/heads/dev", "2026-10-16T09:00:00Z"), + push("refs/heads/main", "2026-10-16T08:00:00Z"), + ]; + let entries = day_entries(Lang::En, &items, 0); + let shape: Vec = entries.iter().map(|e| e.pushes.len()).collect(); + assert_eq!(shape, [3, 0, 0]); + assert_eq!(entries[0].row.updated, "2026-10-16T12:00:00Z"); + assert_eq!(entries[0].row.before, "Pushed 3 times to main in"); + assert_eq!(entries[2].row.before, "Pushed to dev in"); + } + #[test] fn days_from_civil_inverts_civil_from_days() { for days in [-1, 0, 1, 10_957, 20_454, 47_000] { diff --git a/style/_heatmap.scss b/style/_heatmap.scss index 1bb6233..8301dcb 100644 --- a/style/_heatmap.scss +++ b/style/_heatmap.scss @@ -253,6 +253,48 @@ a.cell { color: var(--text); } + // A group of pushes: its summary is laid out as the row, and the pushes list opens under it. + .day-group { + display: block; + } + + summary { + display: flex; + flex-wrap: wrap; + align-items: baseline; + gap: 2px 6px; + font-size: 14px; + color: var(--text); + cursor: pointer; + list-style: none; + + &::-webkit-details-marker { + display: none; + } + + // A chevron that points right when closed and down when open. + &::before { + content: ''; + align-self: center; + width: 6px; + height: 6px; + margin-right: 4px; + border-right: 1.5px solid var(--muted); + border-bottom: 1.5px solid var(--muted); + transform: rotate(-45deg); + transition: transform 0.15s ease; + } + } + + details[open] > summary::before { + transform: rotate(45deg); + } + + details > ul { + margin-top: 10px; + padding-left: 20px; + } + time { margin-left: auto; font-size: 13px;