-
Notifications
You must be signed in to change notification settings - Fork 13
/
int_repo_metrics_by_project.sql
77 lines (72 loc) · 2.05 KB
/
int_repo_metrics_by_project.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
{{
config(
materialized='table'
)
}}
with repo_artifact as (
select
'GITHUB' as artifact_source,
is_fork,
fork_count,
star_count,
license_spdx_id,
language,
watcher_count,
CAST(id as STRING) as artifact_source_id,
LOWER(owner) as artifact_namespace,
LOWER(name) as artifact_name
from {{ ref('stg_ossd__current_repositories') }}
),
repo_snapshot as (
select
{{ oso_id("a.artifact_source", "a.artifact_source_id") }} as `artifact_id`,
artifact_namespace,
artifact_name,
license_spdx_id,
language,
is_fork,
fork_count,
star_count,
watcher_count
from repo_artifact as a
),
repo_stats as (
select
project_id,
to_artifact_id as artifact_id,
MIN(time) as first_commit_time,
MAX(time) as last_commit_time,
COUNT(distinct TIMESTAMP_TRUNC(time, day)) as days_with_commits_count,
COUNT(distinct from_artifact_id) as contributors_to_repo_count,
SUM(amount) as commit_count
from {{ ref('int_events_to_project') }}
where event_type = 'COMMIT_CODE'
group by
project_id,
to_artifact_id
)
select
int_artifacts_in_ossd_by_project.project_id,
int_artifacts_in_ossd_by_project.artifact_id,
int_artifacts_in_ossd_by_project.artifact_namespace,
int_artifacts_in_ossd_by_project.artifact_name,
int_artifacts_in_ossd_by_project.artifact_source,
repo_snapshot.is_fork,
repo_snapshot.fork_count,
repo_snapshot.star_count,
repo_snapshot.watcher_count,
repo_snapshot.language,
repo_snapshot.license_spdx_id,
repo_stats.first_commit_time,
repo_stats.last_commit_time,
repo_stats.days_with_commits_count,
repo_stats.contributors_to_repo_count,
repo_stats.commit_count
from {{ ref('int_artifacts_in_ossd_by_project') }}
left join repo_snapshot
on int_artifacts_in_ossd_by_project.artifact_id = repo_snapshot.artifact_id
left join repo_stats
on int_artifacts_in_ossd_by_project.artifact_id = repo_stats.artifact_id
where
int_artifacts_in_ossd_by_project.artifact_source = 'GITHUB'
and int_artifacts_in_ossd_by_project.artifact_type = 'REPOSITORY'