Skip to content

Commit cae005f

Browse files
committed
merged_by as foreign key to users, if available
1 parent 22a0164 commit cae005f

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

github_to_sqlite/utils.py

+5
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ def save_pull_requests(db, pull_requests, repo):
173173
# Extract user
174174
pull_request["user"] = save_user(db, pull_request["user"])
175175
labels = pull_request.pop("labels")
176+
# Extract merged_by, if it exists
177+
if pull_request.get("merged_by"):
178+
pull_request["merged_by"] = save_user(db, pull_request["merged_by"])
176179
# Head sha
177180
pull_request["head"] = pull_request["head"]["sha"]
178181
pull_request["base"] = pull_request["base"]["sha"]
@@ -196,6 +199,7 @@ def save_pull_requests(db, pull_requests, repo):
196199
pk="id",
197200
foreign_keys=[
198201
("user", "users", "id"),
202+
("merged_by", "users", "id"),
199203
("assignee", "users", "id"),
200204
("milestone", "milestones", "id"),
201205
("repo", "repos", "id"),
@@ -209,6 +213,7 @@ def save_pull_requests(db, pull_requests, repo):
209213
"repo": int,
210214
"title": str,
211215
"body": str,
216+
"merged_by": int,
212217
},
213218
)
214219
# m2m for labels

tests/test_pull_requests.py

+22-10
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,11 @@ def db(pull_requests):
2525

2626
def test_tables(db):
2727
assert {"pull_requests", "users", "repos", "milestones"} == set(db.table_names())
28-
assert {
29-
ForeignKey(
30-
table="pull_requests", column="repo", other_table="repos", other_column="id"
31-
),
28+
assert set(db["pull_requests"].foreign_keys) == {
3229
ForeignKey(
3330
table="pull_requests",
34-
column="milestone",
35-
other_table="milestones",
31+
column="merged_by",
32+
other_table="users",
3633
other_column="id",
3734
),
3835
ForeignKey(
@@ -41,10 +38,19 @@ def test_tables(db):
4138
other_table="users",
4239
other_column="id",
4340
),
41+
ForeignKey(
42+
table="pull_requests",
43+
column="milestone",
44+
other_table="milestones",
45+
other_column="id",
46+
),
47+
ForeignKey(
48+
table="pull_requests", column="repo", other_table="repos", other_column="id"
49+
),
4450
ForeignKey(
4551
table="pull_requests", column="user", other_table="users", other_column="id"
4652
),
47-
} == set(db["pull_requests"].foreign_keys)
53+
}
4854

4955

5056
def test_pull_requests(db):
@@ -74,7 +80,7 @@ def test_pull_requests(db):
7480
"mergeable": None,
7581
"rebaseable": None,
7682
"mergeable_state": "unknown",
77-
"merged_by": '{"login": "simonw", "id": 9599, "node_id": "MDQ6VXNlcjk1OTk=", "avatar_url": "https://avatars0.githubusercontent.com/u/9599?v=4", "gravatar_id": "", "url": "https://api.github.com/users/simonw", "html_url": "https://github.com/simonw", "followers_url": "https://api.github.com/users/simonw/followers", "following_url": "https://api.github.com/users/simonw/following{/other_user}", "gists_url": "https://api.github.com/users/simonw/gists{/gist_id}", "starred_url": "https://api.github.com/users/simonw/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/simonw/subscriptions", "organizations_url": "https://api.github.com/users/simonw/orgs", "repos_url": "https://api.github.com/users/simonw/repos", "events_url": "https://api.github.com/users/simonw/events{/privacy}", "received_events_url": "https://api.github.com/users/simonw/received_events", "type": "User", "site_admin": false}',
83+
"merged_by": 9599,
7884
"comments": 0,
7985
"review_comments": 0,
8086
"maintainer_can_modify": 0,
@@ -106,10 +112,16 @@ def test_users(db):
106112

107113

108114
def test_foreign_keys(db):
109-
assert [
115+
assert db["pull_requests"].foreign_keys == [
110116
ForeignKey(
111117
table="pull_requests", column="repo", other_table="repos", other_column="id"
112118
),
119+
ForeignKey(
120+
table="pull_requests",
121+
column="merged_by",
122+
other_table="users",
123+
other_column="id",
124+
),
113125
ForeignKey(
114126
table="pull_requests",
115127
column="milestone",
@@ -125,4 +137,4 @@ def test_foreign_keys(db):
125137
ForeignKey(
126138
table="pull_requests", column="user", other_table="users", other_column="id"
127139
),
128-
] == db["pull_requests"].foreign_keys
140+
]

0 commit comments

Comments
 (0)