Skip to content

Commit 725208c

Browse files
committed
Template working
1 parent 9cb784d commit 725208c

File tree

6 files changed

+92
-71
lines changed

6 files changed

+92
-71
lines changed

CHANGELOG.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# my name
2+
3+
## ( )
4+
5+
6+
## Bug Fixes
7+
8+
9+
- **git tag**
10+
11+
- get latest tag, regardless of branch for workflows that rely on git-flow releases (48800306fa5ac19b7e9a4c6d7f2f432ee8ae4d84)
12+
13+
14+
15+
16+
17+
<sub><sup>*Generated with [git-changelog](https://github.com/rafinskipg/git-changelog). If you have any problems or suggestions, create an issue.* :) **Thanks** </sub></sup>

tasks/lib/load-template.js

-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ function loadTemplateFile(data) {
4949
try{
5050
var fn = _.template(contents, data);
5151
var tpl = fn(data)
52-
console.log(tpl)
5352
return tpl
5453
}catch(e){
5554
module.log('warn', 'Invalid template file', e);

tasks/lib/write-change-log.js

+18-10
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,9 @@ function writeChangelog(options, commits, sectionsdef) {
3131
debug('writing change log');
3232

3333
var sections = this.organizeCommits(commits, this.options.sections);
34-
34+
3535
var stream;
3636

37-
if (module.options.file) {
38-
stream = fse.createOutputStream(module.options.file);
39-
} else {
40-
stream = process.stdout;
41-
}
4237

4338
console.log(module.options)
4439

@@ -55,16 +50,29 @@ function writeChangelog(options, commits, sectionsdef) {
5550

5651

5752
return new Promise(function(resolve, reject){
58-
this.loadTemplate(data)
53+
54+
module.loadTemplate(data)
5955
.then(function(template){
56+
57+
if (module.options.file) {
58+
stream = fse.createOutputStream(module.options.file);
59+
} else {
60+
stream = process.stdout;
61+
}
62+
6063
if(template){
6164
console.log('Proceding with template')
6265

6366
stream.on('open', function(){
64-
stream.write(template);
65-
console.
67+
var lines = template.split('\n');
68+
console.log(lines)
69+
lines.forEach(function(line){
70+
stream.write(line);
71+
stream.write('\n');
72+
})
73+
console.log('ehe')
6674
stream.end();
67-
resolve();
75+
stream.on('finish', resolve)
6876
});
6977

7078
}else {

templates/template.md

+5-16
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,18 @@
1-
<% if(logo) { %>
2-
<img width="300px" src="<%= logo %>" />
3-
<% } %>
4-
5-
# <%= title %>
6-
7-
<% if(intro) { %>
8-
_<%= intro %>_
9-
<% } %>
10-
11-
<% if(version) { %>
12-
## <%= version.name %> <%= version.number %> ( <%= version.date %> )
13-
<% } %>
14-
1+
<% if(logo) { %><img width="300px" src="<%= logo %>" /><%= '\n' %><% } %># <%= title %>
2+
<% if(intro) { %>_<%= intro %>_<%= '\n' %><% } %>
3+
<% if(version) { %>## <%= version.name %> <%= version.number %> ( <%= version.date %> )<%= '\n' %><% } %>
154
<% _.forEach(sections, function(section){
165
if(section.commitsCount > 0) { %>
176
## <%= section.title %>
187
<% _.forEach(section.commits, function(commit){ %>
198
- <%= commit.subject %> (<%= commit.hash %><% if(commit.closes.length){ %>, Closes: <%= getCommitCloses(commit).join(',') %><% } %>
209
<% }) %>
2110
<% _.forEach(section.components, function(component){ %>
22-
- <%= component.name %>
11+
- **<%= component.name %>**
2312
<% _.forEach(component.commits, function(commit){ %>
2413
- <%= commit.subject %> (<%= commit.hash %><% if(commit.closes.length){ %>, Closes: <%= getCommitCloses(commit).join(',') %><% } %>)
2514
<% }) %>
2615
<% }) %>
16+
<% } %>
2717
<% }) %>
28-
2918
<sub><sup>*Generated with [git-changelog](https://github.com/rafinskipg/git-changelog). If you have any problems or suggestions, create an issue.* :) **Thanks** </sub></sup>

test/fixtures/commits.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ exports.withBreaking = [
8484
component: '$scope' },
8585
{
8686
closes: [],
87-
breaks: [],
87+
breaks: [3, 4],
8888
hash: '1d4f604363094d4eee3b4d7b1ca01133edaad344',
8989
subject: 'did 4 thing',
9090
body: '',
@@ -93,7 +93,7 @@ exports.withBreaking = [
9393
},
9494
{
9595
closes: [],
96-
breaks: [],
96+
breaks: [2,3],
9797
hash: '1d4f604363094d4eee3b4d7b1ca01133edaad344',
9898
subject: 'did 5 thing',
9999
body: '',

test/git_changelog_generate.spec.js

+50-42
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,11 @@ describe('git_changelog_generate.js', function() {
605605
});
606606

607607
describe('.organizeCommits()', function() {
608-
608+
function findItem(key, value){
609+
return function (item){
610+
return item[key] === value
611+
}
612+
}
609613
describe('without breaking commits', function () {
610614

611615
before(function() {
@@ -649,15 +653,10 @@ describe('git_changelog_generate.js', function() {
649653
this.sections = changelog.organizeCommits(this.commits, this.sections);
650654
});
651655

652-
it('should return 8 sections', function() {
653-
expect(this.sections.length).to.equal(8);
656+
it('should return 3 sections', function() {
657+
expect(this.sections.length).to.equal(3);
654658
});
655659

656-
function findItem(key, value){
657-
return function (item){
658-
return item[key] === value
659-
}
660-
}
661660
it('should fix section to have 1 commit', function() {
662661
expect(this.sections.find(findItem('type', 'fix')).components.find(findItem('name', '$scope')).commits.length).to.equal(1);
663662
});
@@ -696,16 +695,40 @@ describe('git_changelog_generate.js', function() {
696695

697696
before(function() {
698697
changelog.setDefaults();
699-
this.sections = {
700-
fix: {},
701-
feat: {},
702-
BREAKING: {},
703-
style: {},
704-
refactor: {},
705-
test: {},
706-
chore: {},
707-
docs: {}
708-
};
698+
this.sections = [
699+
{
700+
title: 'Bug Fixes',
701+
grep: '^fix'
702+
},
703+
{
704+
title: 'Features',
705+
grep: '^feat'
706+
},
707+
{
708+
title: 'Documentation',
709+
grep: '^docs'
710+
},
711+
{
712+
title: 'Breaking changes',
713+
grep: 'BREAKING'
714+
},
715+
{
716+
title: 'Refactor',
717+
grep: '^refactor'
718+
},
719+
{
720+
title: 'Style',
721+
grep: '^style'
722+
},
723+
{
724+
title: 'Test',
725+
grep: '^test'
726+
},
727+
{
728+
title: 'Chore',
729+
grep: '^chore'
730+
}
731+
];
709732
var repo_url = 'https://github.com/owner/repo';
710733
changelog.options.repo_url = repo_url;
711734
changelog.getProviderLinks();
@@ -714,40 +737,25 @@ describe('git_changelog_generate.js', function() {
714737
this.sections = changelog.organizeCommits(this.commits, this.sections);
715738
});
716739

717-
it('should return 8 sections', function() {
718-
expect(Object.keys(this.sections).length).to.equal(8);
740+
it('should return 4 sections', function() {
741+
expect(this.sections.length).to.equal(4);
719742
});
720743

721744
it('should fix section to have 1 commit', function() {
722-
expect(this.sections.fix.$scope.length).to.equal(1);
745+
expect(this.sections.find(findItem('type', 'fix')).components.find(findItem('name', '$scope')).commits.length).to.equal(1);
723746
});
724747

725748
it('should feat section to have 1 commit', function() {
726-
expect(this.sections.feat.$scope.length).to.equal(1);
727-
});
728-
729-
it('should breaks section to be empty', function() {
730-
expect(this.sections.BREAKING.$scope.length).to.equal(1);
731-
});
732-
733-
it('should style section to be empty', function() {
734-
expect(this.sections.style).to.deep.equal({});
735-
});
736-
737-
it('should refactor section be empty', function() {
738-
expect(this.sections.refactor).to.deep.equal({});
749+
expect(this.sections.find(findItem('type', 'feat')).components.find(findItem('name', '$scope')).commits.length).to.equal(1);
739750
});
740751

741-
it('should test section to be empty', function() {
742-
expect(this.sections.test).to.deep.equal({});
752+
it('should breaks have 1 component and 2 comits', function() {
753+
expect(this.sections.find(findItem('type', 'BREAKING')).components.length).to.equals(1);
754+
expect(this.sections.find(findItem('type', 'BREAKING')).components.find(findItem('name', '$scope')).commits.length).to.equal(1);
743755
});
744756

745-
it('should chore section to have 1 commit', function() {
746-
expect(this.sections.chore.$scope.length).to.equal(3);
747-
});
748-
749-
it('should docs section to be empty', function() {
750-
expect(this.sections.docs).to.deep.equal({});
757+
it('should chore section to have 3 commit', function() {
758+
expect(this.sections.find(findItem('type', 'chore')).components.find(findItem('name', '$scope')).commits.length).to.equal(3);
751759
});
752760

753761
});

0 commit comments

Comments
 (0)