Permalink
Browse files

Now allows for fetching more than 1000 comments on a single issue. Fi…

…xed a bug with calculating the issue ID for a comment.
  • Loading branch information...
1 parent 3c39729 commit 225ae2f3569af290c8b783d5089ea4678326353d @JamesMGreene committed Mar 17, 2013
View
@@ -31,6 +31,9 @@ In lieu of a formal styleguide, take care to maintain the existing coding style.
## Release History
+ - 1.5.9: Published to NPM on 2013-03-17.
+ - Fixed a bug with comments missing when there are more than 1000.
+ - Fixed a bug with calculating the issue ID for each comment.
- 1.5.8: Published to NPM on 2013-03-15.
- Fixed a bug with issues missing when honoring user privacy due the issue addressed in 1.5.7.
- 1.5.7: Published to NPM on 2013-03-15.
@@ -25,6 +25,7 @@ var loginP = Q.nfbind(client.login.bind(client));
var addIssueP = Q.nfbind(client.addIssue.bind(client));
var updateIssueP = Q.nfbind(client.updateIssue.bind(client));
+var projectName = 'jwalker';
var author;
getUsernameP().then(function(username) {
// Store this state for use later in the promise chain without having to work hard to continue passing it along when the chain pops
@@ -39,7 +40,7 @@ getUsernameP().then(function(username) {
'content': 'This issue was generated using the amazing "node-gcph-client" library. Try it TODAY with `npm install gcph-client`! <3',
'author': author
});
- return addIssueP('jwalker', newIssue);
+ return addIssueP(projectName, newIssue);
}).then(function(newlyCreatedIssue) {
var newComment = new gcph.Comment({
'author': author,
@@ -52,7 +53,7 @@ getUsernameP().then(function(username) {
'owner': author
}
});
- return updateIssueP('jwalker', newlyCreatedIssue, newComment);
+ return updateIssueP(projectName, newlyCreatedIssue, newComment);
}).then(function(newlyCreatedComment) {
console.log('All promises fulfilled!\n\nNewly created comment:\n' + JSON.stringify(newlyCreatedComment));
}).fail(function(err) {
@@ -17,6 +17,9 @@ var fs = require('fs');
var gcph = require('../lib/gcph');
var exUtil = require('./util/ex-util');
+// Config
+var projectName = 'phantomjs';
+
// Default the final output file if it was not provided as a commandline arg
var outputFilePath = process.argv[2];
@@ -33,7 +36,7 @@ if (!outputFilePath) {
) {
fs.mkdirSync(outputDir);
}
- outputFilePath = path.resolve(outputDir, 'gcAllIssuesAndCommentsHonoringPrivacy.json');
+ outputFilePath = path.resolve(outputDir, projectName + '-gcAllIssuesAndCommentsHonoringPrivacy.json');
console.warn('WARNING: Did not provide an output filename as an argument. Defaulting to:\n ' + outputFilePath + '\n');
}
@@ -52,19 +55,20 @@ var getIssuesP = Q.nfbind(client.getIssues.bind(client));
var getCommentsP = Q.nfbind(client.getComments.bind(client));
var writeFileP = Q.nfbind(fs.writeFile.bind(fs));
+console.warn('WARNING: You must be a project admin for "' + projectName + '" to make this example work correctly.');
getUsernameP().then(function(username) {
return getPasswordP().then(function(password) {
return loginP(username, password);
});
}).then(function() {
console.log('Authenticated BUT also honoring privacy!');
console.warn('WARNING: This will be literally twice as slow as usual!');
- console.log('Now getting all issues and comments for the "phantomjs" project....');
+ console.log('Now getting all issues and comments for the "' + projectName + '" project....');
- return getIssuesP('phantomjs');
+ return getIssuesP(projectName);
}).then(function(issues) {
return Q.all(issues.map(function(issue) {
- return getCommentsP('phantomjs', issue.id).then(function(comments) {
+ return getCommentsP(projectName, issue.id).then(function(comments) {
issue.comments = comments || [];
return issue;
});
@@ -16,6 +16,9 @@ var fs = require('fs');
// Internal modules
var gcph = require('../lib/gcph');
+// Config
+var projectName = 'phantomjs';
+
// Default the final output file if it was not provided as a commandline arg
var outputFilePath = process.argv[2];
@@ -32,7 +35,7 @@ if (!outputFilePath) {
) {
fs.mkdirSync(outputDir);
}
- outputFilePath = path.resolve(outputDir, 'gcAllIssuesAndCommentsUnauthenticated.json');
+ outputFilePath = path.resolve(outputDir, projectName + '-gcAllIssuesAndCommentsUnauthenticated.json');
console.warn('WARNING: Did not provide an output filename as an argument. Defaulting to:\n ' + outputFilePath + '\n');
}
@@ -49,11 +52,11 @@ var getCommentsP = Q.nfbind(client.getComments.bind(client));
var writeFileP = Q.nfbind(fs.writeFile.bind(fs));
console.log('NOT authenticated!');
-console.log('Now getting all issues and comments for the "phantomjs" project....');
+console.log('Now getting all issues and comments for the "' + projectName + '" project....');
-getIssuesP('phantomjs').then(function(issues) {
+getIssuesP(projectName).then(function(issues) {
return Q.all(issues.map(function(issue) {
- return getCommentsP('phantomjs', issue.id).then(function(comments) {
+ return getCommentsP(projectName, issue.id).then(function(comments) {
issue.comments = comments || [];
return issue;
});
@@ -17,6 +17,8 @@ var fs = require('fs');
var gcph = require('../lib/gcph');
var exUtil = require('./util/ex-util');
+// Config
+var projectName = 'phantomjs';
// Default the final output file if it was not provided as a commandline arg
var outputFilePath = process.argv[2];
@@ -33,7 +35,7 @@ if (!outputFilePath) {
) {
fs.mkdirSync(outputDir);
}
- outputFilePath = path.resolve(outputDir, 'gcAllIssuesAndComments.json');
+ outputFilePath = path.resolve(outputDir, projectName + '-gcAllIssuesAndComments.json');
console.warn('WARNING: Did not provide an output filename as an argument. Defaulting to:\n ' + outputFilePath + '\n');
}
@@ -55,12 +57,12 @@ getUsernameP().then(function(username) {
});
}).then(function() {
console.log('Authenticated!');
- console.log('Now getting all issues and comments for the "phantomjs" project....');
+ console.log('Now getting all issues and comments for the "' + projectName + '" project....');
- return getIssuesP('phantomjs');
+ return getIssuesP(projectName);
}).then(function(issues) {
return Q.all(issues.map(function(issue) {
- return getCommentsP('phantomjs', issue.id).then(function(comments) {
+ return getCommentsP(projectName, issue.id).then(function(comments) {
issue.comments = comments || [];
return issue;
});
@@ -0,0 +1,77 @@
+/*!
+ * gcph-client
+ * https://github.com/JamesMGreene/node-gcph-client
+ *
+ * Copyright (c) 2012 James M. Greene
+ * Licensed under the MIT license.
+ */
+
+'use strict';
+
+// External modules
+var Q = require('q');
+var path = require('path');
+var fs = require('fs');
+
+// Internal modules
+var gcph = require('../lib/gcph');
+
+// Config
+var projectName = 'android';
+
+
+// Default the final output file if it was not provided as a commandline arg
+var outputFilePath = process.argv[2];
+if (!outputFilePath) {
+ var outputDir = path.resolve(process.cwd(), 'out/');
+ if (
+ !(
+ fs.existsSync(outputDir) ||
+ (function() {
+ try { return fs.statSync(outputDir).isDirectory(); }
+ catch (e) { return false; }
+ })()
+ )
+ ) {
+ fs.mkdirSync(outputDir);
+ }
+ outputFilePath = path.resolve(outputDir, projectName + '-gcSingleIssueWithAllCommentsUnauthenticated.json');
+
+ console.warn('WARNING: Did not provide an output filename as an argument. Defaulting to:\n ' + outputFilePath + '\n');
+}
+
+// Initialize the client for the Google Code Project Hosting Issue Tracker API
+var clientOpts = {
+ disableAuthWarnings: true,
+ followNextIssueLinks: false
+};
+var client = new gcph.Client(clientOpts);
+
+// Pre-bind all the Node promises for Q
+var getIssuesP = Q.nfbind(client.getIssues.bind(client));
+var getCommentsP = Q.nfbind(client.getComments.bind(client));
+var writeFileP = Q.nfbind(fs.writeFile.bind(fs));
+
+// Config
+var query = new gcph.Query({
+ 'id': 9329,
+ 'max-results': 1
+});
+
+console.log('NOT authenticated!');
+console.log('Now getting issue #' + query.id + ' and its comments for the "' + projectName + '" project....');
+
+getIssuesP(projectName, query).then(function(issues) {
+ return Q.all(issues.map(function(issue) {
+ return getCommentsP(projectName, issue.id).then(function(comments) {
+ issue.comments = comments || [];
+ return issue;
+ });
+ }));
+}).then(function(issues) {
+ return writeFileP(outputFilePath, JSON.stringify(issues, null, ' '), 'utf8');
+}).then(function() {
+ console.log('All promises fulfilled!\n\nFinal JSON was written to:\n ' + outputFilePath + '\n');
+}).fail(function(err) {
+ console.error(err.stack || err);
+}).done();
Oops, something went wrong.

0 comments on commit 225ae2f

Please sign in to comment.