Skip to content

Commit

Permalink
feat(preset): add atom
Browse files Browse the repository at this point in the history
  • Loading branch information
stevemao committed Jul 17, 2015
1 parent 70b1a76 commit 714b694
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 0 deletions.
24 changes: 24 additions & 0 deletions conventions/atom.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## Git Commit Messages

* Use the present tense ("Add feature" not "Added feature")
* Use the imperative mood ("Move cursor to..." not "Moves cursor to...")
* Limit the first line to 72 characters or less
* Reference issues and pull requests liberally
* Consider starting the commit message with an applicable emoji:
* :art: `:art:` when improving the format/structure of the code
* :racehorse: `:racehorse:` when improving performance
* :non-potable_water: `:non-potable_water:` when plugging memory leaks
* :memo: `:memo:` when writing docs
* :penguin: `:penguin:` when fixing something on Linux
* :apple: `:apple:` when fixing something on Mac OS
* :checkered_flag: `:checkered_flag:` when fixing something on Windows
* :bug: `:bug:` when fixing a bug
* :fire: `:fire:` when removing code or files
* :green_heart: `:green_heart:` when fixing the CI build
* :white_check_mark: `:white_check_mark:` when adding tests
* :lock: `:lock:` when dealing with security
* :arrow_up: `:arrow_up:` when upgrading dependencies
* :arrow_down: `:arrow_down:` when downgrading dependencies
* :shirt: `:shirt:` when removing linter warnings

Based on https://github.com/atom/atom/blob/master/CONTRIBUTING.md#git-commit-messages
82 changes: 82 additions & 0 deletions presets/atom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
'use strict';
var dateFormat = require('dateformat');
var Q = require('q');
var readFile = Q.denodeify(require('fs').readFile);
var resolve = require('path').resolve;
var semver = require('semver');
var through = require('through2');

var regex = /tag:\s*[v=]?(.+?)[,\)]/gi;

function presetOpts(cb) {
var parserOpts = {
headerPattern: /^(:.*?:) (.*)$/,
headerCorrespondence: [
'emoji',
'shortDesc'
]
};

var transform = through.obj(function(chunk, enc, cb) {
if (typeof chunk.gitTags === 'string') {
var match = regex.exec(chunk.gitTags);
if (match) {
chunk.version = match[1];
}
}

if (chunk.committerDate) {
chunk.committerDate = dateFormat(chunk.committerDate, 'yyyy-mm-dd', true);
}

cb(null, chunk);
});

var writerOpts = {
transform: function(commit) {
var emojiLength;

if (!commit.emoji || typeof commit.emoji !== 'string') {
return;
}

commit.emoji = commit.emoji.substring(0, 72);
emojiLength = commit.emoji.length;

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

if (typeof commit.shortDesc === 'string') {
commit.shortDesc = commit.shortDesc.substring(0, 72 - emojiLength);
}

return commit;
},
groupBy: 'emoji',
commitGroupsSort: 'title',
commitsSort: ['emoji', 'shortDesc'],
generateOn: function(commit) {
return semver.valid(commit.version);
}
};

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

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

module.exports = presetOpts;
5 changes: 5 additions & 0 deletions templates/atom/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}}]({{@root.host}}/{{#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}}]({{@root.host}}/{{#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}}{{this.repository}}#{{this.issue}}{{/if}}{{/each}}{{/if}}
2 changes: 2 additions & 0 deletions templates/atom/header.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<a name="{{version}}"></a>
{{#if isPatch}}##{{else}}#{{/if}} {{version}}{{#if title}} "{{title}}"{{/if}}{{#if date}} ({{date}}){{/if}}
15 changes: 15 additions & 0 deletions templates/atom/template.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{> header}}

{{#each commitGroups}}

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

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



47 changes: 47 additions & 0 deletions test/atom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'use strict';
var conventionalChangelog = require('../');
var expect = require('chai').expect;
var shell = require('shelljs');
var through = require('through2');
var writeFileSync = require('fs').writeFileSync;

describe('presets', function() {
describe('atom', function() {
before(function() {
shell.cd('atom');
shell.exec('git init');
writeFileSync('test1', '');
shell.exec('git add --all && git commit -m":arrow_down: exception-reporting"');
writeFileSync('test2', '');
shell.exec('git add --all && git commit -m\':bug: `updateContentDimensions` when model changes\'');
writeFileSync('test3', '');
shell.exec('git add --all && git commit -m"Merge pull request #7881 from atom/bf-upgrade-babel-to-5.6.17"');
writeFileSync('test4', '');
shell.exec('git add --all && git commit -m":arrow_up: language-gfm@0.79.0"');
writeFileSync('test5', '');
shell.exec('git add --all && git commit -m":arrow_up: one-dark/light-ui@v1.0.1"');
});

after(function() {
shell.cd('../');
});

it('should work if there is no semver tag', function(done) {
conventionalChangelog({
preset: 'atom'
})
.pipe(through(function(chunk) {
chunk = chunk.toString();

expect(chunk).to.include(':arrow_down:');
expect(chunk).to.include('`updateContentDimensions` when model changes');
expect(chunk).to.include(':arrow_up:');
expect(chunk).to.include('one-dark/light-ui@v1.0.1');

expect(chunk).to.not.include('7881');

done();
}));
});
});
});
1 change: 1 addition & 0 deletions test/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ shell.mkdir('angular');
shell.mkdir('jquery');
shell.mkdir('jshint');
shell.mkdir('eslint');
shell.mkdir('atom');
shell.mkdir('cli');

0 comments on commit 714b694

Please sign in to comment.