Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --branch-name flag to override branch name #233

Merged
merged 3 commits into from Jan 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
3 changes: 3 additions & 0 deletions bin/lib/getOptions.js
Expand Up @@ -24,6 +24,7 @@ const resolveHomeDir = (filepath) =>
export default async function getOptions({ argv, env, flags, log, packageJson }) {
const fromCI = !!flags.ci || !!process.env.CI;
const [patchHeadRef, patchBaseRef] = (flags.patchBuild || '').split('...').filter(Boolean);
const [branchName, ownerName] = (flags.branchName || '').split(':').reverse();

const options = {
projectToken: takeLast(flags.projectToken || flags.appCode) || env.CHROMATIC_PROJECT_TOKEN, // backwards compatibility
Expand Down Expand Up @@ -64,6 +65,8 @@ export default async function getOptions({ argv, env, flags, log, packageJson })
: undefined,
createTunnel: !flags.storybookUrl && env.CHROMATIC_CREATE_TUNNEL !== 'false',

ownerName,
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. Also accepts <owner>:<branch> format.
--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