g1t/apps/web/app/lib/opened-by.ts

22 lines863 bytesCodeBlame
1import type { Pull } from "@g1t/contracts";
2
3/** g1t's own name: its agent's, and the system's. */
4export const G1T = "g1t";
5
6/**
7 * Whether g1t's own agent made a pull request: in a fork of its own, not
8 * on a branch someone pushed.
9 */
10export function madeByG1t(pull: Pick<Pull, "agent" | "branch">): boolean {
11 return pull.agent === G1T && !pull.branch;
12}
13
14/**
15 * Who opened an issue or a pull request, and who asked g1t for it, as
16 * stored: g1t for what it made or filed, with the person it was for as
17 * `requestedBy`; anyone else's, theirs alone. Who may change it is the
18 * same pair read the other way round: `workOwner` in the contracts.
19 */
20export function openedBy(item: Pick<Pull, "author" | "requestedBy">): { name: string; requestedBy: string | null } {
21 return { name: item.author.username, requestedBy: item.requestedBy?.username ?? null };
22}