| 1 | import type { Pull } from "@g1t/contracts"; |
| 2 | |
| 3 | /** g1t's own name: its agent's, and the system's. */ |
| 4 | export 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 | */ |
| 10 | export function madeByG1t(pull: Pick<Pull, "agent" | "branch">): boolean { |
| 11 | return pull.agent === G1T && !pull.branch; |
| 12 | } |
| 13 | |
| 14 | /** |
| 15 | * Who shows as having opened a pull request. g1t for one its agent made, |
| 16 | * with the person who asked for the work as `requestedBy`; anyone else's |
| 17 | * is its author's, with no `requestedBy`. Only the face: who may change |
| 18 | * the pull request is still decided by its stored author. |
| 19 | */ |
| 20 | export function openedBy(pull: Pick<Pull, "agent" | "branch" | "author">): { name: string; requestedBy: string | null } { |
| 21 | if (!madeByG1t(pull)) return { name: pull.author.username, requestedBy: null }; |
| 22 | // Work g1t started itself, such as a security update's code change, was asked for by nobody else. |
| 23 | return { name: G1T, requestedBy: pull.author.username === G1T ? null : pull.author.username }; |
| 24 | } |