Skip to content

Commit

Permalink
Allow overriding branch name.
Browse files Browse the repository at this point in the history
  • Loading branch information
ghengeveld committed Jan 6, 2021
1 parent 58d8af3 commit d847727
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
19 changes: 6 additions & 13 deletions bin/git/getCommitAndBranch.js
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions bin/lib/getOptions.js
Expand Up @@ -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,
};
Expand Down
6 changes: 6 additions & 0 deletions bin/lib/getOptions.test.js
Expand Up @@ -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', () => {
Expand Down
2 changes: 2 additions & 0 deletions bin/lib/parseArgs.js
Expand Up @@ -17,6 +17,7 @@ export default function parseArgs(argv) {
Chromatic options
--allow-console-errors Continue running Chromatic even if there are errors logged to console in your Storybook.
--auto-accept-changes [branch] If there are any changes to the build, automatically accept them. Only for [branch], if specified. Globs are supported via picomatch.
--branch-name <branch> Override the branch name. Only meant to be used for unsupported CI integrations and fixing cross-fork PR comparisons.
--exit-once-uploaded [branch] Exit with 0 once the built version has been published to Chromatic. Only for [branch], if specified. Globs are supported via picomatch.
--exit-zero-on-changes [branch] If all snapshots render but there are visual changes, exit with code 0 rather than the usual exit code 1. Only for [branch], if specified. Globs are supported via picomatch.
--ignore-last-build-on-branch <branch> Do not use the last build on this branch as a baseline if it is no longer in history (i.e. branch was rebased). Globs are supported via picomatch.
Expand Down Expand Up @@ -52,6 +53,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' },
Expand Down
4 changes: 2 additions & 2 deletions bin/tasks/gitInfo.js
Expand Up @@ -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;

Expand Down

0 comments on commit d847727

Please sign in to comment.