Skip to content
Open
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
52 changes: 52 additions & 0 deletions models/marts/engineering/pull_requests.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

with

pull_requests as (
select * from {{ ref('stg_github__pull_requests') }}
),

repositories as (
select * from {{ ref('stg_github__repositories') }}
),

issues as (
select * from {{ ref('stg_github__issues') }}
),

issues_merged as (
select * from {{ ref('stg_github__issues_merged') }}
),

final as (
select
pull_requests.pull_request_id,
repositories.name as repo_name,
issues.number as pull_request_number,

-- TODO: find out how to label these PRs
cast(null as string) as type, -- (bug, eng, feature),

case
when pull_requests.is_draft then 'draft'
when issues_merged.merged_at is not null then 'merged'
when issues.closed_at is not null then 'closed_without_merge'
else 'open'
end as state,

issues.created_at as opened_at,
issues_merged.merged_at,
round(date_diff(issues_merged.merged_at, issues.created_at, hour) / 24.0, 2) as days_open_to_merge

from pull_requests

left join repositories
on pull_requests.head_repo_id = repositories.repo_id

left join issues
on pull_requests.issue_id = issues.issue_id

left join issues_merged
on pull_requests.issue_id = issues_merged.issue_id
)

select * from final
35 changes: 35 additions & 0 deletions models/staging/github/src_github.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: 2

sources:
- name: github
database: analytics-engineers-club
tables:
- name: pull_request
columns:
- name: id
description: "This is **not** the pull request number"
tests:
- unique
- not_null

- name: issue
description: "This table contains both issues AND pull requests"
columns:
- name: id
tests:
- unique
- not_null

- name: issue_merged
columns:
- name: issue_id
tests:
- unique
- not_null

- name: repository
columns:
- name: id
tests:
- unique
- not_null
29 changes: 29 additions & 0 deletions models/staging/github/stg_github__issues.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
with source as (

select * from {{ source('github', 'issue') }}

),

renamed as (

select
id as issue_id,
_fivetran_synced,
body,
closed_at,
created_at,
locked,
milestone_id,
number,
pull_request,
repository_id,
state,
title,
updated_at,
user_id

from source

)

select * from renamed
20 changes: 20 additions & 0 deletions models/staging/github/stg_github__issues_merged.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
with source as (
select * from {{ source('github', 'issue_merged') }}
),

renamed as (
select
issue_id,
actor_id as merge_user_id,

commit_sha,

-- timestamps
merged_at,

-- excluded columns
-- _fivetran_synced,
from source
)

select * from renamed
33 changes: 33 additions & 0 deletions models/staging/github/stg_github__pull_requests.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
with source as (

select * from {{ source('github', 'pull_request') }}

),

renamed as (

select
id as pull_request_id,
issue_id,

base_label,
base_ref,
base_repo_id,
base_sha,
base_user_id,
draft as is_draft,
head_label,
head_ref,
head_repo_id,
head_sha,
head_user_id,
merge_commit_sha,

-- excluded
-- _fivetran_synced,

from source

)

select * from renamed
32 changes: 32 additions & 0 deletions models/staging/github/stg_github__repositories.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
with source as (
select * from {{ source('github', 'repository') }}
),

renamed as (
select
id as repo_id,
owner_id as owner_user_id,

archived as is_archived,

default_branch,
description,
fork as is_fork,
full_name,
homepage,
language,
name,

private as is_private,
-- timestamps
created_at,


-- excluded
-- _fivetran_synced,

from source

)

select * from renamed
3 changes: 3 additions & 0 deletions packages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
packages:
- package: dbt-labs/codegen
version: 0.4.0