diff --git a/node-src/index.ts b/node-src/index.ts index 177753c8e..38d98f37a 100644 --- a/node-src/index.ts +++ b/node-src/index.ts @@ -14,6 +14,7 @@ import checkPackageJson from './lib/checkPackageJson'; import { writeChromaticDiagnostics } from './lib/writeChromaticDiagnostics'; import invalidPackageJson from './ui/messages/errors/invalidPackageJson'; import noPackageJson from './ui/messages/errors/noPackageJson'; +import { getBranch, getCommit, getSlug } from './git/git'; /** Make keys of `T` outside of `R` optional. @@ -110,3 +111,20 @@ export async function runAll(ctx, options?: Options) { await writeChromaticDiagnostics(ctx); } } + +export type GitInfo = { + branch: string; + commit: string; + slug: string; +}; + +export async function getGitInfo(): Promise { + const branch = await getBranch(); + const { commit } = await getCommit(); + const slug = await getSlug(); + + const [ownerName, repoName, ...rest] = slug ? slug.split('/') : []; + const isValidSlug = !!ownerName && !!repoName && !rest.length; + + return { branch, commit, slug: isValidSlug ? slug : '' }; +}