Skip to content

Commit

Permalink
milestones now has FK to creator, plus repo column - closes #29
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Apr 21, 2020
1 parent befb6fe commit e0e8d8c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
8 changes: 5 additions & 3 deletions github_to_sqlite/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class GitHubRepositoryEmpty(GitHubError):

def save_issues(db, issues):
if "milestones" not in db.table_names():
db["milestones"].create({"id": int, "title": str, "description": str}, pk="id")
db["milestones"].create({"id": int, "title": str}, pk="id")
for original in issues:
# Ignore all of the _url fields
issue = {
Expand All @@ -54,7 +54,7 @@ def save_issues(db, issues):
labels = issue.pop("labels")
# Extract milestone
if issue["milestone"]:
issue["milestone"] = save_milestone(db, issue["milestone"])
issue["milestone"] = save_milestone(db, issue["milestone"], issue["repo"])
# For the moment we ignore the assignees=[] array but we DO turn assignee
# singular into a foreign key reference
issue.pop("assignees", None)
Expand Down Expand Up @@ -94,9 +94,10 @@ def save_user(db, user):
return db["users"].upsert(to_save, pk="id", alter=True).last_pk


def save_milestone(db, milestone):
def save_milestone(db, milestone, repo):
milestone = dict(milestone)
milestone["creator"] = save_user(db, milestone["creator"])
milestone["repo"] = repo
milestone.pop("labels_url", None)
milestone.pop("url", None)
return (
Expand All @@ -107,6 +108,7 @@ def save_milestone(db, milestone):
foreign_keys=[("creator", "users", "id")],
alter=True,
replace=True,
columns={"creator": int,},
)
.last_pk
)
Expand Down
1 change: 1 addition & 0 deletions tests/test_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def test_milestones(db):
{
"html_url": "https://github.com/simonw/datasette/milestone/6",
"id": 2949431,
"repo": "simonw/datasette",
"node_id": "MDk6TWlsZXN0b25lMjk0OTQzMQ==",
"number": 6,
"title": "Custom templates edition",
Expand Down

0 comments on commit e0e8d8c

Please sign in to comment.