Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

g1t.sh
27 linesCodeBlameRaw
1import type { Comment, CommitComment } from "@g1t/contracts";
2
3/**
4 * Commit comments in the shape the conversation and the diff show comments
5 * in. A commit comment names its author by username, which stands in for the
6 * id: compare it with the viewer's username to tell their own.
7 */
8export function asComments(comments: CommitComment[]): Comment[] {
9 return comments.map((comment) => ({
10 id: comment.id,
11 kind: "comment",
12 author: { id: comment.author, username: comment.author },
13 body: comment.body,
14 path: comment.path,
15 line: comment.line,
16 verdict: null,
17 createdAt: comment.createdAt,
18 ...(comment.updatedAt && comment.updatedAt !== comment.createdAt ? { editedAt: comment.updatedAt } : {}),
19 }));
20}
21
22/** How many comments each commit has, from a list of a repository's comments. */
23export function countByCommit(comments: Pick<CommitComment, "commit">[]): Record<string, number> {
24 const counts: Record<string, number> = {};
25 for (const comment of comments) counts[comment.commit] = (counts[comment.commit] ?? 0) + 1;
26 return counts;
27}