Last active
January 17, 2020 12:40
-
-
Save shaharkazaz/eeeef83bfdb5a8a4545e646b5c1f66cd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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