~james/core

core/web/src/lib/components/repo/CommitHeader.svelte -rw-r--r-- 5.8 KiB
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 16 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<script module lang="ts">
	import { tv, type VariantProps } from "tailwind-variants";

	export const commitHeader = tv({
		slots: {
			root: "flex flex-col gap-md text-foreground-default",
			header: "flex flex-col gap-xs",
			headerSubject: "min-w-0 typography-paragraph-large wrap-break-word",
			headerBody: "typography-monospace-regular wrap-anywhere whitespace-pre-wrap",
			commitDetails: "flex flex-col gap-xs typography-paragraph-regular",
			commitDetailsRow: "inline-flex min-h-7 flex-wrap items-center",
			commitDetailsTitle: "w-32 text-foreground-muted select-none"
		}
	});

	export type CommitHeaderVariants = VariantProps<typeof commitHeader>;
</script>

<script lang="ts">
	import { resolve } from "$app/paths";
	import type { CommitDetail } from "#lib/api/repo.ts";
	import Pending from "#lib/components/ui/Pending.svelte";
	import CommitAuthor from "#lib/components/repo/CommitAuthor.svelte";
	import TimeAgo from "#lib/components/ui/TimeAgo.svelte";
	import { formatDateTime } from "#lib/format.ts";
	import type { CommitStatuses } from "#lib/api/commitStatuses.ts";
	import PipelineWorkflows from "#lib/components/repo/pipelines/PipelineWorkflows.svelte";
	import Separator from "#lib/components/ui/Separator.svelte";
	import Button from "#lib/components/ui/Button.svelte";
	import CopyButton from "#lib/components/ui/CopyButton.svelte";
	import CommitShaButton from "#lib/components/repo/CommitShaButton.svelte";
	import { verifiedSignature } from "#lib/components/repo/commitSignature.ts";
	import Tooltip from "#lib/components/ui/Tooltip.svelte";

	interface Props {
		ownerHandle: string;
		repoName: string;
		commit: CommitDetail;
		// empty for a root commit
		parent?: string;
		changeId?: string;
		pipelineStatuses?: Promise<CommitStatuses>;
		refNames?: string[] | Promise<string[]>;
	}

	let {
		ownerHandle,
		repoName,
		commit,
		parent = "",
		changeId = "",
		pipelineStatuses,
		refNames
	}: Props = $props();

	const base = $derived(`/${ownerHandle}/${repoName}`);

	const showCommitter = $derived(
		commit.committerEmail !== "" && commit.committerEmail !== commit.authorEmail
	);
	const parentShort = $derived(parent.slice(0, 8));
	const changeIdShort = $derived(changeId.slice(0, 8));

	const absoluteTime = $derived(formatDateTime(commit.committerWhen));

	const styles = $derived(commitHeader());
</script>

<section class={styles.root()}>
	<div class={styles.header()}>
		<span class="flex min-h-9 flex-row items-center justify-between">
			<p class={styles.headerSubject()}>
				{commit.subject}
				{#if refNames}
					<Pending>
						{#each await refNames as name (name)}
							<span
								class="ml-2xs min-w-0 rounded-md bg-background-inset px-2xs typography-monospace-regular font-normal wrap-anywhere text-foreground-default"
							>
								{name}
							</span>
						{/each}
					</Pending>
				{/if}
			</p>
			{#if pipelineStatuses}
				<Pending>
					{@const pipeline = (await pipelineStatuses)[commit.hash]}
					{#if pipeline}
						<PipelineWorkflows
							{ownerHandle}
							{repoName}
							{pipeline}
							variant="symbol"
							summary="long"
						/>
					{/if}
				</Pending>
			{/if}
		</span>
		{#if commit.body}
			<p class={styles.headerBody()}>
				{commit.body}
			</p>
		{/if}
	</div>

	<Separator />

	<div class={styles.commitDetails()}>
		{#snippet attribution(
			label: string,
			name: string,
			email: string,
			did?: string,
			handle?: string
		)}
			<span class={styles.commitDetailsRow()}>
				<span class={styles.commitDetailsTitle()}>{label}</span>
				<CommitAuthor {name} {email} {did} {handle} />
			</span>
		{/snippet}

		{@render attribution(
			"Author",
			commit.authorName,
			commit.authorEmail,
			commit.authorDid,
			commit.authorHandle
		)}

		{#each commit.coAuthors as coAuthor (coAuthor.email)}
			{@render attribution("Co-author", coAuthor.name, coAuthor.email)}
		{/each}

		{#if showCommitter}
			{@render attribution("Committer", commit.committerName, commit.committerEmail)}
		{/if}

		{#if commit.committerWhen}
			<span class={styles.commitDetailsRow()}>
				<span class={styles.commitDetailsTitle()}>Date</span>
				<span class="flex flex-row gap-2xs">
					<TimeAgo value={commit.committerWhen} variant="full" />
					{#if absoluteTime}
						<span class="hidden text-foreground-muted sm:inline">({absoluteTime})</span>
					{/if}
				</span>
			</span>
		{/if}

		{#snippet copyId(label: string, tooltip: string, value: string, short: string)}
			<span class={styles.commitDetailsRow()}>
				<span class={styles.commitDetailsTitle()}>{label}</span>
				<Tooltip content={tooltip}>
					<CopyButton
						{value}
						feedback="icon"
						aria-label="{tooltip} {short}"
						class="-ml-2 typography-monospace-regular"
					>
						<span class="sm:hidden">{short}</span>
						<span class="hidden sm:inline">{value}</span>
					</CopyButton>
				</Tooltip>
			</span>
		{/snippet}

		{#if commit.hash}
			{@const signature = verifiedSignature(commit)}
			{#if signature}
				<span class={styles.commitDetailsRow()}>
					<span class={styles.commitDetailsTitle()}>Commit</span>
					<CommitShaButton
						hash={commit.hash}
						shortHash={commit.shortHash}
						{changeId}
						{signature}
						full
					/>
				</span>
			{:else}
				{@render copyId("Commit", "Copy SHA", commit.hash, commit.shortHash)}
			{/if}
		{/if}

		{#if parent}
			<span class={styles.commitDetailsRow()}>
				<span class={styles.commitDetailsTitle()}>Parent</span>
				<Button
					variant="ghost"
					size="small"
					href={resolve(`${base}/commit/${parent}` as "/")}
					class="-ml-2 typography-monospace-regular"
				>
					<span class="sm:hidden">{parentShort}</span>
					<span class="hidden sm:inline">{parent}</span>
				</Button>
			</span>
		{/if}

		{#if changeId}
			{@render copyId("Change ID", "Copy change ID", changeId, changeIdShort)}
		{/if}
	</div>
</section>