Skip to content
This repository has been archived by the owner on Nov 21, 2017. It is now read-only.

Commit

Permalink
[[FEAT]] Extracting code from https://github.com/ajoslin/conventional…
Browse files Browse the repository at this point in the history
  • Loading branch information
stevemao committed Jan 30, 2016
0 parents commit 6684ba8
Show file tree
Hide file tree
Showing 13 changed files with 329 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
tmp
5 changes: 5 additions & 0 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"preset": "google",
"maximumLineLength": null,
"excludeFiles": ["node_modules/**"]
}
15 changes: 15 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"boss": true,
"curly": true,
"eqeqeq": true,
"eqnull": true,
"immed": true,
"latedef": true,
"mocha" : true,
"newcap": true,
"noarg": true,
"node": true,
"sub": true,
"undef": true,
"unused": true
}
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
language: node_js
node_js:
- '5'
- '4'
- '3'
- '2'
- '1'
- '0.12'
- '0.10'
before_script:
- git config --global user.name 'Travis-CI'
- git config --global user.email 'dummy@example.org'
after_script: NODE_ENV=test istanbul cover ./node_modules/mocha/bin/_mocha -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage
76 changes: 76 additions & 0 deletions convention.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
Commit Message Guidelines
-------------------------

### Overview

Commit messages are written in a simple format which clearly describes the purpose of a change.

The format in general should look like this:

```
[[TYPE]] <Short description>
<Blank line>
<Body / Detailed description>
<Footer>
```

Line lengths in commit messages are not strict, but good commit messages should have headers of no
more than 60 characters, and bodies/footers wrapped at 100 columns. This renders nicely on Github's
UI.

### Header

The first line is the commit message header, which will indicate the type of change, and a general
description of the change. This should fit within 60 characters, ideally. For instance:

```
[[FIX]] Ignore "nocomma" when parsing object literals
```

The title `[[FIX]]` indicates that the change is a bugfix, while the remainder clarifies what the
change actually contains.

Several commit types are used by jshint:

1. `[[FIX]]` --- Commit fixes a bug or regression
2. `[[FEAT]]` --- Commit introduces new functionality
3. `[[DOCS]]` --- Commit modifies documentation. Docs commits should only touch comments in source code, or scripts and assets which are used to generate the documentation.
4. `[[TEST]]` --- Commit modifies tests or test infrastructure only
5. `[[CHORE]]` --- Commit affects dev-ops, CI, or package dependencies

### Body

`<Body>` is a detailed commit message explaining exactly what has changed, and a summary of the
reason why. Lines in the body should be wrapped to 100 characters for best rendering.

For a historical example, see this [example](https://github.com/jshint/jshint/commit/5751c5ed249b7a035758a3ae876cfa1a360fd144)

### Footer

`<Footer>` contains a description of any breaking changes, no matter how subtle, as well as a list
of issues affected or fixed by this commit. Lines in the footer should be wrapped to 100 characters
for best rendering.

For instance:

```
[[FEAT]] Enable `norecurs` option by default
Commit 124124a7f introduced an option which forbids recursion. We liked it so much, we've enabled
it by default.
BREAKING CHANGE:
This change will break the CI builds of many applications and frameworks.
In order to work around this issue, you will need to re-engineer your applications and frameworks
to avoid making recursive calls. Use Arrays as stacks rather than relying on the VM call stack.
Fixes #1000009
Closes #888888
Closes #77777
```

Based on https://github.com/jshint/jshint/blob/master/CONTRIBUTING.md#commit-message-guidelines
67 changes: 67 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
'use strict';
var compareFunc = require('compare-func');
var Q = require('q');
var readFile = Q.denodeify(require('fs').readFile);
var resolve = require('path').resolve;

function presetOpts(cb) {
var parserOpts = {
headerPattern: /^\[\[(.*)]] (.*)$/,
headerCorrespondence: [
'type',
'shortDesc'
],
noteKeywords: 'BREAKING CHANGE'
};

var writerOpts = {
transform: function(commit) {
var type = commit.type ? commit.type.toUpperCase() : '';

if (type === 'FEAT') {
commit.type = 'Features';
} else if (type === 'FIX') {
commit.type = 'Bug Fixes';
} else {
return;
}

if (typeof commit.hash === 'string') {
commit.hash = commit.hash.substring(0, 7);
}

commit.notes.forEach(function(note) {
if (note.title === 'BREAKING CHANGE') {
note.title = 'BREAKING CHANGES';
}
});

return commit;
},
groupBy: 'type',
commitGroupsSort: 'title',
commitsSort: ['type', 'shortDesc'],
noteGroupsSort: 'title',
notesSort: compareFunc
};

Q.all([
readFile(resolve(__dirname, 'templates/template.hbs'), 'utf-8'),
readFile(resolve(__dirname, 'templates/header.hbs'), 'utf-8'),
readFile(resolve(__dirname, 'templates/commit.hbs'), 'utf-8'),
readFile(resolve(__dirname, 'templates/footer.hbs'), 'utf-8')
])
.spread(function(template, header, commit, footer) {
writerOpts.mainTemplate = template;
writerOpts.headerPartial = header;
writerOpts.commitPartial = commit;
writerOpts.footerPartial = footer;

cb(null, {
parserOpts: parserOpts,
writerOpts: writerOpts
});
});
}

module.exports = presetOpts;
41 changes: 41 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "conventional-changelog-jshint",
"version": "0.0.0",
"description": "conventional-changelog jshint preset",
"main": "index.js",
"scripts": {
"coverage": "istanbul cover _mocha -- -R spec && rm -rf ./coverage",
"lint": "jshint *.js --exclude node_modules && jscs *.js",
"test": "mocha --timeout 30000 && npm run-script lint"
},
"repository": {
"type": "git",
"url": "git+https://github.com/stevemao/conventional-changelog-jshint.git"
},
"keywords": [
"conventional-changelog",
"jshint",
"preset"
],
"author": "Steve Mao",
"license": "ISC",
"bugs": {
"url": "https://github.com/stevemao/conventional-changelog-jshint/issues"
},
"homepage": "https://github.com/stevemao/conventional-changelog-jshint#readme",
"devDependencies": {
"chai": "^3.5.0",
"conventional-changelog-core": "0.0.2",
"coveralls": "^2.11.6",
"istanbul": "^0.4.2",
"jscs": "^2.9.0",
"jshint": "^2.9.1",
"mocha": "*",
"shelljs": "^0.5.3",
"through2": "^2.0.0"
},
"dependencies": {
"compare-func": "^1.3.1",
"q": "^1.4.1"
}
}
16 changes: 16 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url] [![Coverage Status][coveralls-image]][coveralls-url]

> [conventional-changelog](https://github.com/ajoslin/conventional-changelog) [jshint](https://github.com/jshint/jshint) preset

See [convention](convention.md)


[npm-image]: https://badge.fury.io/js/conventional-changelog-jshint.svg
[npm-url]: https://npmjs.org/package/conventional-changelog-jshint
[travis-image]: https://travis-ci.org/stevemao/conventional-changelog-jshint.svg?branch=master
[travis-url]: https://travis-ci.org/stevemao/conventional-changelog-jshint
[daviddm-image]: https://david-dm.org/stevemao/conventional-changelog-jshint.svg?theme=shields.io
[daviddm-url]: https://david-dm.org/stevemao/conventional-changelog-jshint
[coveralls-image]: https://coveralls.io/repos/stevemao/conventional-changelog-jshint/badge.svg
[coveralls-url]: https://coveralls.io/r/stevemao/conventional-changelog-jshint
5 changes: 5 additions & 0 deletions templates/commit.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* {{#if shortDesc}}{{shortDesc}}{{else}}{{header}}{{/if}}

{{~!-- commit hash --}} {{#if @root.linkReferences}}([{{hash}}]({{#if @root.host}}{{@root.host}}/{{/if}}{{#if @root.owner}}{{@root.owner}}/{{/if}}{{@root.repository}}/{{@root.commit}}/{{hash}})){{else}}{{hash~}}{{/if}}

{{~!-- commit references --}}{{#if references}}, closes{{~#each references}} {{#if @root.linkReferences}}[{{#if this.owner}}{{this.owner}}/{{/if}}{{this.repository}}#{{this.issue}}]({{#if @root.host}}{{@root.host}}/{{/if}}{{#if this.repository}}{{#if this.owner}}{{this.owner}}/{{/if}}{{this.repository}}{{else}}{{#if @root.owner}}{{@root.owner}}/{{/if}}{{@root.repository}}{{/if}}/{{@root.issue}}/{{this.issue}}){{else}}{{#if this.owner}}{{this.owner}}/{{/if}}{{this.repository}}#{{this.issue}}{{/if}}{{/each}}{{/if}}
11 changes: 11 additions & 0 deletions templates/footer.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{#if noteGroups}}
{{#each noteGroups}}

### {{title}}

{{#each notes}}
* {{#if commit.scope}}{{commit.scope}}: {{/if}}{{text}}
{{/each}}
{{/each}}

{{/if}}
2 changes: 2 additions & 0 deletions templates/header.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<a name="{{version}}"></a>
{{#if isPatch}}##{{else}}#{{/if}} {{#if @root.linkCompare}}[{{version}}]({{@root.host}}/{{#if @root.owner}}{{@root.owner}}/{{/if}}{{@root.repository}}/compare/{{previousTag}}...{{currentTag}}){{else}}{{version}}{{/if}}{{#if title}} "{{title}}"{{/if}}{{#if date}} ({{date}}){{/if}}
16 changes: 16 additions & 0 deletions templates/template.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{> header}}

{{#each commitGroups}}

{{#if title}}
### {{title}}

{{/if}}
{{#each commits}}
{{> commit root=@root}}
{{/each}}
{{/each}}

{{> footer}}


60 changes: 60 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
'use strict';
var child = require('child_process');
var conventionalChangelogCore = require('conventional-changelog-core');
var config = require('./');
var expect = require('chai').expect;
var shell = require('shelljs');
var through = require('through2');
var writeFileSync = require('fs').writeFileSync;

describe('jshint preset', function() {
before(function(done) {
shell.config.silent = true;
shell.rm('-rf', 'tmp');
shell.mkdir('tmp');
shell.cd('tmp');
shell.mkdir('git-templates');
shell.exec('git init --template=./git-templates');

writeFileSync('test1', '');
shell.exec('git add --all && git commit -m"[[Chore]] Move scope-manager to external file"');
writeFileSync('test2', '');
shell.exec('git add --all && git commit -m"[[Test]] Add test for gh-985. Fixes #985"');
writeFileSync('test3', '');
shell.exec('git add --all && git commit -m"[[FIX]] catch params are scoped to the catch only"');
shell.exec('git commit --allow-empty -m"[[Fix]] accidentally use lower-case"');
writeFileSync('test4', '');
child.exec('git add --all && git commit -m"[[FEAT]] Option to assume strict mode\n\nBREAKING CHANGE: Not backward compatible."', function() {
writeFileSync('test5', '');
shell.exec('git add --all && git commit -m"Bad commit"');

done();
});
});

it('should work if there is no semver tag', function(done) {
conventionalChangelogCore({
config: config
})
.on('error', function(err) {
done(err);
})
.pipe(through(function(chunk) {
chunk = chunk.toString();

expect(chunk).to.include('catch params are scoped to the catch only');
expect(chunk).to.include('### Bug Fixes');
expect(chunk).to.include('Option to assume strict mode');
expect(chunk).to.include('accidentally use lower-case');
expect(chunk).to.include('### Features');
expect(chunk).to.include('BREAKING CHANGES');

expect(chunk).to.not.include('Chore');
expect(chunk).to.not.include('Move scope-manager to external file');
expect(chunk).to.not.include('Add test for gh-985.');
expect(chunk).to.not.include('Bad');

done();
}));
});
});

0 comments on commit 6684ba8

Please sign in to comment.