diff --git a/warehouse/dbt/models/intermediate/events/int_events.sql b/warehouse/dbt/models/intermediate/events/int_events.sql index ae0fe84d5..66e5ae25b 100644 --- a/warehouse/dbt/models/intermediate/events/int_events.sql +++ b/warehouse/dbt/models/intermediate/events/int_events.sql @@ -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`, @@ -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 ) ) diff --git a/warehouse/dbt/models/staging/github/stg_github__comments.sql b/warehouse/dbt/models/staging/github/stg_github__comments.sql new file mode 100644 index 000000000..68331097d --- /dev/null +++ b/warehouse/dbt/models/staging/github/stg_github__comments.sql @@ -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 diff --git a/warehouse/dbt/models/staging/github/stg_github__issues.sql b/warehouse/dbt/models/staging/github/stg_github__issues.sql index 4a716abb4..1d49f506b 100644 --- a/warehouse/dbt/models/staging/github/stg_github__issues.sql +++ b/warehouse/dbt/models/staging/github/stg_github__issues.sql @@ -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 diff --git a/warehouse/dbt/models/staging/github/stg_github__pull_requests.sql b/warehouse/dbt/models/staging/github/stg_github__pull_requests.sql index 21d09bcc2..ae5c2e6e8 100644 --- a/warehouse/dbt/models/staging/github/stg_github__pull_requests.sql +++ b/warehouse/dbt/models/staging/github/stg_github__pull_requests.sql @@ -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 diff --git a/warehouse/dbt/models/staging/github/stg_github__schema.yml b/warehouse/dbt/models/staging/github/stg_github__schema.yml index d7b6c6262..b7bc10f01 100644 --- a/warehouse/dbt/models/staging/github/stg_github__schema.yml +++ b/warehouse/dbt/models/staging/github/stg_github__schema.yml @@ -240,4 +240,24 @@ models: - *actor_id - *actor_login - name: type - description: "release publishedevent type" \ No newline at end of file + 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"