This repository has been archived by the owner on Jul 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-all-issues-and-comments-unauthenticated.js
70 lines (59 loc) · 1.97 KB
/
get-all-issues-and-comments-unauthenticated.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*!
* 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 = 'phantomjs';
// 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 + '-gcAllIssuesAndCommentsUnauthenticated.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
};
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));
console.log('NOT authenticated!');
console.log('Now getting all issues and comments for the "' + projectName + '" project....');
getIssuesP(projectName).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();