-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflow.py
More file actions
35 lines (29 loc) · 932 Bytes
/
Copy pathflow.py
File metadata and controls
35 lines (29 loc) · 932 Bytes
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
from prefect import flow
from extract import extract_repository, extract_branches, extract_commits, extract_pulls
from etl_load import (
ensure_schema,
get_since_ts,
upsert_repository,
upsert_branches,
upsert_commits,
upsert_pulls,
)
@flow(log_prints=True)
def github_etl(owner: str, repo: str):
ensure_schema()
repo_meta = extract_repository(owner, repo)
repo_id = upsert_repository(repo_meta, owner, repo)
since_ts = get_since_ts(repo_id)
print(f"[WATERMARK] since = {since_ts}")
branches = extract_branches(owner, repo)
commits = extract_commits(owner, repo, since_ts)
pulls = extract_pulls(owner, repo, since_ts)
upsert_branches(repo_id, branches)
upsert_commits(repo_id, commits)
upsert_pulls(repo_id, pulls)
return {
"repo_id": repo_id,
"branches": len(branches),
"commits": len(commits),
"pulls": len(pulls),
}