repl.it
@turbio/

boop stats

Nodejs

No description

fork
loading
Files
  • index.js
  • all_issues
  • asdf
  • data
  • issue_evs
  • Packager files
  • package-lock.json
  • package.json
index.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
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
const Octokit = require('@octokit/rest');
const octokit = new Octokit({auth: process.env.TOKEN});
const fs = require('fs');

async function fetchall() {
	let page = 0;
	while(true) {
		const {data} = await octokit.issues.list({
			filter: 'all',
			state: 'closed',
			per_page: 100,
			page,
		});

		console.log(page, data.length)

		for (const i of data) {
			fs.appendFileSync('./all_issues', JSON.stringify(i) + '\n');
		}

		page++;

		if (data.length < 100) {
			break;
		}
	}
}

async function getissue(owner, repo, issue_number) {
	let data = [];

	console.log('grabbing', owner, repo, issue_number);

	let page = 0;
	while(true) {
		const {data: d} = await octokit.issues.listEventsForTimeline({
			owner,
			repo,
			issue_number,
			per_page: 100,
			page,
		});

		data = data.concat(d);

		page++;
		if (d.length < 100) {
			break;
		}
		console.log('paginated', page)
	}

	const evs = [];

	for (ev of data) {
		with(ev)
		switch(event) {
			case 'committed':
				evs.push({
					type: 'commit',
					time: author.date,
					by: '???',
				});
				break;

			case 'labeled':
				switch (label.name) {
					case 'preboop':
					case 'boop':
					case 'superboop':
						evs.push({
							type: label.name,
							time: created_at,
							by: actor.login,
						});
						break
					case 'hefty':
					case 'dependencies':
					case 'Low Priority Bug':
					case 'easy':
					case 'boards':
					case 'code':
					case 'bug':
						break;
					default:
						console.log(ev)
						throw new Error('unknown label: ' + label.name)
				}
				break;

			case 'unlabeled':
				switch (label.name) {
					case 'preboop':
					case 'boop':
					case 'superboop':
						evs.push({
							type: 'un' + label.name,
							time: created_at,
							by: actor.login,
						});
						break
					case 'hefty':
					case 'dependencies':
					case 'Low Priority Bug':
					case 'easy':
					case 'boards':
					case 'code':
					case 'bug':
						break;
					default:
						console.log(ev)
						throw new Error('unknown label: ' + label.name)
				}
				break;

			case 'reviewed':
				if (state === 'approved') {
					evs.push({
						type: 'approve',
						time: submitted_at,
						by: user.login,
					});
				} else if (state === 'changes_requested') {
					evs.push({
						type: 'refuse',
						time: submitted_at,
						by: user.login,
					});
				} else if (state === 'commented') {
					// pass
				} else if (state === 'dismissed') {
					// pass
				} else {
					console.log(ev)
					throw new Error('unknown review type: ' + state)
				}
				break;

			case 'merged':
				evs.push({
					type: 'merge',
					time: created_at,
					by: actor.login,
				})
				break;

			case 'closed':
				evs.push({
					type: 'close',
					time: created_at,
					by: actor.login
				})
				break;

			case 'reopened':
				evs.push({
					type: 'reopen',
					time: created_at,
					by: actor.login
				})
				break;

			// don't care
			case 'review_requested':
			case 'review_request_removed':
			case 'review_dismissed':
			case 'deployed':
			case 'referenced':
			case 'commented':
			case 'head_ref_deleted':
			case 'renamed':
			case 'head_ref_force_pushed':
			case 'cross-referenced':
			case 'mentioned':
			case 'subscribed':
			case 'base_ref_force_pushed':
			case 'base_ref_changed':
			case 'added_to_project':
			case 'moved_columns_in_project':
			case 'assigned':
			case 'unassigned':
			case 'commit-commented':
			case 'head_ref_restored':
			case 'unsubscribed':
			case 'comment_deleted':
			case 'ready_for_review':
				break;

			default:
				console.log(ev)
				throw new Error('idk what to do about ev: ' + event)
		}
	}

	console.log(evs);
	return evs;
}

issue_evs = {};

fs.readFileSync('./issue_evs', 'utf8')
	.split('\n')
	.slice(0, -1)
	.map(l => JSON.parse(l))
	.forEach(i => {
		issue_evs[i.n] = i;
	});

	async function fetchevs() {const issues = fs.readFileSync('./all_issues', 'utf8')
		.split('\n')
		.slice(0, -1)
		.map(l => JSON.parse(l));

	const step = 2;
	for (let i = 0; i < issues.length; i += step) {
		const p = [];
		for (let j = 0; j < step; j++) {
			const iss = issues[i+j];
			if(!iss.pull_request) continue;
			if (issue_evs[iss.number]) continue;

			p.push(
				getissue(
					iss.repository.owner.login,
					iss.repository.name,
					iss.number,
				)
				.then(ev => {
					const ent = {n: i.number, ev}
					fs.appendFileSync('./issue_evs', JSON.stringify(ent)+'\n')
				}),
			);
		}

		await Promise.all(p);
	}
}

const with_boop = Object.values(issue_evs)
	.filter(i => i.ev.find(e => e.type === 'boop'))

function ppms(ms) {
	if (ms < 1000)
		return ms + 'ms'
	else if (ms < 1000 * 60)
		return Math.floor(ms / 1000) + 's'
	else if (ms < 1000 * 60 * 60)
		return Math.floor(ms / 1000 / 60) + 'm'
	else if (ms < 1000 * 60 * 60 * 24)
		return Math.floor(ms / 1000 / 60 / 60) + 'h'
	else
		return Math.floor(ms / 1000 / 60 / 60 / 24) + 'd'
}

const days_acc = {};

const to_day = (da) => {
	const d = new Date(da);
	d.setHours(0);
	d.setMinutes(0);
	d.setSeconds(0);
	d.setMilliseconds(0);
	return d;
}

for (const i of with_boop) {
	let first = null;
	let last = null;
	let boop_at = null;
	let acc = [];
	for (const e of i.ev) {
		if (e.type === 'boop') {
			if (!first) first = new Date(e.time);
			boop_at = new Date(e.time);
		}

		if (e.type === 'unboop' && boop_at) {
			acc.push([boop_at, new Date(e.time)]);
			boop_at = null;
		}

		if (e.type === 'approve') {
			if (boop_at) {
				acc.push([boop_at, new Date(e.time)])
				boop_at = null;
			}
			last = new Date(e.time);
			break;
		}
	}

	if (!acc.length) continue; // TODO

	//const c = to_day(first);
	//do {
		//if (!days_acc[c.toString()]) days_acc[c.toString()] = 0
		//days_acc[c.toString()] += acc_ms;
		//console.log(first, last);
		//c.setDate(c.getDate() + 1);
	//} while(c < to_day(last))

	const total_ms = acc
		.map(([s, e]) => e - s)
		.reduce((s, c) => s + c);

	// This is a lil tricky. We'll AND the booped intervals
	// with an interval for when we care. This way we don't
	// count boop time outside of work hours as it's not
	// actually very meaningful.
	// so we might have:
	//  booped: ...#############   ####   #     ##########...
	// matters: ...      ########         ########        ...
	// should only actually count:
	//                   #######          #     ##
	// to count "days" we'll just go through and mask with a
	// pre built list of intervals. Makes it easy peasy
	// instead of trimming the boop intervals -_-

	console.log('pull:'+i.n, 'booped for', ppms(total_ms));
}

function mask2([a1, b1], [a2, b2]) {
	if (b1 - a1 > b2 - a2) {
		const tmpa1 = a1;
		const tmpb1 = b1;
		a1 = a2;
		b1 = b2;
		a2 = tmpa1;
		b2 = tmpb1;
	}

	// (a1,b1) <= (a2,b2)

	//  1111  or 1111
	// 222222    2222
	if (a2 <= a1 && b2 >= b1) {
		return [a2, b2];
	}

	// 11   or    11
	//   22     22
	if (b1 < a2 || b2 < a1) {
		return null;
	}

	// 1111
	//   2222
	if (a1 < a2) {
		return [a2, b1]
	}

	//   1111
	// 2222
	if (b1 > b2) {
		return [a1, b2];
	}

	throw new Error('hmmm')
}
Fetching token
?