-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
3,300 additions
and
34 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict'; | ||
|
||
const branchName = require('current-git-branch'); | ||
const { Command, Option } = require('commander'); | ||
const path = require('path'); | ||
const { | ||
validateBranchName, | ||
} = require('./lib/validateBranchName'); | ||
const currentBranchName = branchName(); | ||
const SUCCESS_CODE = 0; | ||
const FAILED_CODE = 1; | ||
// const REGEXP = [ | ||
// '^(master|develop){1}$|^(feature|fix|hotfix|release)\/.+$', | ||
// '(feature|release|hotfix)\/(JIRA-\d+', | ||
// '(feature|release|hotfix)\/(JIRA-\d+\/)?[a-z-]+', | ||
// '^(feature|fix|hotfix|release)\/.+', | ||
// ]; | ||
const pkgJson = require(path.join(__dirname, './package.json')); | ||
const program = new Command(); | ||
program.description('Git branch name validate tool'); | ||
program.version(pkgJson.version, '-v, --version', 'validate-branch-name current version'); | ||
program.option('-t, --test <branch>', 'test target branch, using current git brach by default'); | ||
program.addOption(new Option('-r, --regexp <regexp>', 'choose regular expression to test branch name')); | ||
program.parse(process.argv); | ||
|
||
const options = program.opts(); | ||
const branch = options.test || currentBranchName; | ||
|
||
// validate whether it is a git repository | ||
if (!options.branch && !currentBranchName) { | ||
console.error('\x1b[31m%s\x1b[0m', 'Error: not a git repository\n'); | ||
process.exitCode = FAILED_CODE; | ||
return; | ||
} | ||
try { | ||
console.log(options.regexp); | ||
const result = validateBranchName(branch, options.regexp); | ||
process.exitCode = result ? SUCCESS_CODE : FAILED_CODE; | ||
} catch (error) { | ||
console.error('\x1b[31m%s\x1b[0m', error.message + '\n'); | ||
process.exitCode = FAILED_CODE; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,8 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict'; | ||
|
||
const branchName = require('current-git-branch'); | ||
const { | ||
validateBranchName, | ||
} = require('./lib/validateBranchName'); | ||
const currentBranchName = branchName(); | ||
const SUCCESS_CODE = 0; | ||
const FAILED_CODE = 1; | ||
const { validateBranchName } = require('./lib/validateBranchName'); | ||
|
||
// validate whether it is a git repository | ||
if (!currentBranchName) { | ||
console.error('\x1b[31m%s\x1b[0m', 'Error: not a git repository\n'); | ||
process.exitCode = FAILED_CODE; | ||
return; | ||
} | ||
try { | ||
const result = validateBranchName(currentBranchName); | ||
process.exitCode = result ? SUCCESS_CODE : FAILED_CODE; | ||
} catch (error) { | ||
console.error('\x1b[31m%s\x1b[0m', error.message + '\n'); | ||
process.exitCode = FAILED_CODE; | ||
} | ||
module.exports = branch => { | ||
const branchName = branch || require('current-git-branch'); | ||
return validateBranchName(branchName, null, false); | ||
}; |
This file contains 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
Oops, something went wrong.