~ knotless Search/
↑↓ move↵ open⇧↵ all results

johnandersen777.bsky.social/knotless

git that lives in your Atmosphere account

Forked from chadtmiller.com/knotless

0
0
94 lines · 3.2 KB Raw History
<script lang="ts">
	import type { CheckView, CommitView } from '#lib/lexicons/dev/knotless/defs.ts';
	import { date, itemHref, repoHref, subject, whenCommitted } from '#lib/format.ts';
	import CheckMark from '#lib/molecules/CheckMark.svelte';
	import Committed from '#lib/molecules/Committed.svelte';
	import Icon from '#lib/atoms/Icon.svelte';
	import More from '#lib/atoms/More.svelte';
	import Sha from '#lib/atoms/Sha.svelte';
	import Toolbar from '#lib/organisms/Toolbar.svelte';
	import RepoPage from '#lib/templates/RepoPage.svelte';
	import { Pages, type Page } from '#lib/pages.svelte.ts';
	import { zone } from '#lib/zone.svelte.ts';
	import Empty from '#lib/molecules/Empty.svelte';
	let { data } = $props();
	const h = $derived(data.history);
	const r = $derived(data.repo);
	/** A commit, and the newest run of each workflow at it. */
	type Shown = { commit: CommitView; checks: CheckView[] };
	/** Each page of history with its commits paired with their checks, made once, as Pages knows the page loaded by its items. */
	const paired = new WeakMap<object, Page<Shown>>();
	function page(history: typeof h): Page<Shown> {
		let found = paired.get(history);
		if (!found) {
			const checks = history.checks ?? [];
			const items = history.commits.map((commit) => ({
				commit,
				checks: checks.filter((c) => c.commit === commit.sha)
			}));
			found = { items, cursor: history.cursor };
			paired.set(history, found);
		}
		return found;
	}
	const commits = new Pages(
		() => data,
		(d) => page(d.history),
		(s) => s.commit.sha
	);
	/**
	 * The commits by the day they were committed on, which runs in order
	 * down history, as the day each was written need not: a rebase or a
	 * squash keeps that. A clock that was wrong can bring a day round
	 * again, so each run of one is keyed by its first commit.
	 */
	const days = $derived.by(() => {
		const out: [string, Shown[]][] = [];
		for (const s of commits.items) {
			const on = date(whenCommitted(s.commit));
			const last = out.at(-1);
			if (last && last[0] === on) last[1].push(s);
			else out.push([on, [s]]);
		}
		return out;
	});
	const href = (c: CommitView) => repoHref(data.authority, r.name, `/commit/${c.sha}`);
</script>

<RepoPage repo={r} tab="code" title="Commits · {r.name}" feed="commits">
	<Toolbar
		authority={data.authority}
		name={r.name}
		rev={h.ref}
		view="commits"
		path={h.path}
		branches={data.branches}
		head={r.defaultBranch}
		tags={data.tags}
	/>
	{#each days as [day, commits] (commits[0].commit.sha)}
		<h2 class="day" class:zoneless={!zone.tz}><Icon name="commit" />Commits on {day}</h2>
		<div class="box">
			<ul class="list">
				{#each commits as { commit: c, checks } (c.sha)}
					<li>
						<div class="grow">
							<a class="title clip" href={href(c)}>{subject(c.message)}</a>
							<div class="meta">
								<Committed commit={c} /><CheckMark {checks} />{#if c.pull}<a
										class="from"
										href={itemHref(repoHref(data.authority, r.name), c.pull.uri)}
										title={c.pull.title}><Icon name="merge" />Pull</a
									>{/if}
							</div>
						</div>
						<Sha sha={c.sha} href={href(c)} />
					</li>
				{/each}
			</ul>
		</div>
	{:else}
		<div class="box"><Empty title="No commits here" /></div>
	{/each}
	<More pages={commits} label="Older commits" />
</RepoPage>