Skip to content

Commit 62a3607

Browse files
committed
Release notes main js
1 parent a8f4443 commit 62a3607

File tree

1 file changed

+119
-0
lines changed

1 file changed

+119
-0
lines changed

github-release-notes.js

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
'use strict';
2+
3+
var Github = require('github-api');
4+
var options = getOptions(process.argv);
5+
var token = options.token;
6+
var username = options.username;
7+
var repositoryName = options.repo;
8+
var github = new Github({
9+
token: token,
10+
auth: "oauth"
11+
});
12+
var repo = github.getRepo(username, repositoryName);
13+
14+
/**
15+
* Create a literal object of the node module options
16+
*
17+
* @param {Array} args The array of arguments (the module arguments start from index 2)
18+
*
19+
* @return {Object} The object containg the key/value options
20+
*/
21+
function getOptions(args) {
22+
var settings = {};
23+
24+
for(var i=2;i<args.length;i++) {
25+
settings[args[i].split('=')[0].replace('--', '')] = args[i].split('=')[1];
26+
}
27+
28+
return settings;
29+
}
30+
31+
/**
32+
* Get all the tags of the repo
33+
*
34+
* @return {Promise}
35+
*/
36+
function getAllTags() {
37+
return new Promise(function (resolve, reject) {
38+
repo.listTags(function(err, tags) {
39+
if(err) {
40+
reject(err);
41+
} else {
42+
resolve(tags);
43+
}
44+
});
45+
});
46+
}
47+
48+
function createBody(message) {
49+
return '- ' + message;
50+
}
51+
52+
function commitMessages(commits) {
53+
return commits.map(function (commit) {
54+
return commit.commit.message;
55+
});
56+
}
57+
58+
function getCommitsBetweenTwo(since, until) {
59+
var options = {
60+
since: since,
61+
until: until
62+
};
63+
64+
return new Promise(function (resolve, reject) {
65+
66+
repo.getCommits(options, function (err, commits) {
67+
if(err) {
68+
reject(err);
69+
} else {
70+
resolve(commitMessages(commits));
71+
}
72+
});
73+
});
74+
}
75+
76+
function getTagDates(tags) {
77+
return [tags[0], tags[1]].map(function(tag) {
78+
return new Promise(function (resolve, reject) {
79+
repo.getCommit('master', tag.commit.sha, function(err, commit) {
80+
if(err) {
81+
reject(err);
82+
} else {
83+
resolve(commit.committer.date);
84+
}
85+
});
86+
});
87+
})
88+
}
89+
90+
function makeRelease(options) {
91+
repo.makeRelease(options, function (err, release) {
92+
if(err) {
93+
console.error(err);
94+
} else {
95+
console.info(release);
96+
}
97+
});
98+
}
99+
100+
getAllTags().then(function(tags) {
101+
Promise.all(getTagDates(tags))
102+
.then(function(data) {
103+
getCommitsBetweenTwo(data[1], data[0]).then(function (commitMessages) {
104+
var body = commitMessages.filter(function(message) {
105+
return !message.match('Merge');
106+
}).map(createBody);
107+
108+
body.pop();
109+
110+
var options = {
111+
tag_name: tags[0].name,
112+
name: tags[0].name,
113+
body: body.join('\n')
114+
};
115+
116+
makeRelease(options);
117+
});
118+
});
119+
});

0 commit comments

Comments
 (0)