From d146601ab9a3b28678b3c8f835719832138a85eb Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Wed, 2 Aug 2023 14:18:19 +0200 Subject: [PATCH 1/2] add getGitInfo function exported by the node-api --- node-src/tasks/index.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/node-src/tasks/index.ts b/node-src/tasks/index.ts index 277390379..6754e323f 100644 --- a/node-src/tasks/index.ts +++ b/node-src/tasks/index.ts @@ -11,6 +11,7 @@ import snapshot from './snapshot'; import storybookInfo from './storybookInfo'; import upload from './upload'; import verify from './verify'; +import { getBranch, getCommit, getSlug } from '../git/git'; export const runUploadBuild = [ auth, @@ -30,3 +31,20 @@ export default (options: Context['options']): Listr.ListrTask[] => { return options.junitReport ? tasks.concat(report) : tasks; }; + +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 : '' }; +} From 96ca43448869440197f598e6c7ca4dd2a9f5517b Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Thu, 3 Aug 2023 09:36:29 +0200 Subject: [PATCH 2/2] move the code to the actual entrypoint for node --- node-src/index.ts | 18 ++++++++++++++++++ node-src/tasks/index.ts | 18 ------------------ 2 files changed, 18 insertions(+), 18 deletions(-) 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 : '' }; +} diff --git a/node-src/tasks/index.ts b/node-src/tasks/index.ts index 6754e323f..277390379 100644 --- a/node-src/tasks/index.ts +++ b/node-src/tasks/index.ts @@ -11,7 +11,6 @@ import snapshot from './snapshot'; import storybookInfo from './storybookInfo'; import upload from './upload'; import verify from './verify'; -import { getBranch, getCommit, getSlug } from '../git/git'; export const runUploadBuild = [ auth, @@ -31,20 +30,3 @@ export default (options: Context['options']): Listr.ListrTask[] => { return options.junitReport ? tasks.concat(report) : tasks; }; - -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 : '' }; -}