{"version":3,"file":"get-git-logs.mjs","sources":["../../src/version/get-git-logs.ts"],"sourcesContent":["import { $ } from 'execa';\n\nexport interface GitLog {\n  readonly hash: string;\n  readonly message: string;\n  readonly scope: string;\n  readonly type: string;\n  readonly breaking: boolean;\n  readonly fullText: string;\n}\n\nconst TYPE_ORDER: Readonly<Record<string, number>> = {\n  feat: 0,\n  fix: 1,\n  refactor: 2,\n  style: 3,\n  test: 4,\n  build: 5,\n  ci: 6,\n  docs: 7,\n};\n\nexport async function getGitLogs({ dir, name, gitHead }: {\n  dir: string;\n  name: string;\n  gitHead: string;\n}): Promise<GitLog[]> {\n  const { stdout } = await $({\n    stdout: 'pipe',\n    cwd: dir,\n  })`git log ${'--pretty=format:%h %s'} ${gitHead}..HEAD -- .`;\n\n  return stdout\n    .split('\\n')\n    .map((line) => line.trim())\n    .filter(Boolean)\n    .flatMap((line) => createLog(name, line) ?? [])\n    .sort(compareLogs);\n}\n\nfunction createLog(name: string, line: string): GitLog | undefined {\n  const match = line.match(/^\\s*([a-f0-9]+)\\s+(?=\\S)(.+?)(?<=\\S)\\s*?$/mu);\n\n  if (!match) return;\n\n  const [, hash = '', text = ''] = match;\n  const matchConventional = text.match(/^([^:\\s(]*?)(?:\\(([^)\\s]*)\\))?(!)?:(.*)$/u);\n  const [, type = '', scope = '', bang = '', message = text] = matchConventional ?? [];\n  const partial = { hash, message: message.trim(), scope, type: getNormalType(type), breaking: Boolean(bang) };\n  const fullText = getFullText(name, partial);\n\n  return { ...partial, fullText };\n}\n\nfunction getFullText(name: string, log: Omit<GitLog, 'fullText'>): string {\n  const breaking = log.breaking ? '!' : '';\n  const scope = log.scope && log.scope !== name && !name.endsWith(`/${log.scope}`) ? `(${log.scope})` : '';\n  const label = log.type ? `__${log.type}${scope}${breaking}:__ ` : '';\n  const hash = log.hash ? ` (${log.hash})` : '';\n\n  return `${label}${log.message}${hash}`;\n}\n\nfunction getNormalType(type: string): string {\n  type = type.toLowerCase().trim();\n\n  if (type.startsWith('feat')) return 'feat';\n\n  if (type.startsWith('fix')) return 'fix';\n\n  if (type.startsWith('perf')) return 'perf';\n\n  if (type.startsWith('ops')) return 'ops';\n\n  if (type.startsWith('refactor')) return 'refactor';\n  if (type.startsWith('rewrit')) return 'refactor';\n\n  if (type.startsWith('styl')) return 'style';\n\n  if (type.startsWith('test')) return 'test';\n\n  if (type.startsWith('build')) return 'build';\n\n  if (type.startsWith('doc')) return 'docs';\n\n  if (type.startsWith('chore')) return 'chore';\n  if (type.startsWith('patch')) return 'chore';\n  if (!type) return 'chore';\n\n  return type;\n}\n\nfunction compareLogs(a: GitLog, b: GitLog): number {\n  return (TYPE_ORDER[a.type] ?? 100) - (TYPE_ORDER[b.type] ?? 200)\n        || Number(b.breaking) - Number(a.breaking)\n        || a.fullText.localeCompare(b.fullText);\n}\n"],"names":[],"mappings":";AAWA,MAAM,aAA+C;AAAA,EACnD,MAAM;AAAA,EACN,KAAK;AAAA,EACL,UAAU;AAAA,EACV,OAAO;AAAA,EACP,MAAM;AAAA,EACN,OAAO;AAAA,EACP,IAAI;AAAA,EACJ,MAAM;AACR;AAEA,eAAsB,WAAW,EAAE,KAAK,MAAM,WAIxB;AACpB,QAAM,EAAE,WAAW,MAAM,EAAE;AAAA,IACzB,QAAQ;AAAA,IACR,KAAK;AAAA,EAAA,CACN,YAAY,uBAAuB,IAAI,OAAO;AAE/C,SAAO,OACJ,MAAM,IAAI,EACV,IAAI,CAAC,SAAS,KAAK,KAAA,CAAM,EACzB,OAAO,OAAO,EACd,QAAQ,CAAC,SAAS,UAAU,MAAM,IAAI,KAAK,CAAA,CAAE,EAC7C,KAAK,WAAW;AACrB;AAEA,SAAS,UAAU,MAAc,MAAkC;AACjE,QAAM,QAAQ,KAAK,MAAM,6CAA6C;AAEtE,MAAI,CAAC,MAAO;AAEZ,QAAM,CAAA,EAAG,OAAO,IAAI,OAAO,EAAE,IAAI;AACjC,QAAM,oBAAoB,KAAK,MAAM,2CAA2C;AAChF,QAAM,GAAG,OAA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