diff --git a/bin/git/getCommitAndBranch.js b/bin/git/getCommitAndBranch.js index e1724979a..3009ef338 100644 --- a/bin/git/getCommitAndBranch.js +++ b/bin/git/getCommitAndBranch.js @@ -6,17 +6,12 @@ import missingTravisInfo from '../ui/messages/errors/missingTravisInfo'; import travisInternalBuild from '../ui/messages/warnings/travisInternalBuild'; import { getBranch, getCommit, hasPreviousCommit } from './git'; -const notHead = (b) => { - if (!b || b === 'HEAD') { - return false; - } - return b; -}; +const notHead = (branch) => (branch && branch !== 'HEAD' ? branch : false); -export async function getCommitAndBranch({ patchBaseRef, inputFromCI, log } = {}) { +export async function getCommitAndBranch({ branchName, patchBaseRef, ci, log } = {}) { // eslint-disable-next-line prefer-const let { commit, committedAt, committerEmail, committerName } = await getCommit(); - let branch = patchBaseRef || (await getBranch()); + let branch = notHead(branchName) || notHead(patchBaseRef) || (await getBranch()); const { TRAVIS_EVENT_TYPE, @@ -88,15 +83,13 @@ export async function getCommitAndBranch({ patchBaseRef, inputFromCI, log } = {} notHead(process.env.GERRIT_BRANCH) || notHead(process.env.CI_BRANCH) || notHead(process.env.GITHUB_REF) || - notHead(branch) || 'HEAD'; } + // REPOSITORY_URL is for netlify: https://www.netlify.com/docs/continuous-deployment/ const fromCI = - !!inputFromCI || - !!process.env.CI || - !!process.env.REPOSITORY_URL || - !!process.env.GITHUB_REPOSITORY; + !!ci || !!process.env.CI || !!process.env.REPOSITORY_URL || !!process.env.GITHUB_REPOSITORY; + log.debug( `git info: ${JSON.stringify({ commit, diff --git a/bin/lib/getOptions.js b/bin/lib/getOptions.js index 65873466e..cb7055632 100644 --- a/bin/lib/getOptions.js +++ b/bin/lib/getOptions.js @@ -64,6 +64,7 @@ export default async function getOptions({ argv, env, flags, log, packageJson }) : undefined, createTunnel: !flags.storybookUrl && env.CHROMATIC_CREATE_TUNNEL !== 'false', + branchName: flags.branchName, patchHeadRef, patchBaseRef, }; diff --git a/bin/lib/getOptions.test.js b/bin/lib/getOptions.test.js index d3ec23958..b9014b823 100644 --- a/bin/lib/getOptions.test.js +++ b/bin/lib/getOptions.test.js @@ -195,6 +195,12 @@ describe('await getOptions', () => { createTunnel: false, }); }); + + it('allows you to specify the branch name', async () => { + expect(await getOptions(getContext(['--branch-name', 'my/branch']))).toMatchObject({ + branchName: 'my/branch', + }); + }); }); describe('getStorybookConfiguration', () => { diff --git a/bin/lib/parseArgs.js b/bin/lib/parseArgs.js index 5b4fff45f..2b8825c3f 100644 --- a/bin/lib/parseArgs.js +++ b/bin/lib/parseArgs.js @@ -52,6 +52,7 @@ export default function parseArgs(argv) { 'exit-zero-on-changes': { type: 'string' }, 'ignore-last-build-on-branch': { type: 'string' }, only: { type: 'string' }, + 'branch-name': { type: 'string' }, 'patch-build': { type: 'string' }, 'preserve-missing': { type: 'boolean' }, skip: { type: 'string' }, diff --git a/bin/tasks/gitInfo.js b/bin/tasks/gitInfo.js index b9bd99e65..8ac4522e6 100644 --- a/bin/tasks/gitInfo.js +++ b/bin/tasks/gitInfo.js @@ -19,9 +19,9 @@ const TesterSkipBuildMutation = ` `; export const setGitInfo = async (ctx, task) => { - const { patchBaseRef, fromCI, ignoreLastBuildOnBranch, skip } = ctx.options; + const { branchName, patchBaseRef, fromCI, ignoreLastBuildOnBranch, skip } = ctx.options; - ctx.git = await getCommitAndBranch({ patchBaseRef, inputFromCI: fromCI, log: ctx.log }); + ctx.git = await getCommitAndBranch({ branchName, patchBaseRef, ci: fromCI, log: ctx.log }); ctx.git.version = await getVersion(); const { branch, commit } = ctx.git;