FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat: use cz-conventional-changelog as default adapter by felipecrs · Pull Request #794 · commitizen/cz-cli · GitHub

Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .js  (2) .json  (2) .md  (1) All 3 file types selected
Only manifest files
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
8 changes: 4 additions & 4 deletions README.md
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
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ When you're working in a Commitizen friendly repository, you'll be prompted to f

[![Add and commit with Commitizen](https://github.com/commitizen/cz-cli/raw/master/meta/screenshots/add-commit.png)](https://github.com/commitizen/cz-cli/raw/master/meta/screenshots/add-commit.png)

### If your repo is NOT Commitizen friendly:
### If your repo is NOT Commitizen-friendly

If you're **not** working in a Commitizen friendly repository, then `git cz` will work just the same as `git commit` but `npx cz` will use the [streamich/git-cz](https://github.com/streamich/git-cz) adapter. To fix this, you need to first [make your repo Commitizen-friendly](#making-your-repo-commitizen-friendly)
If you're **not** working in a Commitizen friendly repository, then `git cz` will work just the same as `git commit` but `npx cz` will use the [cz-conventional-changelog](https://github.com/commitizen/cz-conventional-changelog) adapter. To fix this, you need to first [make your repo Commitizen-friendly](#making-your-repo-commitizen-friendly).

## Making your repo Commitizen-friendly

For this example, we'll be setting up our repo to use [AngularJS's commit message convention](https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#-git-commit-guidelines) also known as [conventional-changelog](https://github.com/ajoslin/conventional-changelog).
For this example, we'll be setting up our repo to use [Conventional Commits convention](https://www.conventionalcommits.org/) through the [conventional-changelog](https://github.com/conventional-changelog/conventional-changelog) [commitizen adapter](https://github.com/commitizen/cz-conventional-changelog).

First, install the Commitizen cli tools:

Expand Down Expand Up @@ -86,7 +86,7 @@ The above command does three things for you.
}
```

Alternatively, commitizen configs may be added to a .czrc file:
Alternatively, commitizen configs may be added to a `.czrc` or `.cz.json` file:

```json
{
Expand Down
164 changes: 85 additions & 79 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
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
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
},
"dependencies": {
"cachedir": "2.2.0",
"cz-conventional-changelog": "3.2.0",
"cz-conventional-changelog": "3.3.0",
"dedent": "0.7.0",
"detect-indent": "6.0.0",
"find-node-modules": "2.0.0",
Expand Down
15 changes: 4 additions & 11 deletions src/cli/git-cz.js
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { configLoader } from '../commitizen';
import { git as useGitStrategy, gitCz as useGitCzStrategy } from './strategies';
import { gitCz as useGitCzStrategy } from './strategies';

export {
bootstrap
Expand All @@ -9,19 +9,12 @@ export {
* This is the main cli entry point.
* environment may be used for debugging.
*/
function bootstrap (environment = {}, argv = process.argv) {
function bootstrap(environment = {}, argv = process.argv) {

// Get cli args
let rawGitArgs = argv.slice(2, argv.length);

let adapterConfig = environment.config || configLoader.load();
let adapterConfig = environment.config || configLoader.load() || { path: 'cz-conventional-changelog' };

// Choose a strategy based on the existance the adapter config
if (typeof adapterConfig !== 'undefined') {
// This tells commitizen we're in business
useGitCzStrategy(rawGitArgs, environment, adapterConfig);
} else {
// This tells commitizen that it is not needed, just use git
useGitStrategy(rawGitArgs, environment);
}
useGitCzStrategy(rawGitArgs, environment, adapterConfig);
}
8 changes: 4 additions & 4 deletions test/tests/cli.js
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ describe('git-cz', () => {

beforeEach(() => {
fakeStrategies = {
git: sinon.spy(),
gitCz: sinon.spy()
}

Expand Down Expand Up @@ -49,17 +48,18 @@ describe('git-cz', () => {
});

describe('and the config is not returned from configLoader.load', () => {
it('tells commitizen to use the git strategy', () => {
it('tells commitizen to use the default adapter', () => {
bootstrap({});
expect(fakeStrategies.git.called).to.equal(true);

expect(fakeStrategies.gitCz.args[0][2].path).to.equal('cz-conventional-changelog');
});
});
});

describe('when argv is overridden', () => {
it('uses the overridden argv', () => {
bootstrap({}, ['node', 'git-cz', 'index.js']);
expect(fakeStrategies.git.args[0][0][0]).to.equal('index.js');
expect(fakeStrategies.gitCz.args[0][0][0]).to.equal('index.js');
});
})
});
Expand Down

Back | FazBrowse Home | New Git URL