@@ -160,6 +160,7 @@ class GHIssueEventKind(IntEnum):
160
160
MENTIONED = 10
161
161
HEAD_REF_RESTORED = 11
162
162
RENAMED = 12
163
+ HEAD_REF_FORCE_PUSHED = 13
163
164
164
165
165
166
class GHIssueEvent (SQLBase ):
@@ -252,7 +253,9 @@ class GHPull(SQLBase):
252
253
title = Column (Text )
253
254
closed_at = IntColumn (nullable = True )
254
255
created_at = IntColumn ()
256
+ user = ForeignId ("user.id" )
255
257
merged_at = IntColumn (nullable = True )
258
+ merged_by = ForeignId ("user.id" , nullable = True )
256
259
updated_at = IntColumn ()
257
260
258
261
gh_id = IntColumn ()
@@ -356,6 +359,9 @@ def event_name_to_kind(event: str) -> GHIssueEventKind:
356
359
case "head_ref_restored" :
357
360
return GHIssueEventKind .HEAD_REF_RESTORED
358
361
362
+ case "head_ref_force_pushed" :
363
+ return GHIssueEventKind .HEAD_REF_FORCE_PUSHED
364
+
359
365
case "renamed" :
360
366
return GHIssueEventKind .RENAMED
361
367
@@ -658,12 +664,20 @@ def get_issue(self, issue: gh.Issue.Issue) -> int:
658
664
659
665
return issue_id
660
666
661
- def get_pull (self , pull : gh .PullRequest .PullRequest ) -> int :
667
+ def get_stored_pull_id (self , pull : gh .PullRequest .PullRequest ) -> int :
662
668
stored = self .get_pull_by_id (pull .id )
663
669
if stored :
664
- # log.info("Getting pull ID from stored cache ")
670
+ log .info (f"Cached pull { pull . number } " )
665
671
return stored .id
666
672
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
+
667
681
else :
668
682
log .info (f"Pull { pull .number } [red]" + pull .title + "[/]" )
669
683
# log.debug({
@@ -677,8 +691,13 @@ def get_pull(self, pull: gh.PullRequest.PullRequest) -> int:
677
691
title = pull .title or "" ,
678
692
closed_at = to_stamp (pull .closed_at ),
679
693
created_at = to_stamp (pull .created_at ),
694
+ user = pull .user and self .get_user (pull .user ),
695
+
680
696
merged_at = to_stamp (pull .merged_at ),
697
+ merged_by = pull .merged_by and self .get_user (pull .merged_by ),
698
+
681
699
updated_at = to_stamp (pull .updated_at ),
700
+
682
701
gh_id = pull .id ,
683
702
additions = pull .additions ,
684
703
deletions = pull .deletions ,
@@ -745,25 +764,28 @@ def get_pull(self, pull: gh.PullRequest.PullRequest) -> int:
745
764
comment_id , GHEntryKind .COMMENT , comment .body
746
765
)
747
766
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
+ )
760
782
761
- print (review )
762
- comment_id = self .add (review )
783
+ print (review )
784
+ comment_id = self .add (review )
763
785
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
+ )
767
789
768
790
def get_label (self , label : gh .Label .Label ) -> int :
769
791
stored = self .get_label_by_name (label .name )
@@ -774,7 +796,9 @@ def get_label(self, label: gh.Label.Label) -> int:
774
796
return self .add (
775
797
GHLabel (
776
798
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
778
802
color = label .color ,
779
803
)
780
804
)
@@ -873,14 +897,26 @@ def fill_pulls(c: Connect):
873
897
count = 1
874
898
for pull in pulls :
875
899
# 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
+
878
905
c .get_pull (pull )
879
906
880
907
count += 1
881
908
if s .args .max_pulls_fetch < count :
909
+ log .warning (
910
+ f"Reached max number of pulls ({ count } ), withdrawing" )
911
+
882
912
break
883
913
914
+ else :
915
+ log .debug ({
916
+ "url" : pull .html_url ,
917
+ "num" : pull .number
918
+ })
919
+
884
920
885
921
def impl (args ):
886
922
if not args .token :
0 commit comments