CB-12895 : added eslint
Project: http://git-wip-us.apache.org/repos/asf/cordova-coho/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-coho/commit/34ae0bbb Tree: http://git-wip-us.apache.org/repos/asf/cordova-coho/tree/34ae0bbb Diff: http://git-wip-us.apache.org/repos/asf/cordova-coho/diff/34ae0bbb Branch: refs/heads/master Commit: 34ae0bbbe9657bac15ebeda87f2c8a8560fa83b0 Parents: d27736a Author: Audrey So <[email protected]> Authored: Fri Jun 9 11:40:05 2017 -0700 Committer: Audrey So <[email protected]> Committed: Tue Aug 22 11:49:55 2017 -0700 ---------------------------------------------------------------------- .eslintrc.yml | 10 ++ .jshintrc | 7 - package.json | 18 ++- src/apputil.js | 20 +-- src/audit-license-headers.js | 41 +++-- src/check-license.js | 149 ++++++++---------- src/create-pr.js | 82 +++++----- src/create-verify-archive.js | 55 ++++--- src/executil.js | 16 +- src/flagutil.js | 35 ++--- src/for-each.js | 21 ++- src/gitutil.js | 99 ++++++------ src/last-week.js | 44 +++--- src/list-pulls.js | 99 ++++++------ src/list-release-urls.js | 13 +- src/list-repos.js | 11 +- src/main.js | 205 ++++++++++++------------ src/merge-pr.js | 74 +++++---- src/nightly.js | 26 +-- src/npm-link.js | 86 +++++----- src/npm-publish.js | 64 ++++---- src/platform-release.js | 111 ++++++------- src/plugin-release.js | 321 +++++++++++++++++++------------------- src/print-tags.js | 7 +- src/repo-clone.js | 21 ++- src/repo-push.js | 15 +- src/repo-reset.js | 26 +-- src/repo-status.js | 28 ++-- src/repo-update.js | 80 +++++----- src/repoutil.js | 45 +++--- src/retrieve-sha.js | 6 +- src/shortlog.js | 20 +-- src/superspawn.js | 33 ++-- src/svnutil.js | 13 +- src/update-release-notes.js | 75 ++++----- src/verify-tags.js | 16 +- src/versionutil.js | 57 ++++--- test/flagutil.test.js | 110 ++++++------- test/test.js | 6 +- 39 files changed, 1065 insertions(+), 1100 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/34ae0bbb/.eslintrc.yml ---------------------------------------------------------------------- diff --git a/.eslintrc.yml b/.eslintrc.yml new file mode 100644 index 0000000..0cccb8c --- /dev/null +++ b/.eslintrc.yml @@ -0,0 +1,10 @@ +root: true +extends: semistandard +rules: + indent: + - error + - 4 + camelcase: off + padded-blocks: off + operator-linebreak: off + no-throw-literal: off \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/34ae0bbb/.jshintrc ---------------------------------------------------------------------- diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index c22ed7c..0000000 --- a/.jshintrc +++ /dev/null @@ -1,7 +0,0 @@ -{ - "node": true, - "esversion": 6, - "latedef": "nofunc", - "unused": "vars", - "undef": true -} http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/34ae0bbb/package.json ---------------------------------------------------------------------- diff --git a/package.json b/package.json index 4a3fb52..b9a6932 100644 --- a/package.json +++ b/package.json @@ -9,9 +9,12 @@ "dependencies": { "chalk": "~0.4", "co": "~4.0", + "co-stream": "0.1.1", "glob": "^5.0.14", "gnode": "^0.1.0", + "inquirer": "2.0.0", "jasmine": "^2.5.3", + "jira-client": "4.2.0", "jira-linkify": "^2.3.0", "nlf": "^1.4.3", "opener": "^1.4.1", @@ -21,12 +24,16 @@ "semver": "^4.2.0", "shelljs": "0.1.4", "treeify": "^1.0.1", - "jira-client": "4.2.0", - "inquirer": "2.0.0", - "xml2js": "0.4.17", - "co-stream": "0.1.1" + "xml2js": "0.4.17" }, "devDependencies": { + "eslint": "^3.19.0", + "eslint-config-semistandard": "^11.0.0", + "eslint-config-standard": "^10.2.1", + "eslint-plugin-import": "^2.3.0", + "eslint-plugin-node": "^5.0.0", + "eslint-plugin-promise": "^3.5.0", + "eslint-plugin-standard": "^3.0.1", "nsp": ">=2.0.1", "tap-dot": "^1.0.0", "tap-spec": "^4.0.0", @@ -37,7 +44,8 @@ "oldtest": "node test/test.js | tap-spec", "test": "npm run jasmine", "cover": "istanbul cover --root src --print detail jasmine", - "jasmine": "jasmine --captureExceptions --color" + "jasmine": "jasmine --captureExceptions --color", + "eslint": "eslint test && eslint src" }, "repository": { "type": "git", http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/34ae0bbb/src/apputil.js ---------------------------------------------------------------------- diff --git a/src/apputil.js b/src/apputil.js index bf571ab..d979a89 100644 --- a/src/apputil.js +++ b/src/apputil.js @@ -24,31 +24,31 @@ var shell = require('shelljs'); var origWorkingDir = path.resolve(process.cwd()); var baseWorkingDir = origWorkingDir; -exports.resolveUserSpecifiedPath = function(p) { +exports.resolveUserSpecifiedPath = function (p) { return path.resolve(origWorkingDir, p); }; -exports.initWorkingDir = function(chdir) { - if(chdir) { +exports.initWorkingDir = function (chdir) { + if (chdir) { var newDir = path.resolve(__dirname, '..', '..'); process.chdir(newDir); baseWorkingDir = newDir; } console.log('Running from ' + baseWorkingDir); -} +}; -exports.getBaseDir = function() { +exports.getBaseDir = function () { return baseWorkingDir; -} +}; -exports.fatal = function() { +exports.fatal = function () { console.error.apply(console, arguments); process.exit(1); }; exports.prefixLength = 30; -exports.print = function() { +exports.print = function () { var newArgs = Array.prototype.slice.call(arguments); // Prefix any prints() to distinguish them from command output. if (newArgs.length > 1 || newArgs[0]) { @@ -61,11 +61,11 @@ exports.print = function() { } var prefix = chalk.magenta.bold(curDir) + chalk.yellow(banner); newArgs.unshift(prefix); - newArgs = newArgs.map(function(val) { return val.replace(/\n/g, '\n' + prefix + ' ') }); + newArgs = newArgs.map(function (val) { return val.replace(/\n/g, '\n' + prefix + ' '); }); } console.log.apply(console, newArgs); -} +}; exports.setShellSilent = function (func) { var origShellSilent = shell.config.silent; http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/34ae0bbb/src/audit-license-headers.js ---------------------------------------------------------------------- diff --git a/src/audit-license-headers.js b/src/audit-license-headers.js index aed4189..734ef59 100644 --- a/src/audit-license-headers.js +++ b/src/audit-license-headers.js @@ -18,7 +18,6 @@ under the License. */ var fs = require('fs'); -var os = require('os'); var path = require('path'); var chalk = require('chalk'); var shelljs = require('shelljs'); @@ -47,52 +46,52 @@ var COMMON_RAT_EXCLUDES = [ '.jshintrc', '*.xcworkspacedata', '*.xccheckout', - '*.xcscheme', + '*.xcscheme' ]; -var RAT_IGNORE_PATH = '.ratignore'; +var RAT_IGNORE_PATH = '.ratignore'; var RATIGNORE_COMMENT_PREFIX = '#'; var RAT_NAME = 'apache-rat-0.12'; -var RAT_URL = 'https://dist.apache.org/repos/dist/release/creadur/apache-rat-0.12/apache-rat-0.12-bin.tar.gz'; +var RAT_URL = 'https://dist.apache.org/repos/dist/release/creadur/apache-rat-0.12/apache-rat-0.12-bin.tar.gz'; -function startsWith(string, prefix) { +function startsWith (string, prefix) { return string.indexOf(prefix) === 0; } -function isComment(pattern) { +function isComment (pattern) { return startsWith(pattern.trim(), RATIGNORE_COMMENT_PREFIX); } -module.exports = function*() { +module.exports = function * () { var opt = flagutil.registerRepoFlag(optimist); - opt = flagutil.registerHelpFlag(opt); + opt = flagutil.registerHelpFlag(opt); opt.usage('Uses Apache RAT to audit source files for license headers.\n' + '\n' + - 'Usage: $0 audit-license-headers --repo=name [-r repos]') - argv = opt.argv; + 'Usage: $0 audit-license-headers --repo=name [-r repos]'); + argv = opt.argv; // eslint-disable-line no-undef - if (argv.h) { + if (argv.h) { // eslint-disable-line no-undef optimist.showHelp(); process.exit(1); } - var repos = flagutil.computeReposFromFlag(argv.r, {includeModules: true}); + var repos = flagutil.computeReposFromFlag(argv.r, {includeModules: true}); // eslint-disable-line no-undef yield module.exports.scrubRepos(repos); -} +}; -module.exports.scrubRepos = function*(repos, silent, ignoreError, win, fail) { +module.exports.scrubRepos = function * (repos, silent, ignoreError, win, fail) { // Check that RAT command exists. var ratPath; - yield repoutil.forEachRepo([repoutil.getRepoById('coho')], function*() { - ratPath = path.join(process.cwd(), RAT_NAME, RAT_NAME+'.jar'); + yield repoutil.forEachRepo([repoutil.getRepoById('coho')], function * () { + ratPath = path.join(process.cwd(), RAT_NAME, RAT_NAME + '.jar'); }); if (!fs.existsSync(ratPath)) { console.log('RAT tool not found, downloading to: ' + ratPath); - yield repoutil.forEachRepo([repoutil.getRepoById('coho')], function*() { + yield repoutil.forEachRepo([repoutil.getRepoById('coho')], function * () { // TODO: this will not work on windows right? if (shelljs.which('curl')) { yield executil.execHelper(['sh', '-c', 'curl "' + RAT_URL + '" | tar xz']); @@ -109,13 +108,13 @@ module.exports.scrubRepos = function*(repos, silent, ignoreError, win, fail) { // NOTE: // the CWD in a callback is the directory for its respective repo - yield repoutil.forEachRepo(repos, function*(repo) { + yield repoutil.forEachRepo(repos, function * (repo) { var excludePatterns = COMMON_RAT_EXCLUDES; // read in exclude patterns from repo's .ratignore, one pattern per line if (fs.existsSync(RAT_IGNORE_PATH)) { - var ratignoreFile = fs.readFileSync(RAT_IGNORE_PATH); + var ratignoreFile = fs.readFileSync(RAT_IGNORE_PATH); var ratignoreLines = ratignoreFile.toString().trim().split('\n'); // add only non-empty and non-comment lines @@ -133,8 +132,8 @@ module.exports.scrubRepos = function*(repos, silent, ignoreError, win, fail) { }); // run Rat - yield executil.execHelper(executil.ARGS('java -jar', ratPath, '-d', '.').concat(excludeFlags), silent, ignoreError, function(stdout) { + yield executil.execHelper(executil.ARGS('java -jar', ratPath, '-d', '.').concat(excludeFlags), silent, ignoreError, function (stdout) { if (win) win(repo, stdout); }); }); -} +}; http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/34ae0bbb/src/check-license.js ---------------------------------------------------------------------- diff --git a/src/check-license.js b/src/check-license.js index cd4ad4d..0729a15 100644 --- a/src/check-license.js +++ b/src/check-license.js @@ -17,26 +17,26 @@ specific language governing permissions and limitations under the License. */ -var nlf = require('nlf'), - treeify = require('treeify'), - optimist = require('optimist'), - fs = require('fs'), - path = require('path'), - Q = require('q'), - flagutil = require('./flagutil'); - -var jsonObject = {}, - validLicenses = [], - knownIssues = {}, - licensesFile = path.join('cordova-coho', 'src', 'validLicenses.json'), - knownIssuesFile = path.join('cordova-coho', 'src', 'knownIssues.json'), - reposWithDependencies = [], - flagged = []; - -module.exports = function*(argv) { - var opt = flagutil.registerRepoFlag(optimist) +var nlf = require('nlf'); +var treeify = require('treeify'); +var optimist = require('optimist'); +var fs = require('fs'); +var path = require('path'); +var Q = require('q'); +var flagutil = require('./flagutil'); + +var jsonObject = {}; +var validLicenses = []; +var knownIssues = {}; +var licensesFile = path.join('cordova-coho', 'src', 'validLicenses.json'); +var knownIssuesFile = path.join('cordova-coho', 'src', 'knownIssues.json'); +var reposWithDependencies = []; +var flagged = []; + +module.exports = function * (argv) { + var opt = flagutil.registerRepoFlag(optimist); opt = flagutil.registerHelpFlag(opt); - var argv = opt + var argv = opt // eslint-disable-line no-redeclare .usage('Go through each specified repo and check the licenses of node modules that are 3rd-party dependencies.\n\n' + 'Usage: $0 check-license --repo=name [-r repos]') .argv; @@ -49,17 +49,17 @@ module.exports = function*(argv) { checkLicense(repos); }; -function getRepoLicense(repoName){ - return Q.nfapply(nlf.find, [{ - directory : path.join(process.cwd(), repoName) - } - ]).then(function (p) { - return p; - }); +function getRepoLicense (repoName) { + return Q.nfapply(nlf.find, [{ + directory: path.join(process.cwd(), repoName) + } + ]).then(function (p) { + return p; + }); } -function checkLicense(repos) { - //get the license info for each repo's dependencies and sub-dependencies +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) { @@ -69,14 +69,14 @@ function checkLicense(repos) { 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 + 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 + 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 + // process the results after the licenses for all repos have been retrieved previous.then(function (result) { processResults(results, repos); }, function (err) { @@ -84,7 +84,7 @@ function checkLicense(repos) { }); } -function findPackageDir(repo) { +function findPackageDir (repo) { var packageDir = repo.repoName; if (repo.path) { packageDir = path.join(packageDir, repo.path); @@ -92,50 +92,46 @@ function findPackageDir(repo) { 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 +// process the results of each repo +function processResults (results, repos) { + // get valid licenses file to flag packages validLicenses = fs.readFileSync(licensesFile, 'utf8'); - if (!validLicenses) - { + if (!validLicenses) { console.log('No valid licenses file. Please make sure it exists.'); return; } validLicenses = (JSON.parse(validLicenses)).validLicenses; - //get known issues file to report known package issues + // get known issues file to report known package issues knownIssues = fs.readFileSync(knownIssuesFile, 'utf8'); - if (!knownIssues) - { + if (!knownIssues) { console.log('No known issues file. Please make sure it exists.'); return; } knownIssues = JSON.parse(knownIssues); - //go through each repo, get its dependencies and add to json object + // go through each repo, get its dependencies and add to json object for (var i = 0; i < results.length; ++i) { var repo = repos[i]; - if (reposWithDependencies.indexOf(repo.id) > -1) - { + if (reposWithDependencies.indexOf(repo.id) > -1) { var repoJsonObj = {}; repoJsonObj.dependencies = getDependencies(results[i]); var repoIdentifier = repo.repoName; if (repo.path) { - repoIdentifier += "/" + repo.path; + repoIdentifier += '/' + repo.path; } jsonObject[repoIdentifier] = repoJsonObj; } } - //output results (license info for all packages + list of flagged packages) + // output results (license info for all packages + list of flagged packages) console.log('Below is the license info for all the packages'); console.log(treeify.asTree(jsonObject, true)); console.log('\n***********************************************************************************************************************'); console.log('***********************************************************************************************************************'); console.log('***********************************************************************************************************************\n'); if (flagged.length) { - for (var j = 0; j < flagged.length; ++j) - { + for (var j = 0; j < flagged.length; ++j) { if (knownIssues[ flagged[j].name ]) { flagged[j]['known-issues'] = knownIssues[ flagged[j].name ]; } @@ -148,12 +144,11 @@ function processResults(results, repos) { } } -//get dependencies for a repo -function getDependencies(packages) { +// get dependencies for a repo +function getDependencies (packages) { var dependencies = []; - for (var j = 0; j < packages.length; ++j) - { - //pull out only relevant info and add to dependencies array + for (var j = 0; j < packages.length; ++j) { + // pull out only relevant info and add to dependencies array var obj = {}; obj.name = packages[j].name; obj.id = packages[j].id; @@ -161,56 +156,46 @@ function getDependencies(packages) { obj.licenses = packages[j].licenseSources.package.sources; dependencies.push(obj); - //flag any packages whose licenses may not be compatible - if (!hasValidLicense(obj)) - { + // flag any packages whose licenses may not be compatible + if (!hasValidLicense(obj)) { var duplicate = false; - //avoid duplicating already flagged packages - for (var z = 0; z < flagged.length; ++z) - { - if (flagged[z].id == obj.id) - { + // avoid duplicating already flagged packages + for (var z = 0; z < flagged.length; ++z) { + if (flagged[z].id === obj.id) { duplicate = true; break; } } - if (duplicate) - flagged[z].directory = flagged[z].directory.concat(obj.directory); //if it is already flagged then just add the directory to the directories array + if (duplicate) { + flagged[z].directory = flagged[z].directory.concat(obj.directory); // if it is already flagged then just add the directory to the directories array - else - flagged.push(JSON.parse(JSON.stringify(obj))); + } else { flagged.push(JSON.parse(JSON.stringify(obj))); } } } return dependencies; } -//check if package has valid licenses -function hasValidLicense(package) { +// check if package has valid licenses +function hasValidLicense (pkg) { var isValid = false; - if (package.licenses.length == 0) - return isValid; - - else - { - //go through each license of the package - for (var x = 0; x < package.licenses.length; ++x) - { + if (pkg.licenses.length === 0) { return isValid; } else { + // go through each license of the package + for (var x = 0; x < pkg.licenses.length; ++x) { isValid = false; - //go through valid licenses and try to match with package license - for (var y = 0; y < validLicenses.length; ++y) - { - var pattern = new RegExp(validLicenses[y], "gi"); //construct regular expression from valid license - if ((package.licenses[x].license).match(pattern)) //match it against the package license + // go through valid licenses and try to match with package license + for (var y = 0; y < validLicenses.length; ++y) { + var pattern = new RegExp(validLicenses[y], 'gi'); // construct regular expression from valid license + if ((pkg.licenses[x].license).match(pattern)) { // match it against the package license isValid = true; + } } - //shortcut - if one license isn't valid then go ahead and flag it - if (isValid == false) - break; + // shortcut - if one license isn't valid then go ahead and flag it + if (isValid === false) { break; } } } http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/34ae0bbb/src/create-pr.js ---------------------------------------------------------------------- diff --git a/src/create-pr.js b/src/create-pr.js index 4812172..62f423d 100644 --- a/src/create-pr.js +++ b/src/create-pr.js @@ -27,49 +27,49 @@ var apputil = require('./apputil'); var url = require('url'); var opener = require('opener'); -module.exports = function *(argv) { +module.exports = function * (argv) { var opt = flagutil.registerHelpFlag(optimist); opt.options('branch', { - desc: 'Topic branch for which to create pull request (Default: current branch) ', - demand: false - }); + desc: 'Topic branch for which to create pull request (Default: current branch) ', + demand: false + }); argv = opt .usage('Launch github URL to create PR\n' + '\n' + 'Usage: $0 create-pr --branch <topic_branch>') .argv; - if (argv.h) { + if (argv.h) { optimist.showHelp(); process.exit(1); - } - var currentRepo = repoutil.getRepoById(repoutil.resolveCwdRepo()); - var currentBranch = opt.branch; - if (!currentBranch) { - currentBranch = yield gitutil.retrieveCurrentBranchName(); - } - if (currentBranch == 'master') { - console.log('You can crate a PR only for a topic branch that is not master. Use --branch to specify the topic branch or checkout to the topic branch.'); - } - var remoteInfo = yield getRemoteName(currentBranch); - var remoteFork = yield getRemoteForkName(remoteInfo.remoteName); - var url = REMOTE + currentRepo.repoName + '/compare/master...' + remoteFork + ':' + remoteInfo.remoteBranch + '?expand=1'; - console.log("Navigating to: " + url); - opener(url); -} + } + var currentRepo = repoutil.getRepoById(repoutil.resolveCwdRepo()); + var currentBranch = opt.branch; + if (!currentBranch) { + currentBranch = yield gitutil.retrieveCurrentBranchName(); + } + if (currentBranch === 'master') { + console.log('You can crate a PR only for a topic branch that is not master. Use --branch to specify the topic branch or checkout to the topic branch.'); + } + var remoteInfo = yield getRemoteName(currentBranch); + var remoteFork = yield getRemoteForkName(remoteInfo.remoteName); + var url = REMOTE + currentRepo.repoName + '/compare/master...' + remoteFork + ':' + remoteInfo.remoteBranch + '?expand=1'; + console.log('Navigating to: ' + url); + opener(url); +}; -function* getRemoteForkName(remoteName) { - var remotes = (yield executil.execHelper(executil.ARGS('git remote -v'), /*silent*/ true)).split('\n'); +function * getRemoteForkName (remoteName) { + var remotes = (yield executil.execHelper(executil.ARGS('git remote -v'), /* silent */ true)).split('\n'); var remoteUrl; - for (var i = 0; i < remotes.length; i++) { - //fork https://github.com/forkName/cordova-coho.git (push) - var tokens = remotes[i].split(/\s+/); - if (tokens[2] === '(push)' && tokens[0] === remoteName) { - remoteUrl = tokens[1]; - break; - } + for (var i = 0; i < remotes.length; i++) { + // fork https://github.com/forkName/cordova-coho.git (push) + var tokens = remotes[i].split(/\s+/); + if (tokens[2] === '(push)' && tokens[0] === remoteName) { + remoteUrl = tokens[1]; + break; + } } if (!remoteUrl) { - apputil.fatal('Cannot find remote Url: ' + remotes); + apputil.fatal('Cannot find remote Url: ' + remotes); } var parsed = url.parse(remoteUrl); // parsed => /forkName/cordova-coho.git @@ -77,27 +77,27 @@ function* getRemoteForkName(remoteName) { return forkName; } -function* getRemoteName(currentBranch) { - var branches = (yield executil.execHelper(executil.ARGS('git branch -vv'), /*silent*/ true)).split('\n'); +function * getRemoteName (currentBranch) { + var branches = (yield executil.execHelper(executil.ARGS('git branch -vv'), /* silent */ true)).split('\n'); //* create-pr 3bed9b5 [remotes/fork/create-pr] Add support for launching URL to create a PR - for (var i = 0; i < branches.length; i++) { + for (var i = 0; i < branches.length; i++) { //* create-pr 3bed9b5 [remotes/fork/create-pr] Add support for launching URL to create a PR - //0 1 2 3 + // 0 1 2 3 var tokens = branches[i].split(/\s+/); - if (tokens[0] == '*') { + if (tokens[0] === '*') { // found the current branch - if(currentBranch !== tokens[1]) { + if (currentBranch !== tokens[1]) { apputil.fatal('Unexpected format. Cannot find remote branch: ' + tokens[1] + '!== ' + currentBranch); } // if there is no upstream remote specified - we have no choice but to bail var remote = tokens[3]; - if(remote.indexOf('[') !== 0) { - apputil.fatal('Cannot determine upstream remote branch. Have you already pushed it? \n' + + if (remote.indexOf('[') !== 0) { + apputil.fatal('Cannot determine upstream remote branch. Have you already pushed it? \n' + 'To push and set upstream: git push -u <remoteFork> ' + currentBranch + '\n' + 'To set upstream branch: git branch --set-upstream <remoteFork>'); } // Strip off the [] - remote = remote.substring(1, remote.length -1); + remote = remote.substring(1, remote.length - 1); tokens = remote.split('/'); var remoteName = tokens[0]; var remoteBranch = tokens[1]; @@ -105,8 +105,8 @@ function* getRemoteName(currentBranch) { remoteName = tokens[1]; remoteBranch = tokens[2]; } - return { remoteName : remoteName, remoteBranch: remoteBranch}; + return { remoteName: remoteName, remoteBranch: remoteBranch }; } } apputil.fatal('Unexpected error. Cannot determine remote: ' + branches); -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/34ae0bbb/src/create-verify-archive.js ---------------------------------------------------------------------- diff --git a/src/create-verify-archive.js b/src/create-verify-archive.js index 0b317f0..1f5d5d4 100644 --- a/src/create-verify-archive.js +++ b/src/create-verify-archive.js @@ -28,42 +28,41 @@ var executil = require('./executil'); var flagutil = require('./flagutil'); var gitutil = require('./gitutil'); var repoutil = require('./repoutil'); -var npm_link = require('./npm-link'); var print = apputil.print; var settingUpGpg = path.resolve(path.dirname(__dirname), 'docs', 'setting-up-gpg.md'); var isWin = process.platform === 'win32'; exports.GPG_DOCS = settingUpGpg; -exports.createCommand = function*(argv) { - var opt = flagutil.registerRepoFlag(optimist) +exports.createCommand = function * (argv) { + var opt = flagutil.registerRepoFlag(optimist); opt = opt .options('tag', { desc: 'The pre-existing tag or hash to archive (defaults to newest tag on branch)' - }) + }) .options('allow-pending', { desc: 'Whether to allow uncommitted changes to exist when packing (use only for testing)', type: 'boolean' - }) + }) .options('sign', { desc: 'Whether to create .asc, .md5, .sha files (defaults to true)', type: 'boolean', default: 'true' - }) + }) .options('dest', { desc: 'The directory to hold the resulting files.', default: '.' - }); + }); opt = flagutil.registerHelpFlag(opt); - var argv = opt + var argv = opt // eslint-disable-line .usage('Creates a .zip, .asc, .md5, .sha for a repo at a tag or hash.\n' + 'Refer to ' + settingUpGpg + ' for how to set up gpg\n' + '\n' + 'Usage: $0 create-archive [--tag tagname] [--sign] --repo=name [-r repos] --dest cordova-dist-dev/CB-1111') .argv; // Optimist doesn't cast from string :( - argv.sign = argv.sign === true || argv.sign == 'true'; - argv['allow-pending'] = argv['allow-pending'] === true || argv['allow-pending'] == 'true'; + argv.sign = argv.sign === true || argv.sign === 'true'; + argv['allow-pending'] = argv['allow-pending'] === true || argv['allow-pending'] === 'true'; if (argv.h) { optimist.showHelp(); @@ -79,8 +78,8 @@ exports.createCommand = function*(argv) { shelljs.mkdir('-p', outDir); var absOutDir = path.resolve(outDir); - yield repoutil.forEachRepo(repos, function*(repo) { - if(isWin) { + yield repoutil.forEachRepo(repos, function * (repo) { + if (isWin) { yield checkLineEndings(repo); } @@ -104,19 +103,19 @@ exports.createCommand = function*(argv) { print(); print('Archives created.'); print('Verify them using: coho verify-archive ' + path.join(outDir, '*.tgz')); -} +}; // WARNING: NEEDS to be executed in the current working directory of a cordova repo!!! -function *createArchive(repo, tag, outDir, sign) { +function * createArchive (repo, tag, outDir, sign) { print('Creating archive of ' + repo.repoName + '@' + tag); var outPath; - if (repo.id !=='mobile-spec') { + if (repo.id !== 'mobile-spec') { var pkgInfo = require(path.resolve('package')); var tgzname = pkgInfo.name + '-' + tag + '.tgz'; yield executil.execHelper(executil.ARGS('npm pack'), 1, false); outPath = path.join(outDir, tgzname); - if (path.resolve(tgzname) != outPath) { - shelljs.rm('-f', outPath + "*"); + if (path.resolve(tgzname) !== outPath) { + shelljs.rm('-f', outPath + '*'); shelljs.mv(tgzname, outPath); } } else { @@ -134,7 +133,7 @@ function *createArchive(repo, tag, outDir, sign) { exports.createArchive = createArchive; -exports.verifyCommand = function*() { +exports.verifyCommand = function * () { var opt = flagutil.registerHelpFlag(optimist); var argv = opt .usage('Ensures the given .zip files match their neighbouring .asc, .md5, .sha files.\n' + @@ -167,7 +166,7 @@ exports.verifyCommand = function*() { print(chalk.green('Verified ' + resolvedZipPaths.length + ' signatures and hashes.')); }; -function *verifyArchive(archive) { +function * verifyArchive (archive) { var result = yield executil.execHelper(executil.ARGS('gpg --verify', archive + '.asc', archive), false, true); if (result === null) { apputil.fatal('Verification failed. You may need to update your keys. Run: curl "https://dist.apache.org/repos/dist/release/cordova/KEYS" | gpg --import'); @@ -179,7 +178,7 @@ function *verifyArchive(archive) { var sha = yield computeHash(archive, 'SHA512'); var archiveFileName = archive + '.sha512'; var oldArchiveFileName = archive + '.sha'; - + if (fs.existsSync(oldArchiveFileName) && !fs.existsSync(archiveFileName)) { print('Old .sha extension found, this might have been generated by an old cordova-coho version. Using .sha extension for the check.'); archiveFileName = oldArchiveFileName; @@ -193,43 +192,43 @@ function *verifyArchive(archive) { exports.verifyArchive = verifyArchive; -function *computeHash(path, algo) { +function * computeHash (path, algo) { print('Computing ' + algo + ' for: ' + path); var result = yield executil.execHelper(executil.ARGS('gpg --print-md', algo, path), true); return extractHashFromOutput(result); } -function extractHashFromOutput(output) { +function extractHashFromOutput (output) { return output.slice(output.lastIndexOf(':') + 1).replace(/\s*/g, '').toLowerCase(); } -function *checkLineEndings(repo) { +function * checkLineEndings (repo) { var autoCRLF; var eol; var msg = ''; try { autoCRLF = yield executil.execHelper(executil.ARGS('git config --get core.autocrlf'), true); - } catch(e) { + } catch (e) { autoCRLF = ''; } try { eol = yield executil.execHelper(executil.ARGS('git config --get core.eol'), true); - } catch(e) { + } catch (e) { eol = ''; } - if(autoCRLF !== 'false') { + if (autoCRLF !== 'false') { msg = 'Warning: core.autocrlf is set to "' + autoCRLF + '".\n' + 'Set either "' + repo.repoName + '" or global core.autocrlf setting to "false" to avoid issues with executables on non-Windows OS.\n'; } - if(eol !== 'lf') { + if (eol !== 'lf') { msg += 'Warning: core.eol is set to "' + eol + '". Set it to "lf" to normalize line endings.\n'; } - if(!!msg) { + if (msg) { console.error(msg + 'Run these commands in the repos:\n' + ' git config core.eol lf\n' + http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/34ae0bbb/src/executil.js ---------------------------------------------------------------------- diff --git a/src/executil.js b/src/executil.js index 3b294b5..fd5838e 100644 --- a/src/executil.js +++ b/src/executil.js @@ -23,7 +23,7 @@ var print = apputil.print; var gitCommitCount = 0; -function ARGS(s, var_args) { +function ARGS (s, var_args) { var ret = s.trim().split(/\s+/); for (var i = 1; i < arguments.length; ++i) { ret.push(arguments[i]); @@ -40,9 +40,9 @@ exports.verbose = false; // silent == 3 ==> print command, don't print output // TODO: this function should be consolidated to promises, and shouldnt take win/fail callbacks. // some async confusion here -function execHelper(cmdAndArgs, silent, allowError, win, fail) { +function execHelper (cmdAndArgs, silent, allowError, win, fail) { // there are times where we want silent but not allowError. - if (null == allowError) { + if (allowError == null) { // default to allow failure if being silent. allowError = allowError || silent; } @@ -54,10 +54,10 @@ function execHelper(cmdAndArgs, silent, allowError, win, fail) { print('Executing:', cmdAndArgs.join(' ')); } var result = superspawn.spawn(cmdAndArgs[0], cmdAndArgs.slice(1), {stdio: (silent && (silent !== 2)) ? 'default' : 'inherit'}); - return result.then(win || null, fail || function(e) { + return result.then(win || null, fail || function (e) { if (allowError) { throw e; - } else if (+silent != 1) { + } else if (+silent !== 1) { print(e.output); } process.exit(2); @@ -65,10 +65,10 @@ function execHelper(cmdAndArgs, silent, allowError, win, fail) { } exports.execHelper = execHelper; -function reportGitPushResult(repos, branches) { +function reportGitPushResult (repos, branches) { print(''); if (gitCommitCount) { - var flagsStr = repos.map(function(r) { return '-r ' + r.id; }).join(' ') + ' ' + branches.map(function(b) { return '-b ' + b; }).join(' '); + var flagsStr = repos.map(function (r) { return '-r ' + r.id; }).join(' ') + ' ' + branches.map(function (b) { return '-b ' + b; }).join(' '); print('All work complete. ' + gitCommitCount + ' commits were made locally.'); print('To review changes:'); print(' ' + process.argv[1] + ' repo-status ' + flagsStr + ' --diff | less'); @@ -83,7 +83,7 @@ function reportGitPushResult(repos, branches) { exports.reportGitPushResult = reportGitPushResult; -function *execOrPretend(cmd, pretend) { +function * execOrPretend (cmd, pretend) { if (pretend) { print('PRETENDING TO RUN: ' + cmd.join(' ')); } else { http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/34ae0bbb/src/flagutil.js ---------------------------------------------------------------------- diff --git a/src/flagutil.js b/src/flagutil.js index 197f790..3e4b054 100644 --- a/src/flagutil.js +++ b/src/flagutil.js @@ -17,31 +17,30 @@ specific language governing permissions and limitations under the License. */ -var path = require('path'); var apputil = require('./apputil'); var repoutil = require('./repoutil'); -exports.registerHelpFlag = function(opt) { +exports.registerHelpFlag = function (opt) { return opt.options('h', { alias: 'help', desc: 'Shows help information.' }); -} +}; -exports.registerRepoFlag = function(opt) { +exports.registerRepoFlag = function (opt) { return opt.options('r', { alias: 'repo', - desc: 'Which repos to operate on. Multiple flags allowed. This can be repo IDs or repo groups. Use the list-repos command see valid values.', + desc: 'Which repos to operate on. Multiple flags allowed. This can be repo IDs or repo groups. Use the list-repos command see valid values.' }); -} +}; -exports.registerDepthFlag = function(opt) { +exports.registerDepthFlag = function (opt) { return opt.options('depth', { desc: 'Value of --depth flag for git repos.' }); -} +}; -exports.computeReposFromFlag = function(flagValue, opts) { +exports.computeReposFromFlag = function (flagValue, opts) { opts = opts || {}; var includeSvn = opts.includeSvn; var includeModules = opts.includeModules; @@ -54,7 +53,7 @@ exports.computeReposFromFlag = function(flagValue, opts) { var ret = []; var addedIds = {}; var addedRepos = {}; - function addRepo(repo) { + function addRepo (repo) { if (!addedIds[repo.id]) { addedIds[repo.id] = true; @@ -76,8 +75,8 @@ exports.computeReposFromFlag = function(flagValue, opts) { } } } - values.forEach(function(value) { - if (value == '.') { + values.forEach(function (value) { + if (value === '.') { value = repoutil.resolveCwdRepo(); } var repo = repoutil.getRepoById(value); @@ -92,24 +91,22 @@ exports.computeReposFromFlag = function(flagValue, opts) { }); if (!includeSvn) { var hadSvn = false; - ret = ret.filter(function(r) { + ret = ret.filter(function (r) { hadSvn = hadSvn || !!r.svn; return !r.svn; }); - if (hadSvn && !(values.length == 1 && values[0] == 'auto')) { + if (hadSvn && !(values.length === 1 && values[0] === 'auto')) { console.warn('Skipping one or more non-git repos'); } } return ret; -} +}; -exports.validateVersionString = function(version, opt_allowNonSemver) { +exports.validateVersionString = function (version, opt_allowNonSemver) { var pattern = opt_allowNonSemver ? /^\d+\.\d+\.\d+(-?rc\d)?$/ : /^\d+\.\d+\.\d+(-rc\d)?$/; if (!pattern.test(version)) { apputil.fatal('Versions must be in the form #.#.#-[rc#]'); } return version; -} - - +}; http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/34ae0bbb/src/for-each.js ---------------------------------------------------------------------- diff --git a/src/for-each.js b/src/for-each.js index 4d26145..d71a60b 100644 --- a/src/for-each.js +++ b/src/for-each.js @@ -18,13 +18,13 @@ under the License. */ var optimist = require('optimist'); -var path = require('path'); var executil = require('./executil'); var flagutil = require('./flagutil'); var repoutil = require('./repoutil'); -module.exports = function*() { - var opt = flagutil.registerRepoFlag(optimist), cmd; +module.exports = function * () { + var opt = flagutil.registerRepoFlag(optimist); + var cmd; opt = flagutil.registerHelpFlag(opt); var argv = opt .usage('Performs the supplied shell command in each repo directory.\n' + @@ -44,12 +44,11 @@ module.exports = function*() { cmd = [process.env['SHELL'] || 'sh', '-c', argv._[1]]; } - yield repoutil.forEachRepo(repos, function*(repo) { - var replacedCmd = []; - for (var i = 0; i < cmd.length; i++) { - replacedCmd[i] = cmd[i].replace(/\$r/g, repo.repoName); - } - yield executil.execHelper(replacedCmd, false, true); + yield repoutil.forEachRepo(repos, function * (repo) { + var replacedCmd = []; + for (var i = 0; i < cmd.length; i++) { + replacedCmd[i] = cmd[i].replace(/\$r/g, repo.repoName); + } + yield executil.execHelper(replacedCmd, false, true); }); -} - +}; http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/34ae0bbb/src/gitutil.js ---------------------------------------------------------------------- diff --git a/src/gitutil.js b/src/gitutil.js index e44cff7..fe7c558 100644 --- a/src/gitutil.js +++ b/src/gitutil.js @@ -17,7 +17,6 @@ specific language governing permissions and limitations under the License. */ -var path = require('path'); var executil = require('./executil'); var gitutil = exports; var semver = require('semver'); @@ -29,8 +28,8 @@ var semver = require('semver'); * @returns {Array} - the most recent tag as as the 0th index in an array (with the second recent as the next index), or null if no version tags are found. * ignores r tags in plugins */ -exports.findMostRecentTag = function*(prefix) { - prefix = prefix && prefix + "-"; +exports.findMostRecentTag = function * (prefix) { + prefix = prefix && prefix + '-'; var finalBest; var lastBest; @@ -39,7 +38,7 @@ exports.findMostRecentTag = function*(prefix) { 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 ) { + if (value.indexOf(prefix) !== 0) { modifiedValue = null; modifiedCurBest = null; } else { @@ -47,13 +46,13 @@ exports.findMostRecentTag = function*(prefix) { modifiedCurBest = curBest && curBest.substr(prefix.length); } } else { - //used to strip out r for plugins, but now leave it in so they fail semver check + // used to strip out r for plugins, but now leave it in so they fail semver check modifiedCurBest = curBest; modifiedValue = value; } if (semver.valid(modifiedValue)) { - //use finalBest to hold onto reference outside of reduce function + // use finalBest to hold onto reference outside of reduce function finalBest = !curBest ? value : semver.gt(modifiedCurBest, modifiedValue) ? finalBest : value; if (curBest < finalBest) { lastBest = curBest; @@ -64,7 +63,7 @@ exports.findMostRecentTag = function*(prefix) { lastBest = curBest; } return curBest; - } else if(finalBest) { + } else if (finalBest) { if (curBest < finalBest) { lastBest = curBest; } @@ -73,22 +72,22 @@ exports.findMostRecentTag = function*(prefix) { return null; }); - if (ret) { - if (lastBest) { - return [ ret, lastBest ]; - } else { - return [ ret ]; - } + if (ret) { + if (lastBest) { + return [ ret, lastBest ]; } else { - return null; + return [ ret ]; } + } else { + return null; + } }; -exports.tagExists = function*(tagName) { +exports.tagExists = function * (tagName) { return !!(yield executil.execHelper(executil.ARGS('git tag --list ' + tagName), true)); -} +}; -exports.retrieveCurrentBranchName = function*(allowDetached) { +exports.retrieveCurrentBranchName = function * (allowDetached) { var ref; try { ref = yield executil.execHelper(executil.ARGS('git symbolic-ref HEAD'), true, true); @@ -103,9 +102,9 @@ exports.retrieveCurrentBranchName = function*(allowDetached) { throw new Error('Could not parse branch name from: ' + ref); } return match[1]; -} +}; -exports.remoteBranchExists = function*(repo, branch) { +exports.remoteBranchExists = function * (repo, branch) { var branch_token = (repo.remoteName || 'origin') + '/' + branch; var stdout = yield executil.execHelper(executil.ARGS('git branch -r --list ' + branch_token), false, false); if (stdout.indexOf(branch_token) > -1) { @@ -113,9 +112,9 @@ exports.remoteBranchExists = function*(repo, branch) { } else { return false; } -} +}; -exports.stashAndPop = function*(repo, func) { +exports.stashAndPop = function * (repo, func) { var requiresStash = yield gitutil.pendingChangesExist(); var branchName = yield gitutil.retrieveCurrentBranchName(); @@ -129,70 +128,70 @@ exports.stashAndPop = function*(repo, func) { if (requiresStash) { yield executil.execHelper(executil.ARGS('git stash pop')); } -} +}; -exports.pendingChangesExist = function*() { +exports.pendingChangesExist = function * () { return !!(yield executil.execHelper(executil.ARGS('git status --porcelain'), true)); -} +}; -exports.gitCheckout = function*(branchName) { +exports.gitCheckout = function * (branchName) { var curBranch = yield gitutil.retrieveCurrentBranchName(true); - if (curBranch != branchName) { + if (curBranch !== branchName) { return yield executil.execHelper(executil.ARGS('git checkout -q ', branchName)); } -} +}; -exports.createNewBranch = function*(branchName) { +exports.createNewBranch = function * (branchName) { return yield executil.execHelper(executil.ARGS('git branch ', branchName)); -} +}; -exports.localBranchExists = function*(name) { +exports.localBranchExists = function * (name) { return !!(yield executil.execHelper(executil.ARGS('git branch --list ' + name), true)); -} +}; -exports.retrieveCurrentTagName = function() { +exports.retrieveCurrentTagName = function () { // This will return the tag name plus commit info it not directly at a tag. // That's fine since all users of this function are meant to use the result // in an equality check. return executil.execHelper(executil.ARGS('git describe --tags HEAD'), true, true); -} +}; -exports.hashForRef = function(ref) { +exports.hashForRef = function (ref) { return executil.execHelper(executil.ARGS('git rev-parse', ref), true, true); }; -exports.resetFromOrigin = function() { +exports.resetFromOrigin = function () { return executil.execHelper(executil.ARGS('git reset --hard origin/master'), false, true); -} +}; -exports.gitClean = function() { +exports.gitClean = function () { return executil.execHelper(executil.ARGS('git clean -d -f'), false, true); -} +}; -exports.summaryOfChanges = function*(base_sha) { +exports.summaryOfChanges = function * (base_sha) { var cmd = executil.ARGS('git log --topo-order --no-merges'); cmd.push(['--pretty=format:* %s']); cmd.push(base_sha + '..master'); return yield executil.execHelper(cmd, true, false); -} +}; -exports.commitChanges = function*(commit_msg) { +exports.commitChanges = function * (commit_msg) { return yield executil.execHelper(executil.ARGS('git commit -am', commit_msg)); -} +}; -exports.tagRepo = function*(version) { +exports.tagRepo = function * (version) { return yield executil.execHelper(executil.ARGS('git tag', version)); -} +}; -exports.pushToOrigin = function*(ref) { +exports.pushToOrigin = function * (ref) { return yield executil.execHelper(executil.ARGS('git push origin', ref)); -} +}; -exports.diff = function*(first, second) { +exports.diff = function * (first, second) { var args = executil.ARGS('git diff', first + '..' + second); return yield executil.execHelper(args, true, false); -} +}; -exports.merge = function*(ref, win, fail) { +exports.merge = function * (ref, win, fail) { return yield executil.execHelper(executil.ARGS('git merge', ref), false, false, win, fail); -} +}; http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/34ae0bbb/src/last-week.js ---------------------------------------------------------------------- diff --git a/src/last-week.js b/src/last-week.js index 8faa8f4..ccfa521 100644 --- a/src/last-week.js +++ b/src/last-week.js @@ -18,36 +18,36 @@ under the License. */ var optimist = require('optimist'); -var path = require('path'); var apputil = require('./apputil'); var executil = require('./executil'); var flagutil = require('./flagutil'); var repoutil = require('./repoutil'); -module.exports = function*() { +module.exports = function * () { var meEmail = yield executil.execHelper(executil.ARGS('git config user.email'), true); var opt = flagutil.registerRepoFlag(optimist); opt = flagutil.registerHelpFlag(opt) .options('me', { - desc: 'Show only your commits. Short for --user=' + meEmail + ' --cherry-picks=false', - type: 'boolean' - }) + desc: 'Show only your commits. Short for --user=' + meEmail + ' --cherry-picks=false', + type: 'boolean' + }) .options('cherry-picks', { - desc: 'Show changes that you authored, even if you didn\'t commit them', - type: 'boolean', - default: true - }) + desc: 'Show changes that you authored, even if you didn\'t commit them', + type: 'boolean', + default: true + }) .options('user', { - desc: 'Show commits for the given user (substring match)', - type: 'string' - }) + desc: 'Show commits for the given user (substring match)', + type: 'string' + }) .options('days', { - desc: 'Show history for this many days instead of past week.', - type: 'number' - }) + desc: 'Show history for this many days instead of past week.', + type: 'number' + }) .usage('Shows formatted git log for changes in the past 7 days.\n' + '\n' + 'Usage: $0 last-week [--repo=ios] [--me] [--days=7] [--cherry-picks] [--user=someone]'); + /* eslint-disable no-undef */ argv = opt.argv; if (argv.h) { @@ -55,13 +55,13 @@ module.exports = function*() { process.exit(1); } var repos = flagutil.computeReposFromFlag(argv.r, {includeModules: true}); - var filterByEmail = !!argv.me || !! argv.user; + var filterByEmail = !!argv.me || !!argv.user; var days = argv.days || 7; var userEmail = filterByEmail && (argv.user || meEmail); var showCherryPicks = !argv.me && argv['cherry-picks']; var commitCount = 0; var pullRequestCount = 0; - + /* eslint-enable no-undef */ var cmd = executil.ARGS('git log --no-merges --date=short --all-match --fixed-strings'); if (filterByEmail) { cmd.push('--author=' + userEmail); @@ -71,7 +71,7 @@ module.exports = function*() { } apputil.print('Running command: ' + cmd.join(' ') + ' --format="$REPO_NAME %s" --since="' + days + ' days ago"'); - yield repoutil.forEachRepo(repos, function*(repo) { + yield repoutil.forEachRepo(repos, function * (repo) { var repoName = repo.id + new Array(Math.max(0, 20 - repo.id.length + 1)).join(' '); var format = '--format=' + repoName; if (!filterByEmail) { @@ -88,14 +88,14 @@ module.exports = function*() { if (filterByEmail) { console.log('\nPull requests:'); cmd = executil.ARGS('git log --no-merges --date=short --fixed-strings', '--committer=' + userEmail); - yield repoutil.forEachRepo(repos, function*(repo) { + 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']).concat(repoutil.getRepoIncludePath(repo)), true); if (output) { - output.split('\n').forEach(function(line) { + output.split('\n').forEach(function (line) { line = line.replace(/(.*?)\|/, ''); - if (RegExp.lastParen.indexOf(userEmail) == -1) { + if (RegExp.lastParen.indexOf(userEmail) === -1) { console.log(line); pullRequestCount += 1; } @@ -110,4 +110,4 @@ module.exports = function*() { } else { console.log('Total Commits: ' + commitCount); } -} +}; http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/34ae0bbb/src/list-pulls.js ---------------------------------------------------------------------- diff --git a/src/list-pulls.js b/src/list-pulls.js index 7545d2a..3a111d9 100644 --- a/src/list-pulls.js +++ b/src/list-pulls.js @@ -21,20 +21,19 @@ var optimist = require('optimist'); var request = require('request'); var apputil = require('./apputil'); var flagutil = require('./flagutil'); -var repoutil = require('./apputil'); // Set env variable CORDOVA_GIT_ACCOUNT to <username>:<password> or <api-token> to avoid hitting GitHub rate limits. -var GITHUB_ACCOUNT = process.env.CORDOVA_GIT_ACCOUNT ? process.env.CORDOVA_GIT_ACCOUNT + "@" : ""; -var GITHUB_API_URL = "https://" + GITHUB_ACCOUNT + "api.github.com/"; -var GITHUB_ORGANIZATION = "apache"; +var GITHUB_ACCOUNT = process.env.CORDOVA_GIT_ACCOUNT ? process.env.CORDOVA_GIT_ACCOUNT + '@' : ''; +var GITHUB_API_URL = 'https://' + GITHUB_ACCOUNT + 'api.github.com/'; +var GITHUB_ORGANIZATION = 'apache'; var commentFailed = false; -function addLastCommentInfo(repo, pullRequests, callback) { +function addLastCommentInfo (repo, pullRequests, callback) { var remaining = pullRequests.length; if (remaining === 0) { callback(); } - pullRequests.forEach(function(pullRequest) { + pullRequests.forEach(function (pullRequest) { var commentsUrl = pullRequest._links.comments && pullRequest._links.comments.href; var reviewCommentsUrl = pullRequest._links.review_comments && pullRequest._links.review_comments.href; @@ -58,7 +57,7 @@ function addLastCommentInfo(repo, pullRequests, callback) { }); } else { // Otherwise, resort to scraping. - request.get({ url: 'https://github.com/apache/' + repo + '/pull/' + pullRequest.number, headers: { 'User-Agent': 'Cordova Coho' }}, function(err, res, payload) { + request.get({ url: 'https://github.com/apache/' + repo + '/pull/' + pullRequest.number, headers: { 'User-Agent': 'Cordova Coho' } }, function (err, res, payload) { if (err) { if (!commentFailed) { commentFailed = true; @@ -66,7 +65,7 @@ function addLastCommentInfo(repo, pullRequests, callback) { } } else { var m = /[\s\S]*timeline-comment-header[\s\S]*?"author".*?>(.*?)</.exec(payload); - pullRequest.lastUpdatedBy = m && m[1] || ''; + (pullRequest.lastUpdatedBy = m && m[1]) || (''); // eslint-disable-line no-unused-expressions } if (--remaining === 0) { callback(); @@ -76,7 +75,7 @@ function addLastCommentInfo(repo, pullRequests, callback) { }); } -function getPullRequestComments(url, existingComments, callback) { +function getPullRequestComments (url, existingComments, callback) { if (GITHUB_ACCOUNT) { url = url.replace('https://', 'https://' + GITHUB_ACCOUNT); } @@ -110,17 +109,17 @@ function getPullRequestComments(url, existingComments, callback) { }); } -function listGitHubPullRequests(repo, maxAge, hideUser, short, statsOnly, callback) { +function listGitHubPullRequests (repo, maxAge, hideUser, short, statsOnly, callback) { var url = GITHUB_API_URL + 'repos/' + GITHUB_ORGANIZATION + '/' + repo + '/pulls'; - request.get({ url: url, headers: { 'User-Agent': 'Cordova Coho' }}, function(err, res, pullRequests) { + request.get({ url: url, headers: { 'User-Agent': 'Cordova Coho' } }, function (err, res, pullRequests) { if (err) { apputil.fatal('Error getting pull requests from GitHub: ' + err); } else if (!pullRequests) { apputil.fatal('Error: GitHub returned no pull requests'); - } else if (res.headers['x-ratelimit-remaining'] && res.headers['x-ratelimit-remaining'] == 0) { + } else if (res.headers['x-ratelimit-remaining'] && res.headers['x-ratelimit-remaining'] === 0) { var resetEpoch = new Date(res.headers['x-ratelimit-reset'] * 1000); - var expiration = resetEpoch.getHours() + ":" + resetEpoch.getMinutes() + ":" + resetEpoch.getSeconds(); + var expiration = resetEpoch.getHours() + ':' + resetEpoch.getMinutes() + ':' + resetEpoch.getSeconds(); apputil.fatal('Error: GitHub rate limit exceeded, wait till ' + expiration + ' before trying again.\n' + 'See http://developer.github.com/v3/#rate-limiting for details.'); } @@ -129,11 +128,11 @@ function listGitHubPullRequests(repo, maxAge, hideUser, short, statsOnly, callba var origCount = pullRequests.length; if (pullRequests.message === 'Bad credentials') { - apputil.fatal('Error: GitHub Bad credentials. Check your CORDOVA_GIT_ACCOUNT environment variable which should be set with your Github API token: https://github.com/settings/tokens.', + apputil.fatal('Error: GitHub Bad credentials. Check your CORDOVA_GIT_ACCOUNT environment variable which should be set with your Github API token: https://github.com/settings/tokens.', 'CORDOVA_GIT_ACCOUNT used: ' + process.env['CORDOVA_GIT_ACCOUNT']); - } + } - pullRequests = pullRequests.filter(function(p) { + pullRequests = pullRequests.filter(function (p) { var updatedDate = new Date(p.updated_at); var daysAgo = Math.round((new Date() - updatedDate) / (60 * 60 * 24 * 1000)); return daysAgo < maxAge; @@ -146,26 +145,26 @@ function listGitHubPullRequests(repo, maxAge, hideUser, short, statsOnly, callba next(); } - function next() { + function next () { var cbObj = { - "repo": repo, - "fresh-count": 0, - "old-count": 0, - "stale-count": 0, - "total-count": origCount, - "message": null - }; + 'repo': repo, + 'fresh-count': 0, + 'old-count': 0, + 'stale-count': 0, + 'total-count': origCount, + 'message': null + }; if (hideUser) { - pullRequests = pullRequests.filter(function(p) { - return p.lastUpdatedBy != hideUser; + pullRequests = pullRequests.filter(function (p) { + return p.lastUpdatedBy !== hideUser; }); } var count = pullRequests.length; cbObj['fresh-count'] = count; if (!statsOnly) { - pullRequests.sort(function(a,b) {return (a.updated_at > b.updated_at) ? -1 : ((b.updated_at > a.updated_at) ? 1 : 0);} ); + pullRequests.sort(function (a, b) { return (a.updated_at > b.updated_at) ? -1 : ((b.updated_at > a.updated_at) ? 1 : 0); }); } var countMsg = count + ' Pull Requests'; @@ -192,7 +191,7 @@ function listGitHubPullRequests(repo, maxAge, hideUser, short, statsOnly, callba } if (!statsOnly) { - pullRequests.forEach(function(pullRequest) { + pullRequests.forEach(function (pullRequest) { var updatedDate = new Date(pullRequest.updated_at); var daysAgo = Math.round((new Date() - updatedDate) / (60 * 60 * 24 * 1000)); console.log('\x1B[33m-----------------------------------------------------------------------------------------------\x1B[39m'); @@ -222,33 +221,33 @@ function listGitHubPullRequests(repo, maxAge, hideUser, short, statsOnly, callba }); } -function *listPullRequestsCommand() { +function * listPullRequestsCommand () { var opt = flagutil.registerHelpFlag(optimist); opt = flagutil.registerRepoFlag(opt) .options('max-age', { desc: 'Don\'t show pulls older than this (in days)', type: 'number', default: 1000 - }) + }) .options('hide-user', { desc: 'Hide PRs where the last comment\'s is by this github user.', type: 'string' - }) + }) .options('stats-only', { desc: 'List stats for PRs in the repos specified.', type: 'bool' - }) + }) .options('sort-ascending', { desc: 'Used in conjunction with --stats-only. Sort the PRs ascending.', type: 'bool' - }) + }) .options('json', { desc: 'Used in conjunction with --stats-only. Output the report in JSON format.', type: 'bool' - }) + }) .options('short', { - desc: 'Truncates PR body description', - type: 'bool' + desc: 'Truncates PR body description', + type: 'bool' }); opt.usage('Reports what GitHub pull requests are open for the given repositories.\n' + '\n' + @@ -268,15 +267,15 @@ function *listPullRequestsCommand() { var repos = flagutil.computeReposFromFlag(argv.r); var report = { - "title" : "coho list-pulls report", + 'title': 'coho list-pulls report', // "command" : process.argv, - "timestamp" : new Date().toJSON(), - "max-age": argv['max-age'], - "repos" : [] + 'timestamp': new Date().toJSON(), + 'max-age': argv['max-age'], + 'repos': [] }; var simple_report = []; - function next(reportObject) { + function next (reportObject) { if (reportObject && argv['stats-only']) { if (argv.json) { report.repos.push(reportObject); @@ -288,31 +287,31 @@ function *listPullRequestsCommand() { if (repos.length) { var repo = repos.shift(); listGitHubPullRequests(repo.repoName, argv['max-age'], argv['hide-user'], argv.short, argv['stats-only'], next); - } else if (argv['stats-only']){ // done - function compareFunc(a, b) { + } else if (argv['stats-only']) { // done + function compareFunc (a, b) { // eslint-disable-line no-inner-declarations if (a['fresh-count'] < b['fresh-count']) { - return argv['sort-ascending']? -1 : 1; + return argv['sort-ascending'] ? -1 : 1; } if (a['fresh-count'] > b['fresh-count']) { - return argv['sort-ascending']? 1 : -1; + return argv['sort-ascending'] ? 1 : -1; } return 0; - }; + } if (argv.json) { report.repos.sort(compareFunc); - console.log(JSON.stringify(report, null, 4)); + console.log(JSON.stringify(report, null, 4)); } else { simple_report.sort(compareFunc); - simple_report.forEach(function(report) { + simple_report.forEach(function (report) { console.log(report.repo + ' --> ' + report.message); }); } } } - + var url = 'https://github.com/pulls?utf8=%E2%9C%93&q=is%3Aopen+is%3Apr'; - repos.forEach(function(repo) { + repos.forEach(function (repo) { url += '+repo%3Aapache%2F' + repo.repoName; }); if (!(argv['stats-only'] && argv['json'])) { http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/34ae0bbb/src/list-release-urls.js ---------------------------------------------------------------------- diff --git a/src/list-release-urls.js b/src/list-release-urls.js index 287832b..eed3da5 100644 --- a/src/list-release-urls.js +++ b/src/list-release-urls.js @@ -23,15 +23,15 @@ var flagutil = require('./flagutil'); var gitutil = require('./gitutil'); var repoutil = require('./repoutil'); -module.exports = function*(argv) { - var opt = flagutil.registerRepoFlag(optimist) +module.exports = function * (argv) { + var opt = flagutil.registerRepoFlag(optimist); opt = opt .options('version', { desc: 'The version of the release. E.g. 2.7.1-rc2', demand: true - }) + }); opt = flagutil.registerHelpFlag(opt); - var argv = opt + var argv = opt // eslint-disable-line no-redeclare .usage('List the apache git repo urls for release artifacts.\n' + '\n' + 'Usage: $0 list-release-urls [-r repos] --version=2.7.1-rc2') @@ -45,7 +45,7 @@ module.exports = function*(argv) { var version = argv['version']; var baseUrl = 'http://git-wip-us.apache.org/repos/asf?p=%s.git;a=shortlog;h=refs/tags/%s'; - yield repoutil.forEachRepo(repos, function*(repo) { + yield repoutil.forEachRepo(repos, function * (repo) { if (!(yield gitutil.tagExists(version))) { console.error('Tag "' + version + '" does not exist in repo ' + repo.repoName); return; @@ -54,5 +54,4 @@ module.exports = function*(argv) { console.log(url); yield executil.execHelper(executil.ARGS('git show-ref ' + version), 2, true); }); -} - +}; http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/34ae0bbb/src/list-repos.js ---------------------------------------------------------------------- diff --git a/src/list-repos.js b/src/list-repos.js index 3afe570..14a7ea9 100644 --- a/src/list-repos.js +++ b/src/list-repos.js @@ -19,20 +19,19 @@ under the License. var repoutil = require('./repoutil'); -module.exports = function*(argv) { +module.exports = function * (argv) { console.log('Valid values for the --repo flag:'); console.log(''); console.log('Repositories:'); - repoutil.repoGroups.all.forEach(function(repo) { + repoutil.repoGroups.all.forEach(function (repo) { console.log(' ' + repo.id); }); console.log(''); console.log('Repository Groups:'); var groupNames = Object.keys(repoutil.repoGroups); groupNames.sort(); - groupNames.forEach(function(groupName) { - console.log(' ' + groupName + ' (' + repoutil.repoGroups[groupName].map(function(repo) { return repo.id }).join(', ') + ')'); + groupNames.forEach(function (groupName) { + console.log(' ' + groupName + ' (' + repoutil.repoGroups[groupName].map(function (repo) { return repo.id; }).join(', ') + ')'); }); process.exit(0); -} - +}; http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/34ae0bbb/src/main.js ---------------------------------------------------------------------- diff --git a/src/main.js b/src/main.js index 5d3ef10..958bca4 100644 --- a/src/main.js +++ b/src/main.js @@ -17,7 +17,6 @@ specific language governing permissions and limitations under the License. */ -var path = require('path'); var executil = require('./executil'); try { @@ -26,12 +25,12 @@ try { // Ensure npm install has been run. Object.keys(require('../package').dependencies).forEach(require); } catch (e) { - console.log('Please run "npm install" from this directory:\n\t' + __dirname); + console.log('Please run "npm install" from this directory:\n\t' + __dirname); // eslint-disable-line no-path-concat process.exit(2); } var apputil = require('./apputil'); -function *lazyRequire(name, opt_prop) { +function * lazyRequire (name, opt_prop) { if (opt_prop) { yield require(name)[opt_prop]; } else { @@ -39,7 +38,7 @@ function *lazyRequire(name, opt_prop) { } } -module.exports = function() { +module.exports = function () { var repoCommands = [ { name: 'repo-clone', @@ -67,105 +66,105 @@ module.exports = function() { entryPoint: lazyRequire('./list-repos') }]; var releaseCommands = [{ - name: 'prepare-platform-release-branch', - desc: 'Branches, updates JS, updates VERSION. Safe to run multiple times.', - entryPoint: lazyRequire('./platform-release', 'prepareReleaseBranchCommand') - }, { - name: 'tag-platform-release', - desc: 'Tags repos for a release.', - entryPoint: lazyRequire('./platform-release', 'tagReleaseBranchCommand') - }, { - name: 'audit-license-headers', - desc: 'Uses Apache RAT to look for missing license headers.', - entryPoint: lazyRequire('./audit-license-headers') - }, { - name: 'check-license', - desc: 'Go through each specified repo and check the licenses of node modules that are 3rd-party dependencies.', - entryPoint: lazyRequire('./check-license') - }, { - name: 'create-archive', - desc: 'Zips up a tag, signs it, and adds checksum files.', - entryPoint: lazyRequire('./create-verify-archive', 'createCommand') - }, { - name: 'verify-archive', - desc: 'Checks that archives are properly signed and hashed.', - entryPoint: lazyRequire('./create-verify-archive', 'verifyCommand') - }, { - name: 'print-tags', - desc: 'Prints out tags & hashes for the given repos. Used in VOTE emails.', - entryPoint: lazyRequire('./print-tags') - }, { - name: 'verify-tags', - desc: 'Verify the tags match the hashes within VOTE emails.', - entryPoint: lazyRequire('./verify-tags') - }, { - name: 'list-release-urls', - desc: 'List the apache git repo urls for release artifacts.', - entryPoint: lazyRequire('./list-release-urls') - }, { - name: 'nightly', - desc: 'Builds and publishes nightly builds of cordova-cli using the latest commits for each platform.', - entryPoint: lazyRequire('./nightly') - }, { - name: 'prepare-tools-release', - desc: 'Prepares tools for release', - entryPoint: lazyRequire('./tools-release', 'prepareToolsRelease') - }, { - name: 'prepare-plugins-release', - desc: 'Prepares plugins for release', - entryPoint: lazyRequire('./plugin-release', 'interactive') - }, { - name: 'npm-publish-tag', - 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 all specified repositories', - entryPoint: lazyRequire('./npm-publish', 'unpublishNightly') - }]; + name: 'prepare-platform-release-branch', + desc: 'Branches, updates JS, updates VERSION. Safe to run multiple times.', + entryPoint: lazyRequire('./platform-release', 'prepareReleaseBranchCommand') + }, { + name: 'tag-platform-release', + desc: 'Tags repos for a release.', + entryPoint: lazyRequire('./platform-release', 'tagReleaseBranchCommand') + }, { + name: 'audit-license-headers', + desc: 'Uses Apache RAT to look for missing license headers.', + entryPoint: lazyRequire('./audit-license-headers') + }, { + name: 'check-license', + desc: 'Go through each specified repo and check the licenses of node modules that are 3rd-party dependencies.', + entryPoint: lazyRequire('./check-license') + }, { + name: 'create-archive', + desc: 'Zips up a tag, signs it, and adds checksum files.', + entryPoint: lazyRequire('./create-verify-archive', 'createCommand') + }, { + name: 'verify-archive', + desc: 'Checks that archives are properly signed and hashed.', + entryPoint: lazyRequire('./create-verify-archive', 'verifyCommand') + }, { + name: 'print-tags', + desc: 'Prints out tags & hashes for the given repos. Used in VOTE emails.', + entryPoint: lazyRequire('./print-tags') + }, { + name: 'verify-tags', + desc: 'Verify the tags match the hashes within VOTE emails.', + entryPoint: lazyRequire('./verify-tags') + }, { + name: 'list-release-urls', + desc: 'List the apache git repo urls for release artifacts.', + entryPoint: lazyRequire('./list-release-urls') + }, { + name: 'nightly', + desc: 'Builds and publishes nightly builds of cordova-cli using the latest commits for each platform.', + entryPoint: lazyRequire('./nightly') + }, { + name: 'prepare-tools-release', + desc: 'Prepares tools for release', + entryPoint: lazyRequire('./tools-release', 'prepareToolsRelease') + }, { + name: 'prepare-plugins-release', + desc: 'Prepares plugins for release', + entryPoint: lazyRequire('./plugin-release', 'interactive') + }, { + name: 'npm-publish-tag', + 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 all specified repositories', + entryPoint: lazyRequire('./npm-publish', 'unpublishNightly') + }]; var otherCommands = [{ - name: 'list-pulls', - desc: 'Shows a list of GitHub pull requests for all specified repositories.', - entryPoint: lazyRequire('./list-pulls') - }, { - name: 'merge-pr', - desc: 'Merges specified PR', - entryPoint: lazyRequire('./merge-pr'), - noChdir : true - }, { - name: 'create-pr', - desc: 'Launches github PR UI for the specified topic branch', - entryPoint: lazyRequire('./create-pr'), - noChdir : true - }, - { - name: 'last-week', - desc: 'Prints out git logs of things that happened last week.', - entryPoint: lazyRequire('./last-week') - }, { - name: 'shortlog', - desc: 'A version of `git shortlog -s` aggregated across multiple repos.', - entryPoint: lazyRequire('./shortlog') - }, { - name: 'for-each', - desc: 'Runs a shell command in each repo.', - entryPoint: lazyRequire('./for-each') - }, { - name: 'npm-link', - desc: 'Does an "npm link" of dependent modules that we own.', - entryPoint: lazyRequire('./npm-link') - }, { - name: 'copy-js', - desc: 'Generates and copies cordova.js to platform.', - entryPoint: lazyRequire('./platform-release.js', 'createAndCopyCordovaJSCommand') - } + name: 'list-pulls', + desc: 'Shows a list of GitHub pull requests for all specified repositories.', + entryPoint: lazyRequire('./list-pulls') + }, { + name: 'merge-pr', + desc: 'Merges specified PR', + entryPoint: lazyRequire('./merge-pr'), + noChdir: true + }, { + name: 'create-pr', + desc: 'Launches github PR UI for the specified topic branch', + entryPoint: lazyRequire('./create-pr'), + noChdir: true + }, + { + name: 'last-week', + desc: 'Prints out git logs of things that happened last week.', + entryPoint: lazyRequire('./last-week') + }, { + name: 'shortlog', + desc: 'A version of `git shortlog -s` aggregated across multiple repos.', + entryPoint: lazyRequire('./shortlog') + }, { + name: 'for-each', + desc: 'Runs a shell command in each repo.', + entryPoint: lazyRequire('./for-each') + }, { + name: 'npm-link', + desc: 'Does an "npm link" of dependent modules that we own.', + entryPoint: lazyRequire('./npm-link') + }, { + name: 'copy-js', + desc: 'Generates and copies cordova.js to platform.', + entryPoint: lazyRequire('./platform-release.js', 'createAndCopyCordovaJSCommand') + } ]; var commandMap = {}; - function addToCommandMap(cmd) { + function addToCommandMap (cmd) { commandMap[cmd.name] = cmd; } repoCommands.forEach(addToCommandMap); @@ -175,7 +174,7 @@ module.exports = function() { commandMap['foreach'] = commandMap['for-each']; var usage = 'Usage: $0 command [options]\n\n'; - function addCommandUsage(cmd) { + function addCommandUsage (cmd) { usage += ' ' + cmd.name + ': ' + cmd.desc + '\n'; } usage += 'Repo Management:\n'; @@ -215,7 +214,7 @@ module.exports = function() { command.noChdir = true; } } - + if (command && !command.noChdir) { opts = opts.options('chdir', { desc: 'Use --no-chdir or --global to run in your CWD instead of the parent of cordova-coho/', @@ -223,7 +222,7 @@ module.exports = function() { default: true }); } - var argv = opts.check(function(argv) { + var argv = opts.check(function (argv) { var commandName = argv._[0]; if (!commandName) { throw 'No command specified.'; http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/34ae0bbb/src/merge-pr.js ---------------------------------------------------------------------- diff --git a/src/merge-pr.js b/src/merge-pr.js index 8e8fed4..b1ced56 100644 --- a/src/merge-pr.js +++ b/src/merge-pr.js @@ -6,9 +6,7 @@ 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 @@ -19,26 +17,24 @@ under the License. var flagutil = require('./flagutil'); var optimist = require('optimist'); -var shelljs = require('shelljs'); var executil = require('./executil'); var gitutil = require('./gitutil'); -var superspawn = require('./superspawn'); var chalk = require('chalk'); var repoutil = require('./repoutil'); -module.exports = function *(argv) { +module.exports = function * (argv) { var opt = flagutil.registerHelpFlag(optimist); opt.options('pr', { - desc: 'PR # that needs to be merged', - demand: true - }); + desc: 'PR # that needs to be merged', + demand: true + }); argv = opt .usage('Merges the pull request to master\n' + '\n' + 'This command will:\n' + '* Update your local master. \n' + '* Fetch the PR and create a branch named `pr/pr#`\n' + - '* Attempt a `--ff-only` merge to master. If this fails then: \n' + + '* Attempt a `--ff-only` merge to master. If this fails then: \n' + ' * Perform a rebase of the `pr/pr#` branch. \n' + ' * Attempt a `--ff-only` merge to master. \n' + ' * On success, it will modify the last commit\'s message to include. `This closes #pr` to ensure the corresponding PR closes on pushing to remote. \n\n' + @@ -46,57 +42,57 @@ module.exports = function *(argv) { '(optional) --pull-only Pulls the change into a branch only, and checks it out. Does not merge it to the master branch.' ) .argv; - if (argv.h) { + if (argv.h) { optimist.showHelp(); process.exit(1); - } - - var pull_only = argv['pull-only']; - var localBranch = 'pr/' + argv.pr; - var currentRepo = repoutil.getRepoById(repoutil.resolveCwdRepo()); - var remote = 'https://github.com/apache/' + currentRepo.repoName; - var origin = 'https://git-wip-us.apache.org/repos/asf/' + currentRepo.repoName; - if (currentRepo.github) { - origin = remote; - } + } + + var pull_only = argv['pull-only']; + var localBranch = 'pr/' + argv.pr; + var currentRepo = repoutil.getRepoById(repoutil.resolveCwdRepo()); + var remote = 'https://github.com/apache/' + currentRepo.repoName; + var origin = 'https://git-wip-us.apache.org/repos/asf/' + currentRepo.repoName; + if (currentRepo.github) { + origin = remote; + } - function* mergePr(){ + function * mergePr () { var commitMessage; yield executil.execHelper(executil.ARGS('git checkout master')); yield executil.execHelper(['git', 'pull', origin, 'master']); - var commit = yield executil.execHelper(executil.ARGS('git rev-parse HEAD'), /*silent*/ true); - yield executil.execHelper(['git', 'fetch', /*force update*/ '-fu', remote, - 'refs/pull/' + argv.pr + '/head:' + localBranch]); + var commit = yield executil.execHelper(executil.ARGS('git rev-parse HEAD'), /* silent */ true); + yield executil.execHelper(['git', 'fetch', /* force update */ '-fu', remote, + 'refs/pull/' + argv.pr + '/head:' + localBranch]); if (!pull_only) { try { yield executil.execHelper(executil.ARGS('git merge --ff-only ' + localBranch), - /*silent*/ true, /*allowError*/ true); - commitMessage = yield executil.execHelper(executil.ARGS('git log --format=%B -n 1 HEAD'), /*silent*/ true); - yield executil.execHelper(['git', 'commit', '--amend', '-m', - commitMessage + '\n\n This closes #' + argv.pr]); - } catch (e) { + /* silent */ true, /* allowError */ true); + commitMessage = yield executil.execHelper(executil.ARGS('git log --format=%B -n 1 HEAD'), /* silent */ true); + yield executil.execHelper(['git', 'commit', '--amend', '-m', + commitMessage + '\n\n This closes #' + argv.pr]); + } catch (e) { if (e.message.indexOf('fatal: Not possible to fast-forward, aborting.') > 0) { // Let's try to rebase yield executil.execHelper(executil.ARGS('git checkout ' + localBranch)); yield executil.execHelper(['git', 'pull', '--rebase', origin, 'master']); yield executil.execHelper(executil.ARGS('git checkout master')); yield executil.execHelper(executil.ARGS('git merge --ff-only ' + localBranch)); - commitMessage = yield executil.execHelper(executil.ARGS('git log --format=%B -n 1 HEAD'), /*silent*/ true); - yield executil.execHelper(['git', 'commit', '--amend', '-m', + commitMessage = yield executil.execHelper(executil.ARGS('git log --format=%B -n 1 HEAD'), /* silent */ true); + yield executil.execHelper(['git', 'commit', '--amend', '-m', commitMessage + '\n\n This closes #' + argv.pr]); } else { throw e; } } - console.log(); - var commits = yield executil.execHelper(['git', 'log', + console.log(); + var commits = yield executil.execHelper(['git', 'log', '--graph', '--pretty=format:%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset', '--abbrev-commit', '--stat', - commit + '..HEAD'], /*silent*/ true); + commit + '..HEAD'], /* silent */ true); if (commits) { console.log('---------------'); @@ -109,9 +105,9 @@ module.exports = function *(argv) { } } } - - yield gitutil.stashAndPop('', mergePr); - if (pull_only) { + + yield gitutil.stashAndPop('', mergePr); + if (pull_only) { yield executil.execHelper(executil.ARGS('git checkout ' + localBranch)); - } -}; \ No newline at end of file + } +}; --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
