This repository has been archived by the owner on Nov 27, 2018. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 91
/
changelog.js
86 lines (71 loc) · 2.96 KB
/
changelog.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*global config:true, task:true*/
module.exports = function(grunt) {
grunt.registerTask('changelog', 'Generate changelog for milestone', function() {
this.requiresConfig('changelog.user', 'changelog.repo');
var options = grunt.config(this.name);
if(!options.dest) options.dest = 'CHANGELOG';
if(!options.labels) options.labels = ['bug', 'enhancement'];
console.log('Labels: ' + options.labels);
var GitHubApi = require("github");
var github = new GitHubApi({
version: "3.0.0"
});
var done = this.async();
github.issues.getAllMilestones({
user: options.user,
repo: options.repo,
state: 'closed',
sort: 'completeness'
}, function(err, res) {
if(err) {
grunt.log.error('repo "'+options.user+'/'+options.repo+'" not found!');
done(false);
}
function writeFile() {
var lines = [], line,
moment = require('moment'),
fs = require('fs');
lines.push(options.repo+' change log');
lines.push('=============================');
res.forEach(function(ms){
lines.push("\r\n");
lines.push('Version '+ms.title + (ms.due_on ? ' '+moment(ms.due_on).format('MMM D, YYYY') : ''));
lines.push('----------------------------');
var issueLines = [];
ms.issues.forEach(function(issue) {
var labels = [];
issue.labels.forEach(function(e, i, arr) {
if(options.labels.indexOf(e.name) >= 0) {
labels.push(e.name);
}
});
if(labels.length) {
issueLines.push('['+labels.join(',') + '] #'+issue.number+': '+issue.title+' (' + (issue.assignee ? ('@'+issue.assignee.login) : '') + ')');
}
});
lines = lines.concat(issueLines);
console.log('Loaded issues for ' + ms.title + ': ' + issueLines.length);
});
fs.writeFileSync(options.dest, lines.join("\r\n"), 'utf8');
}
var finished = 0;
res.forEach(function(ms){
github.issues.repoIssues({
user: options.user,
repo: options.repo,
milestone: ms.number,
state: 'closed'
}, (function(r) {
return function(err2, issues) {
r.issues = issues;
finished++;
if(finished == res.length) {
writeFile();
done(true);
}
}
})(ms));
});
});
});
};