-
Notifications
You must be signed in to change notification settings - Fork 23
/
github__daily_metrics.sql
130 lines (121 loc) · 3.73 KB
/
github__daily_metrics.sql
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
with github_issues as (
select *
from {{ ref('github__issues') }}
),
pull_requests as (
select *
from {{ ref('github__pull_requests') }}
),
issues_opened_per_day as (
select
{{ dbt.date_trunc('day', 'created_at') }} as day,
repository as repository,
count(*) as number_issues_opened,
sum(days_issue_open) as sum_days_issue_open,
max(days_issue_open) as longest_days_issue_open
from github_issues
group by
1,2
),
issues_closed_per_day as (
select
{{ dbt.date_trunc('day', 'closed_at') }} as day,
repository as repository,
count(*) as number_issues_closed
from github_issues
where closed_at is not null
group by
1,2
),
prs_opened_per_day as (
select
{{ dbt.date_trunc('day', 'created_at') }} as day,
repository as repository,
count(*) as number_prs_opened,
sum(days_issue_open) as sum_days_pr_open,
max(days_issue_open) as longest_days_pr_open
from pull_requests
group by
1,2
),
prs_merged_per_day as (
select
{{ dbt.date_trunc('day', 'merged_at') }} as day,
repository as repository,
count(*) as number_prs_merged
from pull_requests
where merged_at is not null
group by
1,2
),
prs_closed_without_merge_per_day as (
select
{{ dbt.date_trunc('day', 'closed_at') }} as day,
repository as repository,
count(*) as number_prs_closed_without_merge
from pull_requests
where closed_at is not null
and merged_at is null
group by
1,2
),
issues_per_day as (
select
coalesce(issues_opened_per_day.day,
issues_closed_per_day.day
) as day,
coalesce(issues_opened_per_day.repository,
issues_closed_per_day.repository
) as repository,
number_issues_opened,
number_issues_closed,
sum_days_issue_open,
longest_days_issue_open
from issues_opened_per_day
full outer join issues_closed_per_day
on
issues_opened_per_day.day = issues_closed_per_day.day
and issues_opened_per_day.repository = issues_closed_per_day.repository
),
prs_per_day as (
select
coalesce(prs_opened_per_day.day,
prs_merged_per_day.day,
prs_closed_without_merge_per_day.day
) as day,
coalesce(prs_opened_per_day.repository,
prs_merged_per_day.repository,
prs_closed_without_merge_per_day.repository
) as repository,
number_prs_opened,
number_prs_merged,
number_prs_closed_without_merge,
sum_days_pr_open,
longest_days_pr_open
from prs_opened_per_day
full outer join prs_merged_per_day
on
prs_opened_per_day.day = prs_merged_per_day.day
and prs_opened_per_day.repository = prs_merged_per_day.repository
full outer join prs_closed_without_merge_per_day
on
coalesce(prs_opened_per_day.day, prs_merged_per_day.day) = prs_closed_without_merge_per_day.day
and coalesce(prs_opened_per_day.repository, prs_merged_per_day.repository) = prs_closed_without_merge_per_day.repository
)
select
coalesce(issues_per_day.day, prs_per_day.day) as day,
coalesce(issues_per_day.repository, prs_per_day.repository) as repository,
coalesce(number_issues_opened, 0) as number_issues_opened,
coalesce(number_issues_closed, 0) as number_issues_closed,
sum_days_issue_open,
longest_days_issue_open,
coalesce(number_prs_opened, 0) as number_prs_opened,
coalesce(number_prs_merged, 0) as number_prs_merged,
coalesce(number_prs_closed_without_merge, 0) as number_prs_closed_without_merge,
sum_days_pr_open,
longest_days_pr_open
from issues_per_day
full outer join prs_per_day
on
issues_per_day.day = prs_per_day.day
and issues_per_day.repository = prs_per_day.repository