Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion apps/dashboard/src/lib/github.functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
MyIssuesResult,
MyPullsResult,
PullComment,
PullCommit,
PullDetail,
PullFile,
PullPageData,
Expand Down Expand Up @@ -631,6 +632,44 @@ async function getPullCommentsResult(
});
}

async function getPullCommitsResult(
context: GitHubContext,
data: PullFromRepoInput,
): Promise<PullCommit[]> {
type PullCommitResponse = Awaited<
ReturnType<GitHubClient["rest"]["pulls"]["listCommits"]>
>["data"][number];

return getCachedGitHubRequest<PullCommitResponse[], PullCommit[]>({
context,
resource: "pulls.commits",
params: data,
freshForMs: githubCachePolicy.activity.staleTimeMs,
request: (headers) =>
context.octokit.rest.pulls.listCommits({
owner: data.owner,
repo: data.repo,
pull_number: data.pullNumber,
per_page: 100,
headers,
}),
mapData: (commits) =>
commits.map((c) => ({
sha: c.sha,
message: c.commit.message,
createdAt: c.commit.author?.date ?? c.commit.committer?.date ?? "",
author: c.author
? {
login: c.author.login,
avatarUrl: c.author.avatar_url,
url: c.author.html_url,
type: c.author.type ?? "User",
}
: null,
})),
});
}

async function computePullStatus(
context: GitHubContext,
data: PullFromRepoInput,
Expand Down Expand Up @@ -764,11 +803,15 @@ async function getPullPageDataResult(
freshForMs: githubCachePolicy.detail.staleTimeMs,
});

const comments = await getPullCommentsResult(context, data);
const [comments, commits] = await Promise.all([
getPullCommentsResult(context, data),
getPullCommitsResult(context, data),
]);

return {
detail: mapPullDetail(pull, buildRepositoryRef(data.owner, data.repo)),
comments,
commits,
};
}

Expand Down
8 changes: 8 additions & 0 deletions apps/dashboard/src/lib/github.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,17 @@ export type PullStatus = {
canUpdateBranch: boolean;
};

export type PullCommit = {
sha: string;
message: string;
createdAt: string;
author: GitHubActor | null;
};

export type PullPageData = {
detail: PullDetail | null;
comments: PullComment[];
commits: PullCommit[];
};

export type PullFile = {
Expand Down
185 changes: 141 additions & 44 deletions apps/dashboard/src/routes/_protected/$owner/$repo/pull.$pullId.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ import {
githubPullPageQueryOptions,
githubPullStatusQueryOptions,
} from "#/lib/github.query";
import type { GitHubActor, PullDetail, PullStatus } from "#/lib/github.types";
import type {
GitHubActor,
PullComment,
PullCommit,
PullDetail,
PullStatus,
} from "#/lib/github.types";
import { githubCachePolicy } from "#/lib/github-cache-policy";
import { useHasMounted } from "#/lib/use-has-mounted";
import { useRegisterTab } from "#/lib/use-register-tab";
Expand Down Expand Up @@ -110,6 +116,7 @@ function PullDetailPage() {

const pr = pageQuery.data?.detail;
const comments = pageQuery.data?.comments;
const commits = pageQuery.data?.commits;
const status = statusQuery.data ?? null;

useRegisterTab(
Expand Down Expand Up @@ -241,13 +248,13 @@ function PullDetailPage() {
</div>
)}

{/* Activity / Comments */}
{/* Activity */}
<div className="flex flex-col">
<div className="flex items-center justify-between gap-2 rounded-lg bg-surface-1 px-4 py-2.5">
<h2 className="text-xs font-medium">Activity</h2>
{comments && (
{comments && commits && (
<span className="text-xs tabular-nums text-muted-foreground">
{comments.length}
{comments.length + commits.length}
</span>
)}
</div>
Expand Down Expand Up @@ -278,46 +285,19 @@ function PullDetailPage() {
</div>
)}

{comments && comments.length === 0 && (
<p className="py-4 text-sm text-muted-foreground">
No comments yet.
</p>
)}
{comments &&
commits &&
comments.length === 0 &&
commits.length === 0 && (
<p className="py-4 text-sm text-muted-foreground">
No activity yet.
</p>
)}

{comments && comments.length > 0 && (
<div className="relative flex flex-col pl-8 before:absolute before:left-4 before:top-0 before:h-full before:w-px before:bg-[linear-gradient(to_bottom,var(--color-border)_80%,transparent)]">
{comments.map((comment, i) => (
<div
key={comment.id}
className={cn(
"flex flex-col gap-1 py-4",
i === 0 && "pt-5",
)}
>
<div className="flex items-center gap-1.5">
{comment.author ? (
<img
src={comment.author.avatarUrl}
alt={comment.author.login}
className="size-4 rounded-full border border-border"
/>
) : (
<div className="size-4 rounded-full bg-surface-2" />
)}
<span className="text-xs font-medium">
{comment.author?.login ?? "Unknown"}
</span>
<span className="text-xs text-muted-foreground">
{formatRelativeTime(comment.createdAt)}
</span>
</div>
<Markdown className="text-muted-foreground">
{comment.body}
</Markdown>
</div>
))}
</div>
)}
<ActivityTimeline
comments={comments ?? []}
commits={commits ?? []}
/>

{/* Status card */}
{!pr.isMerged && pr.state !== "closed" && (
Expand Down Expand Up @@ -384,7 +364,11 @@ function PullDetailPage() {

{/* Participants */}
<SidebarSection title="Participants">
<ParticipantsList pr={pr} comments={comments ?? []} />
<ParticipantsList
pr={pr}
comments={comments ?? []}
commits={commits ?? []}
/>
</SidebarSection>

{/* Details */}
Expand Down Expand Up @@ -473,9 +457,11 @@ function DetailRow({
function ParticipantsList({
pr,
comments,
commits,
}: {
pr: PullDetail;
comments: Array<{ author: GitHubActor | null }>;
commits: Array<{ author: GitHubActor | null }>;
}) {
const seen = new Set<string>();
const participants: GitHubActor[] = [];
Expand All @@ -491,6 +477,9 @@ function ParticipantsList({
for (const comment of comments) {
addActor(comment.author);
}
for (const commit of commits) {
addActor(commit.author);
}

if (participants.length === 0) {
return <p className="text-xs text-muted-foreground">No participants yet</p>;
Expand Down Expand Up @@ -891,6 +880,114 @@ function UpdateBranchButton({
);
}

type TimelineItem =
| { type: "comment"; date: string; data: PullComment }
| { type: "commit"; date: string; data: PullCommit };

function ActivityTimeline({
comments,
commits,
}: {
comments: PullComment[];
commits: PullCommit[];
}) {
const items: TimelineItem[] = [
...comments.map((c) => ({
type: "comment" as const,
date: c.createdAt,
data: c,
})),
...commits.map((c) => ({
type: "commit" as const,
date: c.createdAt,
data: c,
})),
].sort((a, b) => new Date(a.date).getTime() - new Date(b.date).getTime());

if (items.length === 0) return null;

return (
<div className="relative flex flex-col pl-8 before:absolute before:left-4 before:top-0 before:h-full before:w-px before:bg-[linear-gradient(to_bottom,var(--color-border)_80%,transparent)]">
{items.map((item, i) => {
const prevType = i > 0 ? items[i - 1].type : null;
const nextType = i < items.length - 1 ? items[i + 1].type : null;
const isConsecutiveCommit =
item.type === "commit" && prevType === "commit";
const isLastInCommitRun =
item.type === "commit" && nextType !== "commit";

if (item.type === "comment") {
const comment = item.data;
return (
<div
key={`comment-${comment.id}`}
className={cn("flex flex-col gap-1 py-5", i === 0 && "pt-5")}
>
<div className="flex items-center gap-1.5">
{comment.author ? (
<img
src={comment.author.avatarUrl}
alt={comment.author.login}
className="size-4 rounded-full border border-border"
/>
) : (
<div className="size-4 rounded-full bg-surface-2" />
)}
<span className="text-xs font-medium">
{comment.author?.login ?? "Unknown"}
</span>
<span className="text-xs text-muted-foreground">
{formatRelativeTime(comment.createdAt)}
</span>
</div>
<Markdown className="text-muted-foreground">
{comment.body}
</Markdown>
</div>
);
}

const commit = item.data;
const firstLine = commit.message.split("\n")[0];
return (
<div
key={`commit-${commit.sha}`}
className={cn(
"flex items-center gap-1.5",
i === 0 ? "pt-5" : isConsecutiveCommit ? "pt-2" : "pt-5",
isLastInCommitRun ? "pb-5" : "pb-2",
)}
>
<div className="flex size-5 shrink-0 items-center justify-center rounded-full border border-border bg-surface-1">
<GitCommitIcon
size={12}
strokeWidth={2}
className="text-muted-foreground"
/>
</div>
{commit.author ? (
<img
src={commit.author.avatarUrl}
alt={commit.author.login}
className="size-5 shrink-0 rounded-full border border-border"
/>
) : (
<div className="size-5 shrink-0 rounded-full bg-surface-2" />
)}
<span className="min-w-0 truncate text-sm">{firstLine}</span>
<code className="ml-auto shrink-0 rounded bg-surface-1 px-1.5 py-0.5 font-mono text-[10px] text-muted-foreground">
{commit.sha.slice(0, 7)}
</code>
<span className="shrink-0 text-xs text-muted-foreground">
{formatRelativeTime(commit.createdAt)}
</span>
</div>
);
})}
</div>
);
}

function CommentBox() {
const [value, setValue] = useState("");

Expand Down
Loading