@@ -45,16 +45,38 @@ function getAllTags() {
4545 } ) ;
4646}
4747
48+ /**
49+ * Return a string with a - to be a bullet list (used for a mapping)
50+ *
51+ * @param {string } message
52+ *
53+ * @return {string }
54+ */
4855function createBody ( message ) {
4956 return '- ' + message ;
5057}
5158
59+ /**
60+ * Transforms the commits to commit messages
61+ *
62+ * @param {[Object] } commits The array of object containing the commits
63+ *
64+ * @return {[string] }
65+ */
5266function commitMessages ( commits ) {
5367 return commits . map ( function ( commit ) {
5468 return commit . commit . message ;
5569 } ) ;
5670}
5771
72+ /**
73+ * Gets all the commits between two dates
74+ *
75+ * @param {string } since The since date in ISO
76+ * @param {string } until The until date in ISO
77+ *
78+ * @return {Promise } The promise which resolves the commit messages
79+ */
5880function getCommitsBetweenTwo ( since , until ) {
5981 var options = {
6082 since : since ,
@@ -73,6 +95,12 @@ function getCommitsBetweenTwo(since, until) {
7395 } ) ;
7496}
7597
98+ /**
99+ * Get the dates of the last two tags
100+ *
101+ * @param {[Object] } tags List of all the tags in the repo
102+ * @return {[Promise] } The promises which returns the dates
103+ */
76104function getTagDates ( tags ) {
77105 return [ tags [ 0 ] , tags [ 1 ] ] . map ( function ( tag ) {
78106 return new Promise ( function ( resolve , reject ) {
@@ -87,6 +115,19 @@ function getTagDates(tags) {
87115 } )
88116}
89117
118+ /**
119+ * Create a release from a given tag (in the options)
120+ *
121+ * @param {Object } options The options to build the release:
122+ * {
123+ * "tag_name": "v1.0.0",
124+ * "target_commitish": "master",
125+ * "name": "v1.0.0",
126+ * "body": "Description of the release",
127+ * "draft": false,
128+ * "prerelease": false
129+ * }
130+ */
90131function makeRelease ( options ) {
91132 repo . makeRelease ( options , function ( err , release ) {
92133 if ( err ) {
@@ -100,23 +141,39 @@ function makeRelease(options) {
100141 } ) ;
101142}
102143
103- getAllTags ( ) . then ( function ( tags ) {
104- Promise . all ( getTagDates ( tags ) )
105- . then ( function ( data ) {
106- getCommitsBetweenTwo ( data [ 1 ] , data [ 0 ] ) . then ( function ( commitMessages ) {
107- var body = commitMessages . filter ( function ( message ) {
108- return ! message . match ( 'Merge' ) ;
109- } ) . map ( createBody ) ;
144+ /**
145+ * Creates the options to make the release
146+ *
147+ * @param {[string] } commitMessages The commit messages to create the release body
148+ */
149+ function prepareRelease ( commitMessages ) {
150+ var body = commitMessages . filter ( function ( message ) {
151+ return ! message . match ( 'Merge' ) ;
152+ } ) . map ( createBody ) ;
153+
154+ body . pop ( ) ;
110155
111- body . pop ( ) ;
156+ var options = {
157+ tag_name : tags [ 0 ] . name ,
158+ name : tags [ 0 ] . name ,
159+ body : body . join ( '\n' ) ,
160+ draft : options . draft || false ,
161+ prerelease : options . prerelease || false
162+ } ;
112163
113- var options = {
114- tag_name : tags [ 0 ] . name ,
115- name : tags [ 0 ] . name ,
116- body : body . join ( '\n' )
117- } ;
164+ makeRelease ( options ) ;
165+ }
118166
119- makeRelease ( options ) ;
167+ /**
168+ * Get All the tags, get the dates, get the commits between those dates and prepeare the release
169+ */
170+ function init ( ) {
171+ getAllTags ( ) . then ( function ( tags ) {
172+ Promise . all ( getTagDates ( tags ) )
173+ . then ( function ( data ) {
174+ getCommitsBetweenTwo ( data [ 1 ] , data [ 0 ] ) . then ( prepareRelease ) ;
120175 } ) ;
121- } ) ;
122- } ) ;
176+ } ) ;
177+ }
178+
179+ init ( ) ;
0 commit comments