Skip to content

Commit

Permalink
feat(app): modify option to release from any branch
Browse files Browse the repository at this point in the history
ISSUES CLOSED: #43
  • Loading branch information
leonardoanalista committed Jun 25, 2017
1 parent 48e9023 commit cc29c2d
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ logs
*.log
npm-debug.log*
.DS_Store
.history
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ node_js:
- '6'
- 'node'
before_install:
- npm i -g npm@^2.0.0
- npm i -g npm@^3.0.0
before_script:
- npm prune

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Of course you can change `corp-release` to any name you like.
* `-d` or `--dryrun`: it runs in non-destructive mode. No alteration should be done in your workspace.
* `--pre-commit [npm-script]`: Pre-commit hook. Pass the name of the npm script to run. It will run like this: `npm run [npm-script]`.
* `--post-success [command]`: Post-success hook (after `git push` completes successfully). Pass a command to run as the argument. Eg: `--post-success "npm publish"`.
* `-b [branch]` or `--branch [branch]`: Branch name allowed to run release. Default is `master`. If you want to release from another branch, you need to specify.
* `-b [branch]` or `--branch [branch]`: Branch name allowed to run release. Default is `master`. If you want to release from another branch, you need to specify. Use "*" to allow any branch - Useful for Jenkins as git does a revision check-out.
* `-v` or `--verbose`: it prints extra info such as commit list from last tag and command details.
* `--changelogpreset [preset]`: The conventional-changelog preset to use. Default is `angular`. `angular-bitbucket` is available for [BitBucket repositories](https://github.com/uglow/conventional-changelog-angular-bitbucket). Other presets can be installed, e.g: `npm i conventional-changelog-jquery` then pass this flag to the command: `--changelogpreset jquery`.
* `-r [num]` or `--releasecount [num]`: How many releases of changelog you want to generate. It counts from the upcoming release. Useful when you forgot to generate any previous changelog. Set to 0 to regenerate all (will overwrite any existing changelog!).
Expand Down Expand Up @@ -88,7 +88,7 @@ In the following example, `updateOtherFiles.js` does *NOT* receive the version a

<details>
<summary>Option 2 - `--pre-commit [npm-script]`</summary>
`corp-semantic-release` also provides a `--pre-commit <NPM script>` option. The NPM script is passed the version
`corp-semantic-release` also provides a `--pre-commit <NPM script>` option. The NPM script is passed the version
number as an argument to the script.

```json
Expand Down
2 changes: 1 addition & 1 deletion confit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ generator-confit:
app:
_version: f02196cc5cb7941ca46ec46d23bd6aef0dfcaca0
buildProfile: Latest
copyrightOwner: Leonardo Correa
copyrightOwner: Developers who contribute to this project
license: MIT
projectType: node
publicRepository: true
Expand Down
15 changes: 15 additions & 0 deletions spec/validateBranch.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,19 @@ describe('validateBranch', () => {
expect(output[0]).to.include(`>>> Your release branch is: fooBranch`);
expect(exitCalled).to.equal(false); // exit() is never called
});

it('should allow release from any branch when option --branch is "*"', () => {
let exitCalled = false;

revert = validateBranch.__set__({
shell: {
exit: () => exitCalled = true,
},
});

const result = validateBranch('*');

expect(result).to.equal(null);
expect(exitCalled).to.equal(false);
});
});
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ program
.option('-d, --dryrun', 'No changes to workspace. Stops after changelog is printed.')
.option('--pre-commit [npm-script]', 'Pre-commit hook. Pass the name of the npm script to run. It will run like this: npm run [pre-commit]')
.option('--post-success [command]', 'Post-success hook (after git push completes successfully). Pass a command to run as the argument. Eg: --post-success "npm publish"')
.option('-b, --branch [branch]', 'Branch name [branch] allowed to run release. Default is master. If you want another branch, you need to specify.')
.option('-b, --branch [branch]', 'Branch name [branch] allowed to run release. Default is master. If you want another branch, you need to specify. Use "*" to allow any branch')
.option('-v, --verbose', 'Prints debug info')
.option('--changelogpreset [preset]', 'The conventional-changelog preset to use. Default is angular. angular-bitbucket' +
' is available for BitBucket repositories. Other presets can be installed: npm i conventional-changelog-jquery')
Expand Down
4 changes: 4 additions & 0 deletions src/lib/validateBranch.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ const log = require('./log');
let shell = require('shelljs'); // Make this a variable to permit mocking during testing

module.exports = function validateBranch(branch) {
if (branch === '*') {
return null;
}

shell.exec('git branch').stdout;
let currentBranch = shell.exec('git rev-parse --abbrev-ref HEAD').stdout.split('\n')[0];

Expand Down

0 comments on commit cc29c2d

Please sign in to comment.