Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions models/github.yml
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ models:
- name: day
description: The reporting day
tests:
- unique
- not_null
- name: number_issues_opened
description: The total number of issues created during this time period
Expand All @@ -207,6 +206,9 @@ models:
- name: number_prs_closed_without_merge
description: The total number of pull requests closed without a merge during this time period

- name: repository
description: The name of the repository

- name: sum_days_pr_open
description: The total number of days a pull request opened during this time period was open

Expand All @@ -221,7 +223,6 @@ models:
- name: week
description: The reporting week
tests:
- unique
- not_null
- name: number_issues_opened
description: The total number of issues created during this time period
Expand Down Expand Up @@ -249,6 +250,9 @@ models:

- name: longest_days_pr_open
description: The longest number of days a pull request opened during this time period was open

- name: repository
description: The name of the repository

- name: github__monthly_metrics
description: >
Expand All @@ -257,7 +261,6 @@ models:
- name: month
description: The reporting month
tests:
- unique
- not_null
- name: number_issues_opened
description: The total number of issues created during this time period
Expand Down Expand Up @@ -285,6 +288,9 @@ models:

- name: longest_days_pr_open
description: The longest number of days a pull request opened during this time period was open

- name: repository
description: The name of the repository

- name: github__quarterly_metrics
description: >
Expand All @@ -293,7 +299,6 @@ models:
- name: quarter
description: The reporting quarter
tests:
- unique
- not_null
- name: number_issues_opened
description: The total number of issues created during this time period
Expand Down Expand Up @@ -321,4 +326,7 @@ models:

- name: longest_days_pr_open
description: The longest number of days a pull request opened during this time period was open

- name: repository
description: The name of the repository

63 changes: 49 additions & 14 deletions models/github__daily_metrics.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,60 +13,81 @@ issues_opened_per_day as (
{{ dbt.date_trunc('day', 'created_at') }} as day,
count(*) as number_issues_opened,
sum(days_issue_open) as sum_days_issue_open,
max(days_issue_open) as longest_days_issue_open
max(days_issue_open) as longest_days_issue_open,
repository as repository
from github_issues
group by 1
group by
1,
repository
),

issues_closed_per_day as (
select
{{ dbt.date_trunc('day', 'closed_at') }} as day,
count(*) as number_issues_closed
count(*) as number_issues_closed,
repository as repository
from github_issues
where closed_at is not null
group by 1
group by
1,
repository
),

prs_opened_per_day as (
select
{{ dbt.date_trunc('day', 'created_at') }} as day,
count(*) as number_prs_opened,
sum(days_issue_open) as sum_days_pr_open,
max(days_issue_open) as longest_days_pr_open
max(days_issue_open) as longest_days_pr_open,
repository as repository
from pull_requests
group by 1
group by
1,
repository
),

prs_merged_per_day as (
select
{{ dbt.date_trunc('day', 'merged_at') }} as day,
count(*) as number_prs_merged
count(*) as number_prs_merged,
repository as repository
from pull_requests
where merged_at is not null
group by 1
group by
1,
repository
),

prs_closed_without_merge_per_day as (
select
{{ dbt.date_trunc('day', 'closed_at') }} as day,
count(*) as number_prs_closed_without_merge
count(*) as number_prs_closed_without_merge,
repository as repository
from pull_requests
where closed_at is not null
and merged_at is null
group by 1
group by
1,
repository
),

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
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 (
Expand All @@ -75,18 +96,29 @@ prs_per_day as (
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
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
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,
Expand All @@ -97,5 +129,8 @@ select
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
full outer join prs_per_day
on
issues_per_day.day = prs_per_day.day
AND issues_per_day.repository = prs_per_day.repository
order by day desc
3 changes: 2 additions & 1 deletion models/github__monthly_metrics.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ with daily_metrics as (

select
{{ dbt.date_trunc('month', 'day') }} as month,
repository as repository,
sum(number_issues_opened) as number_issues_opened,
sum(number_issues_closed) as number_issues_closed,
sum(sum_days_issue_open) / sum(number_issues_opened) as avg_days_issue_open,
Expand All @@ -15,5 +16,5 @@ select
sum(sum_days_pr_open) / sum(number_prs_opened) as avg_days_pr_open,
max(longest_days_pr_open) as longest_days_pr_open
from daily_metrics
group by 1
group by 1, repository
order by 1 desc
3 changes: 2 additions & 1 deletion models/github__quarterly_metrics.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ with daily_metrics as (

select
{{ dbt.date_trunc('quarter', 'day') }} as quarter,
repository as repository,
sum(number_issues_opened) as number_issues_opened,
sum(number_issues_closed) as number_issues_closed,
sum(sum_days_issue_open) / sum(number_issues_opened) as avg_days_issue_open,
Expand All @@ -16,5 +17,5 @@ select
max(longest_days_pr_open) as longest_days_pr_open

from daily_metrics
group by 1
group by 1, repository
order by 1 desc
5 changes: 3 additions & 2 deletions models/github__weekly_metrics.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ with daily_metrics as (
)

select
{{ dbt.date_trunc('week', 'day') }} as week,
{{ dbt.date_trunc('week', 'day') }} as week,
repository as repository,
sum(number_issues_opened) as number_issues_opened,
sum(number_issues_closed) as number_issues_closed,
sum(sum_days_issue_open) / sum(number_issues_opened) as avg_days_issue_open,
Expand All @@ -15,5 +16,5 @@ select
sum(sum_days_pr_open) / sum(number_prs_opened) as avg_days_pr_open,
max(longest_days_pr_open) as longest_days_pr_open
from daily_metrics
group by 1
group by 1, repository
order by 1 desc