You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by fi...@apache.org on 2017/02/06 21:32:38 UTC

cordova-coho git commit: bump linkify dependency for stream goodness. introduce co-streams dependency to be able to wait on stream completion using yield. linkify plugin release notes before presenting them to release manager. interpolate release-manager

Repository: cordova-coho
Updated Branches:
  refs/heads/plugins-releaser 8aa1f7f16 -> fa19b9a77


bump linkify dependency for stream goodness. introduce co-streams dependency to be able to wait on stream completion using yield. linkify plugin release notes before presenting them to release manager. interpolate release-manager-specified version into compiled notes should that have happened.


Project: http://git-wip-us.apache.org/repos/asf/cordova-coho/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-coho/commit/fa19b9a7
Tree: http://git-wip-us.apache.org/repos/asf/cordova-coho/tree/fa19b9a7
Diff: http://git-wip-us.apache.org/repos/asf/cordova-coho/diff/fa19b9a7

Branch: refs/heads/plugins-releaser
Commit: fa19b9a7755485188b46ac0c990e57dde6e85c78
Parents: 8aa1f7f
Author: filmaj <ma...@gmail.com>
Authored: Mon Feb 6 13:32:20 2017 -0800
Committer: filmaj <ma...@gmail.com>
Committed: Mon Feb 6 13:32:20 2017 -0800

----------------------------------------------------------------------
 package.json                |  5 +--
 src/plugin-release.js       | 73 ++++++++++++++++++++++++----------------
 src/update-release-notes.js | 27 +++++++++++----
 3 files changed, 68 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/fa19b9a7/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index bf48139..0d8fd81 100644
--- a/package.json
+++ b/package.json
@@ -11,7 +11,7 @@
     "co": "~4.0",
     "glob": "^5.0.14",
     "gnode": "^0.1.0",
-    "jira-linkify": "^2.2.3",
+    "jira-linkify": "^2.3.0",
     "opener": "^1.4.1",
     "optimist": "0.4",
     "q": "~0.9",
@@ -20,7 +20,8 @@
     "shelljs": "0.1.4",
     "jira-client": "4.2.0",
     "inquirer": "2.0.0",
-    "xml2js": "0.4.17"
+    "xml2js": "0.4.17",
+    "co-stream": "0.1.1"
   },
   "devDependencies": {
     "nsp": ">=2.0.1",

http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/fa19b9a7/src/plugin-release.js
----------------------------------------------------------------------
diff --git a/src/plugin-release.js b/src/plugin-release.js
index 6b64b2a..1bfd1ae 100644
--- a/src/plugin-release.js
+++ b/src/plugin-release.js
@@ -327,33 +327,44 @@ function *interactive_plugins_release() {
             /*   - each plugin may need a version bump.
              *     - how to determine if patch, minor or major? show changes to each plugin and then prompt Release Manager for a decision?
              *     - reuse coho 'update release notes' command */
-            var plugs = Object.keys(plugin_data);
-            var release_note_prompts = [];
-            plugs.forEach(function(plugin) {
-                var data = plugin_data[plugin];
-                var changes = data.changes;
-                release_note_prompts.push({
-                    type: 'editor',
-                    name: plugin,
-                    message: 'Please tweak and compile ' + plugin + ' release notes',
-                    default: tweak_release_notes.createNotes(plugin, data.current_release, changes)
-                });
-                /*     - what's the average case? just a patch bump? perhaps, for each plugin, show release notes and let RM override version beyond patch bump if RM believes it is necessary? */
-                release_note_prompts.push({
-                    type: 'input',
-                    name: plugin + '-version',
-                    message: 'Please enter a semver-compatible version number for this release of ' + plugin + ', based on the changes below:\n' + changes,
-                    default: data.current_release,
-                    validate: function(input) {
-                        if (semver.valid(input)) {
-                            return true;
-                        } else {
-                            return 'That\'s not a valid semver version!';
+            return co.wrap(function *() {
+                var plugs = Object.keys(plugin_data);
+                var release_note_prompts = [];
+                yield plugs.map(function*(plugin) {
+                    var data = plugin_data[plugin];
+                    var changes = data.changes;
+                    var final_notes = yield tweak_release_notes.createNotes(plugin, data.current_release, changes);
+                    release_note_prompts.push({
+                        type: 'editor',
+                        name: plugin,
+                        message: 'Please tweak and compile ' + plugin + ' release notes',
+                        default: final_notes
+                    });
+                    /*     - what's the average case? just a patch bump? perhaps, for each plugin, show release notes and let RM override version beyond patch bump if RM believes it is necessary? */
+                    release_note_prompts.push({
+                        type: 'input',
+                        name: plugin + '-version',
+                        message: function(answers) {
+                            var new_changes = answers[plugin];
+                            var first_heading = new_changes.indexOf('###');
+                            var second_heading = new_changes.indexOf('###', first_heading + 3);
+                            var first_change = new_changes.indexOf('\n', first_heading + 3);
+                            var len = second_heading - first_change;
+                            var change_summary = new_changes.substr(first_change, len);
+                            return 'Please enter a semver-compatible version number for this release of ' + plugin + ', based on the changes below:\n' + change_summary;
+                        },
+                        default: data.current_release,
+                        validate: function(input) {
+                            if (semver.valid(input)) {
+                                return true;
+                            } else {
+                                return 'That\'s not a valid semver version!';
+                            }
                         }
-                    }
+                    });
                 });
-            });
-            return inquirer.prompt(release_note_prompts);
+                return inquirer.prompt(release_note_prompts);
+            })();
         }).then(function(release_notes) {
             return co.wrap(function *() {
                 console.log('Writing out new release notes and plugin versions (if applicable)...');
@@ -361,11 +372,15 @@ function *interactive_plugins_release() {
                     var plugin_name = repo.repoName;
                     if (plugin_data[plugin_name].current_release != release_notes[plugin_name + '-version']) {
                         // Overwrite plugin version if, after release notes review, RM decided on a different version.
+                        var previous_assumed_version = plugin_data[plugin_name].current_release;
                         plugin_data[plugin_name].current_release = release_notes[plugin_name + '-version'];
                         yield versionutil.updateRepoVersion(repo, plugin_data[plugin_name].current_release, {commitChanges:false});
+                        // also overwrite the version originally specified in the release notes file, since we changed it now!
+                        var rn = release_notes[plugin_name];
+                        var new_rn = rn.replace(new RegExp('^### ' + previous_assumed_version, 'g'), '### ' + plugin_data[plugin_name].current_release);
+                        release_notes[plugin_name] = new_rn;
                     }
                     fs.writeFileSync(tweak_release_notes.FILE, release_notes[plugin_name], {encoding: 'utf8'});
-                    linkify.file(tweak_release_notes.FILE);
                     /* - commit changes to versions and release notes together with description '$JIRA Updated version and release notes for release $v'
                      * - tag each plugin repo with $v*/
                     if (yield gitutil.pendingChangesExist()) {
@@ -377,7 +392,7 @@ function *interactive_plugins_release() {
                 });
             })();
         }).then(function() {
-            /* 10. Create release branch.Check if release branch, which would be named in the form "major.minor.x" (i.e. 2.3.x) already exists */
+            /* 10. Create release branch. Check if release branch, which would be named in the form "major.minor.x" (i.e. 2.3.x) already exists */
             return co.wrap(function *() {
                 var repos_with_existing_release_branch = [];
                 yield repoutil.forEachRepo(plugin_repos, function*(repo) {
@@ -393,7 +408,7 @@ function *interactive_plugins_release() {
                 });
             })();
         }).then(function(repos_with_existing_release_branch) {
-            // Here we are passed an array of repos that already had release branches created prior to starting the release process here.
+            // Here we are passed an array of repos that already had release branches created prior to starting the release process.
             // Our mission in this clause, should we choose to accept it, is to merge master back into the branch. But, this can be dangerous! 
             // Should we ask the user to handle the merge / cherry pick, then? Or should we merge automatically?
             console.warn('Some release branches already exist!');
@@ -479,7 +494,7 @@ function cpAndLog(src, dest) {
 
 // TODO: if using this function only to retrieve repo version, use the new
 // versionutil.getRepoVersion method instead.
-function *handleVersion(repo,ver,validate) {
+function *handleVersion(repo, ver, validate) {
     var platform = repo.id;
     var version = ver || undefined;
 

http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/fa19b9a7/src/update-release-notes.js
----------------------------------------------------------------------
diff --git a/src/update-release-notes.js b/src/update-release-notes.js
index 15d50ff..b9f50f1 100644
--- a/src/update-release-notes.js
+++ b/src/update-release-notes.js
@@ -19,12 +19,14 @@
 
 var fs = require('fs');
 var path = require('path');
+var stream = require('stream');
 var optimist = require('optimist');
 var executil = require('./executil');
 var flagutil = require('./flagutil');
 var gitutil = require('./gitutil');
 var repoutil = require('./repoutil');
 var linkify = require('jira-linkify');
+var co_stream = require('co-stream');
 
 var relNotesFile = 'RELEASENOTES.md';
 
@@ -95,15 +97,28 @@ module.exports = function*() {
             } else {
                 newVersion = toTag;
             }
-            var data = createNotes(newVersion, output, argv['override-date']);
-            fs.writeFileSync(relNotesFile, data, {encoding: 'utf8'});
-            // TODO: does it need to write to a file or can we do it via strings in memory?
-            linkify.file(relNotesFile);
+            var final_notes = yield createNotes(repo, newVersion, output, argv['override-date']);
+            fs.writeFileSync(relNotesFile, final_notes, {encoding: 'utf8'});
         }
     });
 };
 
-function createNotes(repo, newVersion, changes, overrideDate) {
+function *createNotes(repo, newVersion, changes, overrideDate) {
+    // pump changes through JIRA linkifier first through a stream pipe
+	var transformer = linkify.stream("CB");
+	var read = new stream.Readable();
+	read._read = function(){};// noop 
+	read.push(changes);
+	read.push(null);
+	var write = new stream.Writable();
+	var data = '';
+	write._write = function(chunk, encoding, done) {
+		data += chunk.toString();
+		done();
+	}
+	read.pipe(transformer).pipe(write);
+    yield co_stream.wait(write); // wait for the writable stream to finish/end
+    // then interpolate linkified changes into existing release notes and compose the final release notes string
     var relNotesData = fs.readFileSync(path.join(process.cwd(), repo, relNotesFile), {encoding: 'utf8'});
     var headerPos = relNotesData.indexOf('### ');
     var date;
@@ -112,7 +127,7 @@ function createNotes(repo, newVersion, changes, overrideDate) {
     } else {
         date = new Date().toDateString().split(' ');
     }
-    return relNotesData.substr(0, headerPos) + "### " + newVersion + ' (' + date[1] + ' ' + date[2] + ', ' + date[3] + ')\n' + changes + '\n\n' + relNotesData.substr(headerPos);
+    return relNotesData.substr(0, headerPos) + "### " + newVersion + ' (' + date[1] + ' ' + date[2] + ', ' + date[3] + ')\n' + data + '\n\n' + relNotesData.substr(headerPos);
 }
 
 module.exports.createNotes = createNotes;


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org