Skip to content

Commit

Permalink
feat(dbt): add comment_events for issues and PRs (#2147)
Browse files Browse the repository at this point in the history
* feat(dbt): add release_published github event type

* feat(dbt): add comment_events for issues and PRs

* fix(dbt): missing parenth
  • Loading branch information
ccerv1 authored Sep 16, 2024
1 parent 903f168 commit b741446
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 3 deletions.
22 changes: 22 additions & 0 deletions warehouse/dbt/models/intermediate/events/int_events.sql
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,26 @@ github_releases as (
from {{ ref('stg_github__releases') }}
),

github_comments as (
select -- noqa: ST06
created_at as `time`,
type as event_type,
CAST(id as STRING) as event_source_id,
"GITHUB" as event_source,
SPLIT(REPLACE(repository_name, "@", ""), "/")[SAFE_OFFSET(1)]
as to_name,
SPLIT(REPLACE(repository_name, "@", ""), "/")[SAFE_OFFSET(0)]
as to_namespace,
"REPOSITORY" as to_type,
CAST(repository_id as STRING) as to_artifact_source_id,
actor_login as from_name,
actor_login as from_namespace,
"GIT_USER" as from_type,
CAST(actor_id as STRING) as from_artifact_source_id,
CAST(1 as FLOAT64) as amount
from {{ ref('stg_github__comments') }}
),

github_issues as (
select -- noqa: ST06
created_at as `time`,
Expand Down Expand Up @@ -222,6 +242,8 @@ all_events as (
select * from github_releases
union all
select * from github_stars_and_forks
union all
select * from github_comments
)
)

Expand Down
31 changes: 31 additions & 0 deletions warehouse/dbt/models/staging/github/stg_github__comments.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
with pull_request_comment_events as (
select
ghe.id as id,
ghe.created_at as created_at,
ghe.repo.id as repository_id,
ghe.repo.name as repository_name,
ghe.actor.id as actor_id,
ghe.actor.login as actor_login,
'PULL_REQUEST_REVIEW_COMMENT' as `type`,
JSON_VALUE(ghe.payload, '$.pull_request.number') as `number`
from {{ ref('stg_github__events') }} as ghe
where ghe.type = 'PullRequestReviewCommentEvent'
),

issue_comment_events as (
select
ghe.id as id,
ghe.created_at as created_at,
ghe.repo.id as repository_id,
ghe.repo.name as repository_name,
ghe.actor.id as actor_id,
ghe.actor.login as actor_login,
'ISSUE_COMMENT' as `type`,
JSON_VALUE(ghe.payload, '$.issue.number') as `number`
from {{ ref('stg_github__events') }} as ghe
where ghe.type = 'IssueCommentEvent'
)

select * from pull_request_comment_events
union all
select * from issue_comment_events
3 changes: 2 additions & 1 deletion warehouse/dbt/models/staging/github/stg_github__issues.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ select
ie.repo.name as repository_name,
ie.actor.id as actor_id,
ie.actor.login as actor_login,
CONCAT("ISSUE_", UPPER(JSON_VALUE(ie.payload, "$.action"))) as `type`
CONCAT("ISSUE_", UPPER(JSON_VALUE(ie.payload, "$.action"))) as `type`,
JSON_VALUE(ie.payload, "$.issue.number") as `number`
from issue_events as ie
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ select
pre.actor.id as actor_id,
pre.actor.login as actor_login,
CONCAT("PULL_REQUEST_", UPPER(JSON_VALUE(pre.payload, "$.action")))
as `type`
as `type`,
JSON_VALUE(ie.payload, "$.number") as `number`
from pull_request_events as pre
22 changes: 21 additions & 1 deletion warehouse/dbt/models/staging/github/stg_github__schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,24 @@ models:
- *actor_id
- *actor_login
- name: type
description: "release publishedevent type"
description: "release published event type"


- name: stg_github__comments
meta:
#...
contributors: oso-team
config:
tags: ['staging', 'github', 'events', 'comments']
description: "GitHub comments"
columns:
- *id
- *created_at
- *repository_id
- *repository_name
- *actor_id
- *actor_login
- name: type
description: "issue or pull request comment type"
- name: number
description: "payload number"

0 comments on commit b741446

Please sign in to comment.