Skip to content

Commit

Permalink
refactor: removed deprecated options
Browse files Browse the repository at this point in the history
  • Loading branch information
rafinskipg committed Apr 18, 2015
1 parent a2efaf5 commit 7d05b63
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 29 deletions.
7 changes: 3 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<a name="">My app - Changelog</a>
<a name="">my name</a>
# (2015-04-18)


## Bug Fixes

- Github commit url
([c186f2d8](https://github.com/rafinskipg/git-changelog/commit/c186f2d877e7907305953610bcaaef331406178a)
---
<sub><sup>*Generated with [git-changelog](https://github.com/rafinskipg/git-changelog). If you have any problem or suggestion, create an issue.* :) **Thanks** </sub></sup>
2 changes: 1 addition & 1 deletion EXTENDEDCHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<a name="">Git changelog extended</a>
<a name="">My app - Changelog</a>
# (2015-04-18)


Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ grunt.initConfig({
* **repo_url** : The url of the project. For issues and commits links. Defaults to `git config --get remote.origin.url`
* **version**: The version of the project. Defaults to ` `,
* **file**: The name of the file that will be generated. Defaults to `CHANGELOG.md`,
* **appName** (DEPRECATED: Use app_name) : The name of the project. Defaults to `My App - Changelog`
* **app_name** : The name of the project. Defaults to `My App - Changelog`
* **ignore_tags** (DEPRECATED, use tag option): Ignore tags, read from the beggining of the history. Defaults to `false`
* **grep_commits**: The commits that will be picked. Defaults to `'^fix|^feat|^docs|^refactor|^chore|BREAKING'`
* **tag**: You can select from which tag to generate the log, it defaults to the last one. Set it to false for log since the beggining of the project
* **debug**: Debug mode, false by default
Expand Down
6 changes: 3 additions & 3 deletions tasks/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@


'use strict';
var _ = require('lodash');

var program = require('commander');
var git_changelog = require('./git_changelog_generate');
var options = _.cloneDeep(require('./defaults'));
var options = {};

if (process.argv.join('').indexOf('/grunt') === -1) {

Expand All @@ -24,7 +24,7 @@ if (process.argv.join('').indexOf('/grunt') === -1) {
console.log('Executing git changelog:');
if (program.extended){
console.log(' - Extended, getting log since the BigBang');
options.ignore_tags = true;
options.tag = false;
}

if (program.app_name){
Expand Down
2 changes: 0 additions & 2 deletions tasks/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ module.exports = {
grep_commits: '^fix|^feat|^docs|BREAKING',
tag: null,
debug: false,
//TODO : remove ignore tags
ignore_tags: false,
sections: [
{
title: 'Bug Fixes',
Expand Down
37 changes: 24 additions & 13 deletions tasks/git_changelog_generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*/

var child = require('child_process');
var defaults = require('./defaults');
var _ = require('lodash');
var fs = require('fs');
var util = require('util');
var q = require('q');
Expand All @@ -20,16 +22,26 @@ var PROVIDER, GIT_LOG_CMD, GIT_NOTAG_LOG_CMD,
EMPTY_COMPONENT = '$$';

// I have to clean that mess

function initOptions(params){
OPTS = _.defaults(params, defaults);
OPTS.msg = 'name: '+ OPTS.app_name +';';
OPTS.msg += 'file: '+ OPTS.file +';';
OPTS.msg += 'grep_commits: '+ OPTS.grep_commits +';';
OPTS.msg += 'debug: '+ OPTS.debug +';';
OPTS.msg += 'version: '+ OPTS.version +';';
}

var init = function(params){
var deferred = q.defer();

OPTS = params;
OPTS.msg = '';
initOptions(params);

getRepoUrl().then(function(url){
OPTS.repo_url = url;
OPTS.msg += 'remote: '+ OPTS.repo_url+';';

//G \ B \ ---
//G \ B \ ---
PROVIDER = OPTS.repo_url.indexOf('github.com') !== -1 ? 'G' :'B';

//Log commits
Expand All @@ -47,7 +59,6 @@ var init = function(params){
B: '[%s]('+OPTS.repo_url+'/commits/%s)'})
[PROVIDER];

OPTS.msg += 'found remote;';
deferred.resolve(OPTS);
})
.catch(function(){
Expand All @@ -59,13 +70,6 @@ var init = function(params){
};




var warn = function() {
console.log('WARNING:', util.format.apply(null, arguments));
};


var parseRawCommit = function(raw) {
if (!raw) { return null; }

Expand Down Expand Up @@ -214,7 +218,7 @@ var writeChangelog = function(stream, commits) {

organizeCommitsInSections(commits, sections)

stream.write(util.format(HEADER_TPL, OPTS.version, OPTS.appName || OPTS.app_name, OPTS.version, currentDate()));
stream.write(util.format(HEADER_TPL, OPTS.version, OPTS.app_name, OPTS.version, currentDate()));
printSection(stream, 'Bug Fixes', sections.fix);
printSection(stream, 'Features', sections.feat);
printSection(stream, 'Refactor', sections.refactor, false);
Expand Down Expand Up @@ -305,7 +309,7 @@ var generate = function(params) {

if(typeof(tag) !== 'undefined' && tag !== false && !OPTS.ignore_tags){
log('Reading git log since', tag);
OPTS.msg += 'since tag:'+ tag +';';
OPTS.msg += 'since tag: '+ tag +';';
fn = function(){ return readGitLog(GIT_LOG_CMD, tag);};
}else{
log('Reading git log since the beggining');
Expand Down Expand Up @@ -337,6 +341,13 @@ function log(){
}
}

var warn = function() {
if(OPTS.debug){
console.log('WARNING:', util.format.apply(null, arguments));
}
};


// publish for testing
exports.parseRawCommit = parseRawCommit;
exports.organizeCommitsInSections = organizeCommitsInSections;
Expand Down
43 changes: 39 additions & 4 deletions test/changelog.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,9 @@ describe('changelog.js', function() {
describe('Params tests', function() {
it('should read log since beggining if tag is false', function(done) {

var options = _.cloneDeep(defaults);

options.tag = false;
options.name = 'my name';
var options = {
tag : false
};

ch.generate(options)
.then(function(opts){
Expand All @@ -128,5 +127,41 @@ describe('changelog.js', function() {
console.log('error', err);
})
});

it('should read log since specified tag if tag is present', function(done) {

var options = {
tag : 'v0.0.1'
};

ch.generate(options)
.then(function(opts){
expect(opts.msg).to.be.a('string');
expect(opts.msg.indexOf('tag: v0.0.1')).to.not.equal(-1);
done();
})
.catch(function(err){
console.log('error', err);
})
});

it('should add the application name', function(done) {

var options = {
app_name : 'my name'
};

ch.generate(options)
.then(function(opts){
expect(opts.msg).to.be.a('string');
expect(opts.msg.indexOf('name: my name')).to.not.equal(-1);
done();
})
.catch(function(err){
console.log('error', err);
})
});


});
});

0 comments on commit 7d05b63

Please sign in to comment.