Skip to content
This repository was archived by the owner on Jan 2, 2024. It is now read-only.

Commit bba23f9

Browse files
committed
add PR creator and merger
1 parent 431bd9c commit bba23f9

File tree

3 files changed

+66
-23
lines changed

3 files changed

+66
-23
lines changed

scripts/average_issue_close.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ SELECT avg((
88
-- issue.closed_at as closed,
99
-- strftime('%s', 'now') as time,
1010
-- issue.name
11-
FROM issue;
11+
FROM issue
12+
WHERE NOT (issue.closed_at IS NULL)
13+
;

scripts/average_pr_close.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,9 @@ SELECT avg((
66
END
77
) - pull.created_at) AS "average"
88
FROM pull
9+
-- WHERE (
10+
-- CASE
11+
-- WHEN NOT (pull.closed_by IS NULL) AND
12+
-- NOT (pull.)
13+
-- )
914
;

scripts/parse_github.py

Lines changed: 58 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ class GHIssueEventKind(IntEnum):
160160
MENTIONED = 10
161161
HEAD_REF_RESTORED = 11
162162
RENAMED = 12
163+
HEAD_REF_FORCE_PUSHED = 13
163164

164165

165166
class GHIssueEvent(SQLBase):
@@ -252,7 +253,9 @@ class GHPull(SQLBase):
252253
title = Column(Text)
253254
closed_at = IntColumn(nullable=True)
254255
created_at = IntColumn()
256+
user = ForeignId("user.id")
255257
merged_at = IntColumn(nullable=True)
258+
merged_by = ForeignId("user.id", nullable=True)
256259
updated_at = IntColumn()
257260

258261
gh_id = IntColumn()
@@ -356,6 +359,9 @@ def event_name_to_kind(event: str) -> GHIssueEventKind:
356359
case "head_ref_restored":
357360
return GHIssueEventKind.HEAD_REF_RESTORED
358361

362+
case "head_ref_force_pushed":
363+
return GHIssueEventKind.HEAD_REF_FORCE_PUSHED
364+
359365
case "renamed":
360366
return GHIssueEventKind.RENAMED
361367

@@ -658,12 +664,20 @@ def get_issue(self, issue: gh.Issue.Issue) -> int:
658664

659665
return issue_id
660666

661-
def get_pull(self, pull: gh.PullRequest.PullRequest) -> int:
667+
def get_stored_pull_id(self, pull: gh.PullRequest.PullRequest) -> int:
662668
stored = self.get_pull_by_id(pull.id)
663669
if stored:
664-
# log.info("Getting pull ID from stored cache")
670+
log.info(f"Cached pull {pull.number}")
665671
return stored.id
666672

673+
else:
674+
return None
675+
676+
def get_pull(self, pull: gh.PullRequest.PullRequest) -> int:
677+
stored = self.get_stored_pull_id(pull)
678+
if stored:
679+
return stored
680+
667681
else:
668682
log.info(f"Pull {pull.number} [red]" + pull.title + "[/]")
669683
# log.debug({
@@ -677,8 +691,13 @@ def get_pull(self, pull: gh.PullRequest.PullRequest) -> int:
677691
title=pull.title or "",
678692
closed_at=to_stamp(pull.closed_at),
679693
created_at=to_stamp(pull.created_at),
694+
user = pull.user and self.get_user(pull.user),
695+
680696
merged_at=to_stamp(pull.merged_at),
697+
merged_by=pull.merged_by and self.get_user(pull.merged_by),
698+
681699
updated_at=to_stamp(pull.updated_at),
700+
682701
gh_id=pull.id,
683702
additions=pull.additions,
684703
deletions=pull.deletions,
@@ -745,25 +764,28 @@ def get_pull(self, pull: gh.PullRequest.PullRequest) -> int:
745764
comment_id, GHEntryKind.COMMENT, comment.body
746765
)
747766

748-
for comment in pull.get_review_comments():
749-
review = GHReviewComment(
750-
gh_id=comment.id,
751-
target=pull_id,
752-
user=self.get_user(comment.user),
753-
created_at=to_stamp(comment.created_at),
754-
diff_hunk=comment.diff_hunk,
755-
commit=self.get_commit(comment.commit_id),
756-
original_commit=self.get_commit(
757-
comment.original_commit_id
758-
),
759-
)
767+
if False:
768+
# HACK temporarily disabled because old database did not
769+
# have nullable constraint enabled.
770+
for comment in pull.get_review_comments():
771+
review = GHReviewComment(
772+
gh_id=comment.id,
773+
target=pull_id,
774+
user=self.get_user(comment.user),
775+
created_at=to_stamp(comment.created_at),
776+
diff_hunk=comment.diff_hunk,
777+
commit=self.get_commit(comment.commit_id),
778+
original_commit=self.get_commit(
779+
comment.original_commit_id
780+
),
781+
)
760782

761-
print(review)
762-
comment_id = self.add(review)
783+
print(review)
784+
comment_id = self.add(review)
763785

764-
self.fill_mentions(
765-
comment_id, GHEntryKind.REVIEW_COMMENT, comment.body
766-
)
786+
self.fill_mentions(
787+
comment_id, GHEntryKind.REVIEW_COMMENT, comment.body
788+
)
767789

768790
def get_label(self, label: gh.Label.Label) -> int:
769791
stored = self.get_label_by_name(label.name)
@@ -774,7 +796,9 @@ def get_label(self, label: gh.Label.Label) -> int:
774796
return self.add(
775797
GHLabel(
776798
text=label.name,
777-
description=label.description,
799+
description="FIXME", # HACK. Trying to get
800+
# description=label.description, causes the '400
801+
# returned object contains no URL' error
778802
color=label.color,
779803
)
780804
)
@@ -873,14 +897,26 @@ def fill_pulls(c: Connect):
873897
count = 1
874898
for pull in pulls:
875899
# HACK same hack reason as in `fill_issues`
876-
if pull.html_url.endswith(f"pull/{pull.number}") \
877-
and s.first_processing(pull):
900+
if pull.html_url.endswith(f"pull/{pull.number}"):
901+
stored = c.get_stored_pull_id(pull)
902+
if stored:
903+
continue
904+
878905
c.get_pull(pull)
879906

880907
count += 1
881908
if s.args.max_pulls_fetch < count:
909+
log.warning(
910+
f"Reached max number of pulls ({count}), withdrawing")
911+
882912
break
883913

914+
else:
915+
log.debug({
916+
"url": pull.html_url,
917+
"num": pull.number
918+
})
919+
884920

885921
def impl(args):
886922
if not args.token:

0 commit comments

Comments
 (0)