import { assertThat } from '@task-stream/api/shared/domain'; export enum DevLinkKind { COMMIT = 'COMMIT', BRANCH = 'BRANCH', PULL_REQUEST = 'PULL_REQUEST', } export enum DevLinkState { OPEN = 'OPEN', MERGED = 'MERGED', CLOSED = 'CLOSED', } /** * Code that mentions a ticket: a commit, a branch or a pull/merge request, * as the Git host reported it. The URL identifies it. */ export interface DevLink { kind: DevLinkKind; url: string; /** Commit message's first line, branch name or PR title. */ title: string; /** Short SHA, branch or PR number. */ ref: string; /** Pull requests only. */ state: DevLinkState | null; /** github, gitea, gitlab. */ provider: string; author: string | null; at: string; } /** A ticket keeps the last this-many pieces of code. */ export const MAX_DEV_LINKS = 100; /** Ticket keys of a project mentioned in a text (WEB-12, web-12), once each. */ export function issueKeysIn(text: string, projectKey: string): string[] { const pattern = new RegExp( `(? `${projectKey.toUpperCase()}-${m[1]}`, ), ), ]; } export function normalizeDevLink(link: DevLink): DevLink { assertThat(/^https?:\/\//.test(link.url), 'A dev link needs an http(s) URL'); return { ...link, title: link.title.split('\n')[0].trim().slice(0, 200) || link.ref, ref: link.ref.slice(0, 120), author: link.author?.slice(0, 120) ?? null, }; }