Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
200 lines (177 loc) · 5.18 KB
/
Copy pathindex.js
File metadata and controls
200 lines (177 loc) · 5.18 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*
* index.js: Exports GitHub issues into spreadsheet format
*
* (C) 2015, EmpireJS.
*
*/
var fs = require('fs'),
path = require('path'),
util = require('util'),
async = require('async'),
exceljs = require('exceljs'),
GitHubApi = require('github');
var importer = module.exports = function (options, callback) {
// account username to access GitHub repo
options.commentor = 'hackygolucky';
// name of file to export to
options.file = path.join(__dirname, 'cascadia-cfp.xlsx');
options.github = new GitHubApi({
// required
version: "3.0.0",
// optional
timeout: 5000
});
options.github.authenticate({
type: 'basic',
username: options.commentor,
password: process.env.GITHUB_PASS
});
async.waterfall([
async.apply(importer.readIssues, options),
async.apply(importer.createSheet, options)
], function (err, res) {
if (err) { return callback(err); }
});
};
// ### function readIssues (options, callback)
// Reads all the existing issues on the repo so we
// don't create duplicates
//
importer.readIssues = function (options, callback) {
var github = options.github,
repo = options.repo.split('/');
console.log('Reading issues | %s', options.repo);
//
// Remark: This is super brittle and only works
// for 200 CFP submissions max.
//
async.parallel([
async.apply(github.issues.repoIssues, {
user: repo[0],
repo: repo[1],
per_page: 100,
page: 1
}),
async.apply(github.issues.repoIssues, {
user: repo[0],
repo: repo[1],
per_page: 100,
page: 2
}),
async.apply(github.issues.repoIssues, {
user: repo[0],
repo: repo[1],
per_page: 100,
page: 3
})
], function (err, pages) {
if (err) { return callback(err); }
var all = pages[0].concat(pages[1]).concat(pages[2])
all.forEach(function (issue) {
issue.source = {
user: repo[0],
repo: repo[1]
}
});
callback(null, all);
})
};
importer.createSheet = function (options, issues, callback) {
issues = issues.filter(function (issue) {
issue.lines = issue.body.split(/[\r]?\n/);
return issue.lines[0][0] === '#';
}).map(importer.parseIssue);
issues.forEach(function (issue) {
console.log('--------------------------------\n\n');
console.dir(issue.parsed);
// console.dir(issue.lines);
console.log('\n\n--------------------------------\n\n');
});
callback();
var workbook = new Excel.Workbook()
, sheet = workbook.addWorksheet("Talk Reviews")
, row;
worksheet.columns = [
{ header: "Title", key: "title", width: 40 },
{ header: "Name", key: "speaker", width: 30 },
{ header: "Location", key: "location", width: 30 },
{ header: "Email", key: "email", width: 40 },
{ header: "Twitter", key: "twitter", width: 20 },
{ header: "GitHub", key: "github", width: 20 },
{ header: "Url(s)", key: "urls", width: 30 },
{ header: "Summary", key: "summary", width: 60 },
{ header: "Speaker Bio", key: "bio", width: 30}
];
// for each issue in issues, insert the issue object properties into
// subsequent columns in row[i]
for(var i; i < issues.length; i++){
worksheet.addRow({
title: title,
speaker: speaker,
location: speaker.location,
email: speaker.email,
twitter: speaker.twitter,
github: speaker.github,
urls: speaker.urls,
summary: summary,
bio: speaker.bio
}
};
}
var speakerParser = /^\s*[\*-] ([\w\(\)]+)\s*:\s+(.*)$/,
bioParser = /^##\s?Speaker Bio/i;
importer.parseIssue = function (issue) {
var parsed = issue.parsed = { speaker: {} };
var lines = issue.lines.slice();
var maybeSummary = [];
//
// Parses a single speaker line from this header:
// * "Property : Value"
//
function parseSpeakerInfo(line) {
if (!line || !line.length) { return; }
var match;
if ((match = speakerParser.exec(line))) {
parsed.speaker[match[1].toLowerCase()] = match[2];
} else {
maybeSummary.push(line);
}
}
//
// 1. Parse the title, then parse out the speaker
// details
//
parsed.title = lines.shift().replace(/^# /, '');
while (lines.length && lines[0].substr(0, 2) !== '##') {
parseSpeakerInfo(lines.shift());
}
if (maybeSummary.length && process.env.DEBUG) {
console.log('Maybe summary: %s %s', parsed.title, maybeSummary)
}
//
// 2. Parse out the actual talk summary:
// - Folks really don't know how to write a summary
// - Or follow a template
// - So this is basically a huge hack.
// - Since this isn't a proper state machine.
//
var len = maybeSummary.length;
if (!len || maybeSummary[len - 1].length < 50) {
lines.shift();
parsed.summary = [];
while (lines.length && !bioParser.test(lines[0])) {
parsed.summary.push(lines.shift());
}
} else {
parsed.summary = maybeSummary;
}
//
// 3. Parse out the actual speaker bio
//
lines.shift();
parsed.speaker.bio = [];
while (lines.length && lines[0].substr(0, 2) !== '##') {
parsed.speaker.bio.push(lines.shift());
}
return issue;
};