cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject cordova-coho git commit: Handle multiple modules within a single repo.
Date Tue, 16 Jun 2015 16:12:28 GMT
Repository: cordova-coho
Updated Branches:
  refs/heads/tb-coho-modules [created] 4bc180b19


Handle multiple modules within a single repo.

This change includes logic to handle multiple modules within a single repo, and adds specific
handling for the cordova-serve module in the cordova-lib repo. It also generalizes some of
the existing logic for modules within a repo (that formerly was specific to cordova-lib).
Specific changes:

1. Adds support for repos specifying a path to their module, when it is not at the top level.
2. Adds support for a repo entry actually being a module within a repo.
3. Adds 'Cordova Serve' to the list of repos, it actually being a module within the Cordova
Lib repo.
4. When requesting the list of repos from the 'repo=' parameter, the caller can request to
just get repos (the default) or to get modules. If just repos, then where the list would include
two entries that point to the same repo, only one is returned (the 'base' module is prioritized).
When modules are requested, then all entries are returned. The idea here is that actions that
work on repos only want unique repos. Actions that work on modules (like packaging, license
checks etc) want modules.
5. The following repo based commands now work on modules:
  * audit-license-headers
  * check-license
  * create-archive
  * last-week
  * print-tags
6. findMostRecentTag() can now be provided a prefix, in which case it will find the most recent
tag with that prefix. The prefix can be used by modules other than the primary module to differentiate
their versions.
7. Added update-release-notes command that will udpate a modules release notes picking commits
that are unique to the module's path (see getRepoIncludePath)
8. Added repoutil.getRepoIncludePath() method that determines a path to provide 'git log'
so it only includes commits unique to a module. For the base module, this will include commits
in the root directory and the base module's directory. For other modules, it will only include
changes in the module's directory.


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

Branch: refs/heads/tb-coho-modules
Commit: 4bc180b199c6c1c09a6714260b4ff7e3a4fb48a3
Parents: 58af213
Author: Tim Barham <tim.barham@microsoft.com>
Authored: Sat Jun 13 17:39:23 2015 -0700
Committer: Tim Barham <tim.barham@microsoft.com>
Committed: Mon Jun 15 13:53:13 2015 -0700

----------------------------------------------------------------------
 .gitignore                   |  1 +
 src/audit-license-headers.js |  2 +-
 src/check-license.js         | 47 +++++++++++++++++-----------
 src/create-verify-archive.js |  4 +--
 src/flagutil.js              | 25 +++++++++++++--
 src/gitutil.js               | 49 ++++++++++++++++++++---------
 src/last-week.js             |  6 ++--
 src/main.js                  |  4 +++
 src/print-tags.js            |  4 +--
 src/repo-clone.js            |  2 +-
 src/repoutil.js              | 38 +++++++++++++++++++++--
 src/update-release-notes.js  | 65 +++++++++++++++++++++++++++++++++++++++
 12 files changed, 202 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/4bc180b1/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index 2ceaa0d..8cbc9ca 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
 apache-rat-0.8
 apache-rat-0.10
 node_modules
+.idea

http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/4bc180b1/src/audit-license-headers.js
----------------------------------------------------------------------
diff --git a/src/audit-license-headers.js b/src/audit-license-headers.js
index 69ecdcc..131db8b 100644
--- a/src/audit-license-headers.js
+++ b/src/audit-license-headers.js
@@ -58,7 +58,7 @@ module.exports = function*() {
         optimist.showHelp();
         process.exit(1);
     }
-    var repos = flagutil.computeReposFromFlag(argv.r);
+    var repos = flagutil.computeReposFromFlag(argv.r, {includeModules: true});
     // Check that RAT command exists.
     var ratName = 'apache-rat-0.10';
     var ratUrl = "https://dist.apache.org/repos/dist/release/creadur/apache-rat-0.10/apache-rat-0.10-bin.tar.gz";

http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/4bc180b1/src/check-license.js
----------------------------------------------------------------------
diff --git a/src/check-license.js b/src/check-license.js
index 8f9ff29..ad07bf3 100644
--- a/src/check-license.js
+++ b/src/check-license.js
@@ -43,7 +43,7 @@ module.exports = function*(argv) {
         optimist.showHelp();
         process.exit(1);
     }
-    var repos = flagutil.computeReposFromFlag(argv.r);
+    var repos = flagutil.computeReposFromFlag(argv.r, {includeModules: true});
     checkLicense(repos);
 };
 
@@ -55,35 +55,41 @@ function getRepoLicense(repoName){
        return p;
    });
 }
-function checkLicense(repos) {
 
-    //get the license info for each repo's dependencies and subdependencies
+function checkLicense(repos) {
+    //get the license info for each repo's dependencies and sub-dependencies
     var results = [];
     var previous = Q.resolve();
-    repos.forEach(function(repo) {
-            previous = previous.then(function() {
-                if (fs.existsSync(repo.repoName) && (fs.existsSync(path.join(repo.repoName,
'package.json')) || (fs.existsSync(path.join(repo.repoName, repo.repoName, 'package.json')))))
{
-                    reposWithDependencies.push(repo.repoName);
-                    if (repo.repoName == 'cordova-lib')
-                        return getRepoLicense(path.join(repo.repoName, repo.repoName)); //go
into inner cordova-lib to get packages
-                    return getRepoLicense(repo.repoName);
-                }
-                else
-                    Q.resolve('Repo directory does not exist: ' + repos.repoName + '. First
run coho repo-clone.'); //don't end execution if repo doesn't have dependencies or doesn't
exist
-
+    repos.forEach(function (repo) {
+        previous = previous.then(function () {
+            var packageDir = findPackageDir(repo);
+            if (packageDir) {
+                reposWithDependencies.push(repo.id);
+                return getRepoLicense(packageDir);
+            } else {
+                Q.resolve('Repo directory does not exist: ' + repos.repoName + '. First run
coho repo-clone.'); //don't end execution if repo doesn't have dependencies or doesn't exist
+            }
         }).then(function (data) {
             results.push(data); //push the result of this repo to the results array for later
processing
         });
     });
 
     //process the results after the licenses for all repos have been retrieved
-    previous.then(function(result) {
+    previous.then(function (result) {
         processResults(results, repos);
-    }, function(err) {
+    }, function (err) {
         console.log(err);
     });
 }
 
+function findPackageDir(repo) {
+    var packageDir = repo.repoName;
+    if (repo.path) {
+        packageDir = path.join(packageDir, repo.path);
+    }
+    return fs.existsSync(path.join(packageDir, 'package.json')) ? packageDir : null;
+}
+
 //process the results of each repo
 function processResults(results, repos) {
     //get valid licenses file to flag packages
@@ -97,11 +103,16 @@ function processResults(results, repos) {
 
     //go through each repo, get its dependencies and add to json object
     for (var i = 0; i < results.length; ++i) {
-        if (reposWithDependencies.indexOf(repos[i].repoName) > -1)
+        var repo = repos[i];
+        if (reposWithDependencies.indexOf(repo.id) > -1)
         {
             var repoJsonObj = {};
             repoJsonObj.dependencies = getDependencies(results[i]);
-            jsonObject[repos[i].repoName] = repoJsonObj;
+            var repoIdentifier = repo.repoName;
+            if (repo.path) {
+                repoIdentifier += "/" + repo.path;
+            }
+            jsonObject[repoIdentifier] = repoJsonObj;
         }
     }
 

http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/4bc180b1/src/create-verify-archive.js
----------------------------------------------------------------------
diff --git a/src/create-verify-archive.js b/src/create-verify-archive.js
index f499e28..2757617 100644
--- a/src/create-verify-archive.js
+++ b/src/create-verify-archive.js
@@ -64,7 +64,7 @@ exports.createCommand = function*(argv) {
         optimist.showHelp();
         process.exit(1);
     }
-    var repos = flagutil.computeReposFromFlag(argv.r);
+    var repos = flagutil.computeReposFromFlag(argv.r, {includeModules: true});
 
     if (argv.sign && !shelljs.which('gpg')) {
         apputil.fatal('gpg command not found on your PATH. Refer to ' + settingUpGpg);
@@ -75,7 +75,7 @@ exports.createCommand = function*(argv) {
     var absOutDir = path.resolve(outDir);
 
     yield repoutil.forEachRepo(repos, function*(repo) {
-        var tag = argv.tag || (yield gitutil.findMostRecentTag());
+        var tag = argv.tag || (yield gitutil.findMostRecentTag(repo.versionPrefix));
         if (!tag) {
             apputil.fatal('Could not find most recent tag. Try running with --tag');
         }

http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/4bc180b1/src/flagutil.js
----------------------------------------------------------------------
diff --git a/src/flagutil.js b/src/flagutil.js
index cc65024..17cd59f 100644
--- a/src/flagutil.js
+++ b/src/flagutil.js
@@ -42,7 +42,11 @@ exports.registerDepthFlag = function(opt) {
     });
 }
 
-exports.computeReposFromFlag = function(flagValue, includeSvn) {
+exports.computeReposFromFlag = function(flagValue, opts) {
+    opts = opts || {};
+    var includeSvn = opts.includeSvn;
+    var includeModules = opts.includeModules;
+
     if (flagValue === 'auto') {
         console.log('No repos specified - using repo in CWD');
         flagValue = '.';
@@ -50,10 +54,27 @@ exports.computeReposFromFlag = function(flagValue, includeSvn) {
     var values = flagValue === true ? [] : Array.isArray(flagValue) ? flagValue : [flagValue];
     var ret = [];
     var addedIds = {};
+    var addedRepos = {};
     function addRepo(repo) {
         if (!addedIds[repo.id]) {
             addedIds[repo.id] = true;
-            ret.push(repo);
+
+            // If we're not requesting modules be included, then we want to de-dup in the
case where two repos have the
+            // same repoName (because one or both is actually a sub-module). This probably
means we're doing a repo level
+            // operation, so it doesn't matter which we keep, but we'll prefer the one that
represents the base repo.
+            if (includeModules) {
+                ret.push(repo);
+            } else {
+                var existingRepo = addedRepos[repo.repoName];
+                if (!existingRepo || !repo.isModule) {
+                    if (existingRepo) {
+                        ret[ret.indexOf(existingRepo)] = repo;
+                    } else {
+                        ret.push(repo);
+                    }
+                    addedRepos[repo.repoName] = repo;
+                }
+            }
         }
     }
     values.forEach(function(value) {

http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/4bc180b1/src/gitutil.js
----------------------------------------------------------------------
diff --git a/src/gitutil.js b/src/gitutil.js
index 355197b..ceea264 100644
--- a/src/gitutil.js
+++ b/src/gitutil.js
@@ -22,21 +22,42 @@ var executil = require('./executil');
 var gitutil = exports;
 var semver = require('semver');
 
-exports.findMostRecentTag = function*() {
-    // Returns the greatest semver-looking tag in the repo
+/**
+ * Returns the greatest semver-looking tag in the repo. If prefix is specified, only looks
at tags that start with
+ * 'prefix-' (this allows for multiple modules in the same repo).
+ * @param {string} [prefix] - An optional prefix to filter tags.
+ * @returns {string} - the most recent tag, or null if no version tags are found.
+ */
+exports.findMostRecentTag = function*(prefix) {
+    prefix = prefix && prefix + "-";
+
     return (yield executil.execHelper(executil.ARGS('git tag --list'), true)).split(/\s+/)
-    .reduce(function(curBest, value) {
-        // Strip the "r" prefix that plugin repos use (ugh), but also make them look higher
than 3.0.0 tag that exists
-        var modifiedCurBest = curBest.replace(/^r/, '9');
-        var modifiedValue = value.replace(/^r/, '9');
-        if (semver.valid(modifiedValue)) {
-            return !curBest ? modifiedValue : semver.gt(modifiedCurBest, modifiedValue) ?
curBest : value;
-        } else if (curBest && semver.valid(modifiedCurBest)) {
-            return curBest;
-        }
-        return null;
-    });
-}
+        .reduce(function (curBest, value) {
+            var modifiedCurBest, modifiedValue;
+
+            if (prefix) {
+                // Ignore values that don't start with prefix, and strip prefix from the
value we're going to test
+                if (value.indexOf(prefix) !== 0) {
+                    modifiedValue = null;
+                    modifiedCurBest = null;
+                } else {
+                    modifiedValue = value.substr(prefix.length);
+                    modifiedCurBest = curBest && curBest.substr(prefix.length);
+                }
+            } else {
+                // Strip the "r" prefix that plugin repos use (ugh), but also make them look
higher than 3.0.0 tag that exists
+                modifiedCurBest = curBest.replace(/^r/, '9');
+                modifiedValue = value.replace(/^r/, '9');
+            }
+
+            if (semver.valid(modifiedValue)) {
+                return !curBest ? value : semver.gt(modifiedCurBest, modifiedValue) ? curBest
: value;
+            } else if (curBest && semver.valid(modifiedCurBest)) {
+                return curBest;
+            }
+            return null;
+        });
+};
 
 exports.tagExists = function*(tagName) {
     return !!(yield executil.execHelper(executil.ARGS('git tag --list ' + tagName), true));

http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/4bc180b1/src/last-week.js
----------------------------------------------------------------------
diff --git a/src/last-week.js b/src/last-week.js
index b105a73..8faa8f4 100644
--- a/src/last-week.js
+++ b/src/last-week.js
@@ -54,7 +54,7 @@ module.exports = function*() {
         optimist.showHelp();
         process.exit(1);
     }
-    var repos = flagutil.computeReposFromFlag(argv.r);
+    var repos = flagutil.computeReposFromFlag(argv.r, {includeModules: true});
     var filterByEmail = !!argv.me || !! argv.user;
     var days = argv.days || 7;
     var userEmail = filterByEmail && (argv.user || meEmail);
@@ -78,7 +78,7 @@ module.exports = function*() {
             format += ' %an - ';
         }
         format += '%cd %s';
-        var output = yield executil.execHelper(cmd.concat([format, '--since=' + days + '
days ago']), true);
+        var output = yield executil.execHelper(cmd.concat([format, '--since=' + days + '
days ago']).concat(repoutil.getRepoIncludePath(repo)), true);
         if (output) {
             console.log(output);
             commitCount += output.split('\n').length;
@@ -91,7 +91,7 @@ module.exports = function*() {
         yield repoutil.forEachRepo(repos, function*(repo) {
             var repoName = repo.id + new Array(Math.max(0, 20 - repo.id.length + 1)).join('
');
             var output = yield executil.execHelper(cmd.concat(['--format=%ae|' + repoName
+ ' %cd %s',
-                '--since=' + days + ' days ago']), true);
+                '--since=' + days + ' days ago']).concat(repoutil.getRepoIncludePath(repo)),
true);
             if (output) {
                 output.split('\n').forEach(function(line) {
                     line = line.replace(/(.*?)\|/, '');

http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/4bc180b1/src/main.js
----------------------------------------------------------------------
diff --git a/src/main.js b/src/main.js
index 374f3f4..aafe192 100644
--- a/src/main.js
+++ b/src/main.js
@@ -113,6 +113,10 @@ module.exports = function() {
             desc: 'Publishes current version of repo to specified tag',
             entryPoint: lazyRequire('./npm-publish', 'publishTag')
         }, {
+            name: 'update-release-notes',
+            desc: 'Updates release notes with commits since the most recent tag.',
+            entryPoint: lazyRequire('./update-release-notes')
+        },  {
             name: 'npm-unpublish-nightly',
             desc: 'Unpublishes last nightly versions for cli and lib',
             entryPoint: lazyRequire('./npm-publish', 'unpublishNightly')

http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/4bc180b1/src/print-tags.js
----------------------------------------------------------------------
diff --git a/src/print-tags.js b/src/print-tags.js
index 9f1286f..f47c9d7 100644
--- a/src/print-tags.js
+++ b/src/print-tags.js
@@ -37,14 +37,14 @@ module.exports = function*(argv) {
         optimist.showHelp();
         process.exit(1);
     }
-    var repos = flagutil.computeReposFromFlag(argv.r);
+    var repos = flagutil.computeReposFromFlag(argv.r, {includeModules: true});
 
     var tag;
     yield repoutil.forEachRepo(repos, function*(repo) {
         if (argv.tag){
             tag = argv.tag;
         } else {
-            tag = yield gitutil.findMostRecentTag();
+            tag = yield gitutil.findMostRecentTag(repo.versionPrefix);
         }
         if (!tag) {
             console.log('    ' + repo.repoName + ': NO TAGS');

http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/4bc180b1/src/repo-clone.js
----------------------------------------------------------------------
diff --git a/src/repo-clone.js b/src/repo-clone.js
index 15e2adb..6a85646 100644
--- a/src/repo-clone.js
+++ b/src/repo-clone.js
@@ -40,7 +40,7 @@ module.exports = function*(argv) {
 
     var depth = argv.depth ? argv.depth : null;
 
-    var repos = flagutil.computeReposFromFlag(argv.r, true);
+    var repos = flagutil.computeReposFromFlag(argv.r, {includeSvn: true});
     yield cloneRepos(repos, false, depth);
 }
 

http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/4bc180b1/src/repoutil.js
----------------------------------------------------------------------
diff --git a/src/repoutil.js b/src/repoutil.js
index b6a4f11..7e72799 100644
--- a/src/repoutil.js
+++ b/src/repoutil.js
@@ -358,11 +358,19 @@ var toolRepos = [
         id: 'lib',
         repoName: 'cordova-lib',
         jiraComponentName: 'CordovaLib',
+        path: 'cordova-lib',
         ratExcludes: [
             'fixtures',
             'platformsConfig.json'
         ]
     }, {
+        title: 'Cordova Serve',
+        id: 'serve',
+        repoName: 'cordova-lib',
+        path: 'cordova-serve',
+        versionPrefix: 'serve',
+        isModule: true
+    }, {
         title: 'Cordova JS',
         id: 'js',
         repoName: 'cordova-js',
@@ -522,9 +530,35 @@ exports.resolveCwdRepo = resolveCwdRepo;
 function getRepoDir(repo) {
     var baseWorkingDir = apputil.getBaseDir();
     var repoDir = path.join(baseWorkingDir, repo.repoName);
-    if(repo.id === 'lib'){
-        repoDir = path.join(repoDir, 'cordova-lib');
+    if (repo.path) {
+        repoDir = path.join(repoDir, repo.path);
     }
     return repoDir;
 }
 exports.getRepoDir = getRepoDir;
+
+function getRepoIncludePath(repo) {
+    var repoPath = repo.path;
+    if (!repoPath) {
+        return [];
+    }
+
+    if (repo.isModule) {
+        // The easy case... if it's a module, then we only include stuff in that module.
Since we should already be in
+        // the module folder, we can just use '.'.
+        return ['--', '.'];
+    }
+
+    // The harder case - this is the main repo. We want to include the repo root folder and
the folder pointed to by
+    // repo.path, but exclude all module folders.
+    var matchingRepos = allRepos.filter(function (testRepo) {
+        return testRepo.isModule && testRepo.repoName == repo.repoName;
+    });
+
+    return matchingRepos.reduce(function (previous, moduleRepo) {
+        // Note that wwe have to do the '../' stuff because we're not in the root directory
of the repo.
+        previous.push(':!../' + moduleRepo.path);
+        return previous;
+    },  ['--', '../']);
+}
+exports.getRepoIncludePath = getRepoIncludePath;

http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/4bc180b1/src/update-release-notes.js
----------------------------------------------------------------------
diff --git a/src/update-release-notes.js b/src/update-release-notes.js
new file mode 100644
index 0000000..ca548ac
--- /dev/null
+++ b/src/update-release-notes.js
@@ -0,0 +1,65 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+var fs = require('fs');
+var path = require('path');
+var optimist = require('optimist');
+var executil = require('./executil');
+var flagutil = require('./flagutil');
+var gitutil = require('./gitutil');
+var repoutil = require('./repoutil');
+
+module.exports = function*() {
+    var meEmail = yield executil.execHelper(executil.ARGS('git config user.email'), true);
+    var opt = flagutil.registerRepoFlag(optimist);
+    opt = flagutil.registerHelpFlag(opt)
+        .usage('Updates release notes with commits since the most recent tag.\n' +
+        '\n' +
+        'Usage: $0 update-release-notes [--repo=ios]');
+    argv = opt.argv;
+
+    if (argv.h) {
+        optimist.showHelp();
+        process.exit(1);
+    }
+
+    var repos = flagutil.computeReposFromFlag(argv.r, {includeModules: true});
+
+    var cmd = executil.ARGS('git log --topo-order --no-merges');
+    cmd.push(['--pretty=format:* %s']);
+    yield repoutil.forEachRepo(repos, function*(repo) {
+        var tag = yield gitutil.findMostRecentTag(repo.versionPrefix);
+        cmd.push(tag + '..master');
+        var repoDesc = repo.repoName;
+        if (repo.path) {
+            repoDesc += '/' + repo.path;
+        }
+        console.log('Finding commits in ' + repoDesc + ' since tag ' + tag);
+        var output = yield executil.execHelper(cmd.concat(repoutil.getRepoIncludePath(repo)),
true);
+        if (output) {
+            var newVersion = require(path.join(process.cwd(), 'package.json')).version;
+            var relNotesFile = 'RELEASENOTES.md';
+            var data = fs.readFileSync(relNotesFile, {encoding: 'utf8'});
+            var pos = data.indexOf('### ');
+            var date = new Date().toDateString().split(' ');
+            data = data.substr(0, pos) + "### " + newVersion + ' (' + date[1] + ' ' + date[2]
+ ', ' + date[3] + ')\n' + output + '\n\n' + data.substr(pos);
+            fs.writeFileSync(relNotesFile, data, {encoding: 'utf8'});
+        }
+    });
+};


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


Mime
View raw message