Skip to content

Commit 5f4f9c5

Browse files
committed
Change the default settings, fix the prepareRelease function binding the tags
1 parent 3da2005 commit 5f4f9c5

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

github-release-notes.js

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var options = getOptions(process.argv);
55
var token = options.token;
66
var username = options.username;
77
var repositoryName = options.repo;
8+
var releasePrefix = options.prefix || '';
89
var github = new Github({
910
token: token,
1011
auth: "oauth"
@@ -47,9 +48,9 @@ function getAllTags() {
4748

4849
/**
4950
* Return a string with a - to be a bullet list (used for a mapping)
50-
*
51+
*
5152
* @param {string} message
52-
*
53+
*
5354
* @return {string}
5455
*/
5556
function createBody(message) {
@@ -58,9 +59,9 @@ function createBody(message) {
5859

5960
/**
6061
* Transforms the commits to commit messages
61-
*
62+
*
6263
* @param {[Object]} commits The array of object containing the commits
63-
*
64+
*
6465
* @return {[string]}
6566
*/
6667
function commitMessages(commits) {
@@ -71,10 +72,10 @@ function commitMessages(commits) {
7172

7273
/**
7374
* Gets all the commits between two dates
74-
*
75+
*
7576
* @param {string} since The since date in ISO
7677
* @param {string} until The until date in ISO
77-
*
78+
*
7879
* @return {Promise} The promise which resolves the commit messages
7980
*/
8081
function getCommitsBetweenTwo(since, until) {
@@ -97,7 +98,7 @@ function getCommitsBetweenTwo(since, until) {
9798

9899
/**
99100
* Get the dates of the last two tags
100-
*
101+
*
101102
* @param {[Object]} tags List of all the tags in the repo
102103
* @return {[Promise]} The promises which returns the dates
103104
*/
@@ -117,7 +118,7 @@ function getTagDates(tags) {
117118

118119
/**
119120
* Create a release from a given tag (in the options)
120-
*
121+
*
121122
* @param {Object} options The options to build the release:
122123
* {
123124
* "tag_name": "v1.0.0",
@@ -128,8 +129,8 @@ function getTagDates(tags) {
128129
* "prerelease": false
129130
* }
130131
*/
131-
function makeRelease(options) {
132-
repo.makeRelease(options, function (err, release) {
132+
function makeRelease(releaseOptions) {
133+
repo.makeRelease(releaseOptions, function (err, release) {
133134
if(err) {
134135
console.error(
135136
(JSON.parse(err.request.responseText)).message + '\n'
@@ -143,25 +144,26 @@ function makeRelease(options) {
143144

144145
/**
145146
* Creates the options to make the release
146-
*
147-
* @param {[string]} commitMessages The commit messages to create the release body
147+
*
148+
* @param {[string]} commitMessages The commit messages to create the release body
148149
*/
149-
function prepareRelease(commitMessages) {
150+
function prepareRelease(tags, commitMessages) {
150151
var body = commitMessages.filter(function(message) {
151152
return !message.match('Merge');
152153
}).map(createBody);
153154

154155
body.pop();
155156

156-
var options = {
157+
var releaseOptions = {
157158
tag_name: tags[0].name,
158-
name: options.prefix || '' + tags[0].name,
159+
name: releasePrefix + tags[0].name,
159160
body: body.join('\n'),
160161
draft: options.draft || false,
161162
prerelease: options.prerelease || false
162163
};
163164

164-
makeRelease(options);
165+
166+
makeRelease(releaseOptions);
165167
}
166168

167169
/**
@@ -171,7 +173,7 @@ function init() {
171173
getAllTags().then(function(tags) {
172174
Promise.all(getTagDates(tags))
173175
.then(function(data) {
174-
getCommitsBetweenTwo(data[1], data[0]).then(prepareRelease);
176+
getCommitsBetweenTwo(data[1], data[0]).then(prepareRelease.bind(null, tags));
175177
});
176178
});
177179
}

0 commit comments

Comments
 (0)