You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2014/02/09 02:26:13 UTC

[1/2] git commit: CB-5625 Show open Pull Requests on GitHub

Updated Branches:
  refs/heads/master 2a63da2fe -> 18c73dad6


CB-5625 Show open Pull Requests on GitHub


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

Branch: refs/heads/master
Commit: df997210c134b3dd56aefba0a82a097956ad69e7
Parents: 2a63da2
Author: Bas Bosman <sb...@mindef.nl>
Authored: Sat Feb 1 15:20:50 2014 +0100
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Sat Feb 8 15:33:21 2014 -0500

----------------------------------------------------------------------
 coho | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 79 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/df997210/coho
----------------------------------------------------------------------
diff --git a/coho b/coho
index 2445fc6..87e98bd 100755
--- a/coho
+++ b/coho
@@ -353,6 +353,9 @@ var gitCommitCount = 0;
 var JIRA_API_URL = "https://issues.apache.org/jira/rest/api/latest/";
 var JIRA_PROJECT_KEY = "CB";
 
+var GITHUB_API_URL = "https://api.github.com/";
+var GITHUB_ORGANIZATION = "apache";
+
 function reportGitPushResult(repos, branches) {
     print('');
     if (gitCommitCount) {
@@ -1649,6 +1652,78 @@ function createReleaseBugCommand() {
     });
 }
 
+function listGitHubPullRequests(repo, branch) {
+    var url = GITHUB_API_URL + 'repos/' + GITHUB_ORGANIZATION + '/' + repo + '/pulls?base=' + branch;
+
+    request.get({ url: url, headers: { 'User-Agent': 'Cordova Coho' }}, function(err, res, pullRequests) {
+        if (err) {
+            fatal('Error getting pull requests from GitHub: ' + err);
+        } else if (!pullRequests) {
+            fatal('Error: GitHub returned no pull requests');
+        } 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();
+            fatal('Error: GitHub rate limit exceeded, wait till ' + expiration + ' before trying again.\n' +
+                'See http://developer.github.com/v3/#rate-limiting for details.');
+        }
+
+        pullRequests = JSON.parse(pullRequests);
+
+        pullRequests.sort(function(a,b) {return (a.updated_at > b.updated_at) ? -1 : ((b.updated_at > a.updated_at) ? 1 : 0);} );
+
+        if(pullRequests.length === 0) {
+            print('No open Pull Requests for repo "' + repo + '" and branch "' + branch + '"');
+        } else {
+            print('Found ' + pullRequests.length + ' Pull Requests for repo "' + repo + '" and branch "' + branch + '"');
+        }
+        console.log('\n');
+
+        pullRequests.forEach(function(pullRequest) {
+            console.log('-----------------------------------------------------------------------------------------------');
+            console.log('Pull Request number ' + pullRequest.number  + ' for ' + repo + ' on branch ' + branch + ' (Last modified:  ' + pullRequest.updated_at + ')');
+            console.log('-----------------------------------------------------------------------------------------------');
+            console.log('Title: ' + pullRequest.title);
+            console.log('Author: ' + pullRequest.user.login);
+            console.log('Url: ' + pullRequest.html_url);
+            if(pullRequest.body !== '') {
+                console.log('\n' + pullRequest.body);
+            }
+            console.log('\n');
+        });
+    });
+}
+
+function listPullRequestsCommand() {
+    var opt = registerHelpFlag(optimist);
+    opt = registerRepoFlag(opt);
+    opt = opt.options('b', {
+        alias: 'branch',
+        desc: 'The name of the branch to check. Can be specified multiple times to specify multiple branches.',
+        default: 'master'
+    });
+    opt.usage('Reports what GitHub pull requests are open for the given repositories.\n' +
+               '\n' +
+               'Example usage: $0 list-pulls -r auto -b master\n' +
+               'Example usage: $0 list-pulls -r plugins -b dev\n' +
+               '\n' +
+               'Please note that GitHub rate limiting applies. See http://developer.github.com/v3/#rate-limiting for details.\n');
+    var argv = opt.argv;
+
+    if (argv.h) {
+        optimist.showHelp();
+        process.exit(1);
+    }
+    
+    var branches = Array.isArray(argv.b) ? argv.b : [argv.b];
+    var repos = computeReposFromFlag(argv.r)
+
+    repos.forEach(function(repo) {
+        branches.forEach(function(branchName) {
+            listGitHubPullRequests(repo.repoName, branchName);
+        });
+    });
+}
+
 function main() {
     var commandList = [
         {
@@ -1676,6 +1751,10 @@ function main() {
             desc: 'Shows a list of valid values for the --repo flag.',
             entryPoint: listReposCommand
         }, {
+            name: 'list-pulls',
+            desc: 'Shows a list of GitHub pull requests for all specified repositories.',
+            entryPoint: listPullRequestsCommand
+        }, {
             name: 'prepare-release-branch',
             desc: 'Branches, updates JS, updates VERSION. Safe to run multiple times.',
             entryPoint: prepareReleaseBranchCommand


[2/2] git commit: CB-5625 list-pulls: Show pull requests for all branches. Output tweaks.

Posted by ag...@apache.org.
CB-5625 list-pulls: Show pull requests for all branches. Output tweaks.


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

Branch: refs/heads/master
Commit: 18c73dad615c067c8eeae8a345c77bd8df82af1d
Parents: df99721
Author: Andrew Grieve <ag...@chromium.org>
Authored: Sat Feb 8 20:24:16 2014 -0500
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Sat Feb 8 20:24:16 2014 -0500

----------------------------------------------------------------------
 coho | 44 ++++++++++++++++----------------------------
 1 file changed, 16 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-coho/blob/18c73dad/coho
----------------------------------------------------------------------
diff --git a/coho b/coho
index 87e98bd..6633968 100755
--- a/coho
+++ b/coho
@@ -1652,8 +1652,8 @@ function createReleaseBugCommand() {
     });
 }
 
-function listGitHubPullRequests(repo, branch) {
-    var url = GITHUB_API_URL + 'repos/' + GITHUB_ORGANIZATION + '/' + repo + '/pulls?base=' + branch;
+function listGitHubPullRequests(repo) {
+    var url = GITHUB_API_URL + 'repos/' + GITHUB_ORGANIZATION + '/' + repo + '/pulls';
 
     request.get({ url: url, headers: { 'User-Agent': 'Cordova Coho' }}, function(err, res, pullRequests) {
         if (err) {
@@ -1671,24 +1671,20 @@ function listGitHubPullRequests(repo, branch) {
 
         pullRequests.sort(function(a,b) {return (a.updated_at > b.updated_at) ? -1 : ((b.updated_at > a.updated_at) ? 1 : 0);} );
 
-        if(pullRequests.length === 0) {
-            print('No open Pull Requests for repo "' + repo + '" and branch "' + branch + '"');
-        } else {
-            print('Found ' + pullRequests.length + ' Pull Requests for repo "' + repo + '" and branch "' + branch + '"');
-        }
-        console.log('\n');
+        console.log('\x1B[31m========= ' + repo + ': ' + pullRequests.length + ' Pull Requests. =========\x1B[39m');
 
         pullRequests.forEach(function(pullRequest) {
-            console.log('-----------------------------------------------------------------------------------------------');
-            console.log('Pull Request number ' + pullRequest.number  + ' for ' + repo + ' on branch ' + branch + ' (Last modified:  ' + pullRequest.updated_at + ')');
-            console.log('-----------------------------------------------------------------------------------------------');
-            console.log('Title: ' + pullRequest.title);
-            console.log('Author: ' + pullRequest.user.login);
-            console.log('Url: ' + pullRequest.html_url);
-            if(pullRequest.body !== '') {
-                console.log('\n' + pullRequest.body);
+            var updatedDate = new Date(pullRequest.updated_at);
+            var daysAgo = Math.round((new Date() - updatedDate) / (60 * 60 * 24 * 1000));
+            console.log('\x1B[33m-----------------------------------------------------------------------------------------------\x1B[39m');
+            console.log(pullRequest.user.login + ': ' + pullRequest.title + ' (\x1B[31m' + daysAgo + ' days ago\x1B[39m)');
+            console.log('\x1B[33m-----------------------------------------------------------------------------------------------\x1B[39m');
+            console.log('* ' + pullRequest.html_url);
+            console.log('To merge: curl "' + pullRequest.patch_url + '" | git am');
+            if (pullRequest.body) {
+                console.log(pullRequest.body);
             }
-            console.log('\n');
+            console.log('');
         });
     });
 }
@@ -1696,15 +1692,10 @@ function listGitHubPullRequests(repo, branch) {
 function listPullRequestsCommand() {
     var opt = registerHelpFlag(optimist);
     opt = registerRepoFlag(opt);
-    opt = opt.options('b', {
-        alias: 'branch',
-        desc: 'The name of the branch to check. Can be specified multiple times to specify multiple branches.',
-        default: 'master'
-    });
     opt.usage('Reports what GitHub pull requests are open for the given repositories.\n' +
                '\n' +
-               'Example usage: $0 list-pulls -r auto -b master\n' +
-               'Example usage: $0 list-pulls -r plugins -b dev\n' +
+               'Example usage: $0 list-pulls | tee pulls.list | less -R\n' +
+               'Example usage: $0 list-pulls -r plugins\n' +
                '\n' +
                'Please note that GitHub rate limiting applies. See http://developer.github.com/v3/#rate-limiting for details.\n');
     var argv = opt.argv;
@@ -1714,13 +1705,10 @@ function listPullRequestsCommand() {
         process.exit(1);
     }
     
-    var branches = Array.isArray(argv.b) ? argv.b : [argv.b];
     var repos = computeReposFromFlag(argv.r)
 
     repos.forEach(function(repo) {
-        branches.forEach(function(branchName) {
-            listGitHubPullRequests(repo.repoName, branchName);
-        });
+        listGitHubPullRequests(repo.repoName);
     });
 }