@@ -347,18 +347,18 @@ func TestIntegration(t *testing.T) {
347
347
},
348
348
{
349
349
`
350
- SELECT
351
- repository_id,
352
- COUNT(commit_author_email) as contributor_count
353
- FROM (
354
- SELECT DISTINCT
355
- repository_id,
356
- commit_author_email
357
- FROM commits
358
- ) as q
359
- GROUP BY repository_id
360
- ORDER BY contributor_count DESC
361
- LIMIT 10
350
+ SELECT
351
+ repository_id,
352
+ COUNT(commit_author_email) as contributor_count
353
+ FROM (
354
+ SELECT DISTINCT
355
+ repository_id,
356
+ commit_author_email
357
+ FROM commits
358
+ ) as q
359
+ GROUP BY repository_id
360
+ ORDER BY contributor_count DESC
361
+ LIMIT 10
362
362
` ,
363
363
[]sql.Row {{"worktree" , int64 (2 )}},
364
364
},
@@ -395,6 +395,107 @@ func TestIntegration(t *testing.T) {
395
395
{"php/crappy.php" , time .Date (2015 , time .April , 5 , 21 , 30 , 47 , 0 , time .UTC )},
396
396
},
397
397
},
398
+ {
399
+ `
400
+ SELECT repository_id, commit_author_when,
401
+ CASE WHEN ARRAY_LENGTH(commit_parents) > 1 THEN 'Merge' ELSE 'Commit' END AS commit_type
402
+ FROM commits
403
+ ORDER BY 2
404
+ ` ,
405
+ []sql.Row {
406
+ {"worktree" , time .Date (2015 , time .March , 31 , 11 , 42 , 21 , 0 , time .UTC ), "Commit" },
407
+ {"worktree" , time .Date (2015 , time .March , 31 , 11 , 44 , 52 , 0 , time .UTC ), "Commit" },
408
+ {"worktree" , time .Date (2015 , time .March , 31 , 11 , 46 , 24 , 0 , time .UTC ), "Commit" },
409
+ {"worktree" , time .Date (2015 , time .March , 31 , 11 , 47 , 14 , 0 , time .UTC ), "Merge" },
410
+ {"worktree" , time .Date (2015 , time .March , 31 , 11 , 48 , 14 , 0 , time .UTC ), "Merge" },
411
+ {"worktree" , time .Date (2015 , time .March , 31 , 11 , 51 , 51 , 0 , time .UTC ), "Commit" },
412
+ {"worktree" , time .Date (2015 , time .March , 31 , 11 , 56 , 18 , 0 , time .UTC ), "Commit" },
413
+ {"worktree" , time .Date (2015 , time .March , 31 , 12 , 00 , 8 , 0 , time .UTC ), "Commit" },
414
+ {"worktree" , time .Date (2015 , time .April , 5 , 21 , 30 , 47 , 0 , time .UTC ), "Commit" },
415
+ },
416
+ },
417
+ {
418
+ `
419
+ SELECT repo,
420
+ CASE
421
+ WHEN day_index = 2 THEN '1 - Monday'
422
+ WHEN day_index = 3 THEN '2 - Tuesday'
423
+ WHEN day_index = 4 THEN '3 - Wednesday'
424
+ WHEN day_index = 5 THEN '4 - Thursday'
425
+ WHEN day_index = 6 THEN '5 - Friday'
426
+ WHEN day_index = 7 THEN '6 - Saturday'
427
+ ELSE '7 - Sunday'
428
+ END AS day,
429
+ CASE
430
+ WHEN n_parents > 1 THEN 'Merge commit'
431
+ ELSE 'Non-merge commit'
432
+ END AS commit_type
433
+ FROM (
434
+ SELECT
435
+ repository_id AS repo,
436
+ committer_name AS developer,
437
+ DAYOFWEEK(committer_when) AS day_index,
438
+ ARRAY_LENGTH(commit_parents) AS n_parents
439
+ FROM commits
440
+ ) t
441
+ ` ,
442
+ []sql.Row {
443
+ {"worktree" , "7 - Sunday" , "Non-merge commit" },
444
+ {"worktree" , "2 - Tuesday" , "Non-merge commit" },
445
+ {"worktree" , "2 - Tuesday" , "Non-merge commit" },
446
+ {"worktree" , "2 - Tuesday" , "Merge commit" },
447
+ {"worktree" , "2 - Tuesday" , "Non-merge commit" },
448
+ {"worktree" , "2 - Tuesday" , "Merge commit" },
449
+ {"worktree" , "2 - Tuesday" , "Non-merge commit" },
450
+ {"worktree" , "2 - Tuesday" , "Non-merge commit" },
451
+ {"worktree" , "2 - Tuesday" , "Non-merge commit" },
452
+ },
453
+ },
454
+ {
455
+ `
456
+ SELECT added, deleted, commit_author_when, commit_hash, repository_id,
457
+ CASE WHEN deleted < (added+deleted)*0.1 THEN 'Added' WHEN added < (added+deleted)*0.1 THEN 'Deleted' ELSE 'Changed' END AS commit_type
458
+ FROM (
459
+ SELECT
460
+ JSON_EXTRACT(stats, "$.Total.Additions") as added,
461
+ JSON_EXTRACT(stats, "$.Total.Deletions") as deleted,
462
+ commit_author_when,
463
+ commit_hash,
464
+ repository_id
465
+ FROM (
466
+ SELECT
467
+ repository_id,
468
+ commit_author_when,
469
+ commit_hash,
470
+ commit_stats(repository_id, commit_hash) as stats
471
+ FROM refs
472
+ natural join ref_commits
473
+ natural join commits
474
+ ORDER BY commit_author_when
475
+ ) q
476
+ ) q2` ,
477
+ []sql.Row {
478
+ {float64 (1 ), float64 (0 ), time .Date (2015 , time .March , 31 , 12 , 00 , 8 , 0 , time .UTC ), "e8d3ffab552895c19b9fcf7aa264d277cde33881" , "worktree" , "Changed" },
479
+ {float64 (0 ), float64 (0 ), time .Date (2015 , time .April , 5 , 21 , 30 , 47 , 0 , time .UTC ), "6ecf0ef2c2dffb796033e5a02219af86ec6584e5" , "worktree" , "Changed" },
480
+ {float64 (0 ), float64 (0 ), time .Date (2015 , time .April , 5 , 21 , 30 , 47 , 0 , time .UTC ), "6ecf0ef2c2dffb796033e5a02219af86ec6584e5" , "worktree" , "Changed" },
481
+ {float64 (0 ), float64 (0 ), time .Date (2015 , time .April , 5 , 21 , 30 , 47 , 0 , time .UTC ), "6ecf0ef2c2dffb796033e5a02219af86ec6584e5" , "worktree" , "Changed" },
482
+ },
483
+ },
484
+ {
485
+ `
486
+ SELECT
487
+ JSON_UNQUOTE(JSON_EXTRACT(SPLIT(committer_email, '@'), '$[1]')) as domain,
488
+ COUNT(*) as n
489
+ FROM commits
490
+ WHERE committer_email LIKE '%%@%%' and committer_email NOT LIKE '%%@github.com'
491
+ GROUP BY domain
492
+ ORDER BY n DESC
493
+ ` ,
494
+ []sql.Row {
495
+ {"gmail.com" , int64 (8 )},
496
+ {"lordran.local" , int64 (1 )},
497
+ },
498
+ },
398
499
}
399
500
400
501
var pid uint64
0 commit comments