Skip to content

Instantly share code, notes, and snippets.

@shaharkazaz
Last active January 17, 2020 12:40
Show Gist options
  • Select an option

  • Save shaharkazaz/eeeef83bfdb5a8a4545e646b5c1f66cd to your computer and use it in GitHub Desktop.

Select an option

Save shaharkazaz/eeeef83bfdb5a8a4545e646b5c1f66cd to your computer and use it in GitHub Desktop.
const chalk = require('chalk');
const {exec} = require('./exec');
const branchName = exec('git rev-parse --abbrev-ref HEAD', {trim: true});
// check if this branch already exists in the remote
const isInRemote = exec(`git show-branch remotes/origin/${branchName}`, {toString: false}).code === 0;
if (!isInRemote) {
const validBranchPrefix = 'feature|fix|hotfix|chore|tests|automation';
const validBranchesRegex = new RegExp(`^(${validBranchPrefix})\/[\\w.-]+$`);
if (!validBranchesRegex.test(branchName)) {
const msg = `Branch names in this project must adhere to this contract: ${validBranchPrefix}.`
console.log(chalk.bgRed.black.bold(msg));
process.exit(1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment