@@ -289,7 +289,7 @@ def get_rich_item(self, item):
289
289
if item ['category' ] in rich_category_switch :
290
290
rich_item = rich_category_switch [item ['category' ]]()
291
291
else :
292
- logger .error ("[github ] rich item not defined for GitHub category {}" .format (
292
+ logger .error ("[gitcode ] rich item not defined for GitCode category {}" .format (
293
293
item ['category' ]))
294
294
295
295
self .add_repository_labels (rich_item )
@@ -307,15 +307,20 @@ def __get_rich_pull(self, item):
307
307
# The real data
308
308
pull_request = item ['data' ]
309
309
310
+ if pull_request ['closed_at' ] == '' :
311
+ pull_request ['closed_at' ] = None
312
+ if pull_request ['merged_at' ] == '' :
313
+ pull_request ['merged_at' ] = None
314
+
310
315
#close and merge in gitcode are two different status
311
316
if pull_request ['state' ] == 'merged' :
312
317
rich_pr ['time_to_close_days' ] = \
313
318
get_time_diff_days (pull_request ['created_at' ], pull_request ['merged_at' ])
314
319
else :
315
- rich_pr ['time_to_close_days' ] = \
320
+ rich_pr ['time_to_close_days' ] = \
316
321
get_time_diff_days (pull_request ['created_at' ], pull_request ['closed_at' ])
317
322
318
- #merged is not equal to closed in gitcode
323
+ # merged is not equal to closed in gitcode, pr state have open, merged, closed
319
324
if pull_request ['state' ] == 'open' :
320
325
rich_pr ['time_open_days' ] = \
321
326
get_time_diff_days (pull_request ['created_at' ], datetime_utcnow ().replace (tzinfo = None ))
@@ -436,11 +441,14 @@ def __get_rich_issue(self, item):
436
441
# The real data
437
442
issue = item ['data' ]
438
443
444
+ if issue ['finished_at' ] == '' :
445
+ issue ['finished_at' ] = None
446
+
439
447
rich_issue ['time_to_close_days' ] = \
440
448
get_time_diff_days (issue ['created_at' ], issue ['finished_at' ])
441
449
442
- #issue have four status: open,progressing, closed, rejected .
443
- if issue ['state' ] == 'open' or issue [ 'state' ] == 'progressing' :
450
+ #issue have four status: open, closed.
451
+ if issue ['state' ] == 'open' :
444
452
rich_issue ['time_open_days' ] = \
445
453
get_time_diff_days (issue ['created_at' ], datetime_utcnow ().replace (tzinfo = None ))
446
454
else :
@@ -468,7 +476,6 @@ def __get_rich_issue(self, item):
468
476
469
477
assignee = issue .get ('assignee_data' , None )
470
478
if assignee and assignee is not None :
471
- assignee = issue ['assignee_data' ]
472
479
rich_issue ['assignee_login' ] = assignee ['login' ]
473
480
rich_issue ['assignee_name' ] = assignee ['name' ]
474
481
rich_issue ["assignee_domain" ] = self .get_email_domain (assignee ['email' ]) if assignee .get ('email' , None ) else None
@@ -493,16 +500,13 @@ def __get_rich_issue(self, item):
493
500
rich_issue ['updated_at' ] = issue ['updated_at' ]
494
501
rich_issue ['closed_at' ] = issue ['finished_at' ]
495
502
rich_issue ['url' ] = issue ['html_url' ]
496
- rich_issue ['issue_type' ] = issue [ 'issue_type' ]
503
+ rich_issue ['issue_type' ] = None
497
504
labels = []
498
505
[labels .append (label ['name' ]) for label in issue ['labels' ] if 'labels' in issue ]
499
506
rich_issue ['labels' ] = labels
500
507
501
- rich_issue ['pull_request' ] = True
502
- rich_issue ['item_type' ] = 'pull request'
503
- if 'head' not in issue .keys () and 'pull_request' not in issue .keys ():
504
- rich_issue ['pull_request' ] = False
505
- rich_issue ['item_type' ] = 'issue'
508
+ rich_issue ['pull_request' ] = False
509
+ rich_issue ['item_type' ] = 'issue'
506
510
507
511
rich_issue ['gitcode_repo' ] = rich_issue ['repository' ].replace (GITCODE , '' )
508
512
rich_issue ['gitcode_repo' ] = re .sub ('.git$' , '' , rich_issue ['gitcode_repo' ])
@@ -573,7 +577,7 @@ def __get_rich_repo(self, item):
573
577
rich_repo ['subscribers_count' ] = repo ['watchers_count' ]
574
578
rich_repo ['stargazers_count' ] = repo ['stargazers_count' ]
575
579
rich_repo ['fetched_on' ] = repo ['fetched_on' ]
576
- rich_repo ['url' ] = repo ['html_url ' ]
580
+ rich_repo ['url' ] = repo ['web_url ' ]
577
581
rich_repo ['status' ] = repo ['status' ]
578
582
if repo ["status" ] in "关闭" :
579
583
rich_repo ['archived' ] = True
@@ -587,7 +591,6 @@ def __get_rich_repo(self, item):
587
591
rich_releases = []
588
592
for release in repo ['releases' ] :
589
593
rich_releases_dict = {}
590
- rich_releases_dict ['id' ] = release ['id' ]
591
594
rich_releases_dict ['tag_name' ] = release ['tag_name' ]
592
595
rich_releases_dict ['target_commitish' ] = release ['target_commitish' ]
593
596
rich_releases_dict ['prerelease' ] = release ['prerelease' ]
@@ -612,7 +615,49 @@ def __get_rich_repo(self, item):
612
615
613
616
return rich_repo
614
617
615
- def get_event_type (self , action_type ):
618
+ def get_event_type (self , action_type , content ):
619
+ if action_type == "label" and "add" in content :
620
+ return "LabeledEvent"
621
+ elif action_type == "label" and "delete" in content :
622
+ return "UnlabeledEvent"
623
+ elif action_type == "closed" :
624
+ return "ClosedEvent"
625
+ elif action_type == "opened" :
626
+ return "ReopenedEvent"
627
+ elif action_type == "assignee" and "assigned" in content :
628
+ return "AssignedEvent"
629
+ elif action_type == "assignee" and "unassigned" in content :
630
+ return "UnassignedEvent"
631
+
632
+
633
+
634
+ switch_event_type = {
635
+ "add_label" : "LabeledEvent" ,
636
+ "remove_label" : "UnlabeledEvent" ,
637
+ "closed_pr" : "ClosedEvent" ,
638
+ "reopened_pr" : "ReopenedEvent" ,
639
+ "set_assignee" : "AssignedEvent" ,
640
+ "setting_assignee" : "AssignedEvent" ,
641
+ "unset_assignee" : "UnassignedEvent" ,
642
+ "change_assignee" : "UnassignedEvent" ,
643
+ "set_milestone" : "MilestonedEvent" ,
644
+ "setting_milestone" : "MilestonedEvent" ,
645
+ "unset_milestone" : "DemilestonedEvent" ,
646
+ "change_milestone" : "DemilestonedEvent" ,
647
+ "update_title" : "RenamedTitleEvent" ,
648
+ "change_title" : "RenamedTitleEvent" ,
649
+ "merged_pr" : "MergedEvent" ,
650
+ "update_description" : "ChangeDescriptionEvent" ,
651
+ "change_description" : "ChangeDescriptionEvent" ,
652
+ "setting_priority" : "SettingPriorityEvent" ,
653
+ "change_priority" : "ChangePriorityEvent"
654
+ }
655
+ if action_type in switch_event_type :
656
+ return switch_event_type [action_type ]
657
+ else :
658
+ return '' .join (word .capitalize () for word in action_type .split ('_' )) + "Event"
659
+
660
+ def get_event_type (self , action_type , content ):
616
661
switch_event_type = {
617
662
"add_label" : "LabeledEvent" ,
618
663
"remove_label" : "UnlabeledEvent" ,
@@ -659,13 +704,13 @@ def __get_rich_event(self, item):
659
704
item ['data' ]['actor' ] = actor
660
705
661
706
rich_event ['id' ] = event ['id' ]
662
- rich_event ['icon' ] = event [ 'icon' ]
707
+ rich_event ['icon' ] = event . get ( 'icon' )
663
708
rich_event ['actor_username' ] = actor ['login' ]
664
709
rich_event ['user_login' ] = rich_event ['actor_username' ]
665
710
rich_event ['content' ] = event ['content' ]
666
711
rich_event ['created_at' ] = event ['created_at' ]
667
712
rich_event ['action_type' ] = event ['action_type' ]
668
- rich_event ['event_type' ] = self .get_event_type (event ['action_type' ])
713
+ rich_event ['event_type' ] = self .get_event_type (event ['action_type' ], ) #待定
669
714
rich_event ['repository' ] = item ["tag" ]
670
715
rich_event ['pull_request' ] = False if 'issue' in event else True
671
716
rich_event ['item_type' ] = 'issue' if 'issue' in event else 'pull request'
@@ -697,6 +742,25 @@ def __get_rich_event(self, item):
697
742
rich_event ['issue_url' ] = main_content ['html_url' ]
698
743
rich_event ['issue_labels' ] = [label ['name' ] for label in main_content ['labels' ]]
699
744
rich_event ["issue_url_id" ] = rich_event ['gitcode_repo' ] + "/issues/" + rich_event ['issue_id_in_repo' ]
745
+
746
+ user = event .get ('user_data' , None )
747
+ if user is not None and user :
748
+ rich_event ['user_name' ] = user ['name' ]
749
+ rich_event ['author_name' ] = user ['name' ]
750
+ rich_event ['user_email' ] = user .get ('email' , None )
751
+ rich_event ["user_domain" ] = self .get_email_domain (user ['email' ]) if user .get ('email' , None ) else None
752
+ rich_event ['user_org' ] = user .get ('company' , None )
753
+ rich_event ['user_location' ] = user .get ('location' , None )
754
+ rich_event ['user_geolocation' ] = None
755
+ else :
756
+ rich_event ['user_name' ] = None
757
+ rich_event ['user_email' ] = None
758
+ rich_event ["user_domain" ] = None
759
+ rich_event ['user_org' ] = None
760
+ rich_event ['user_location' ] = None
761
+ rich_event ['user_geolocation' ] = None
762
+ rich_event ['author_name' ] = None
763
+
700
764
701
765
if self .prjs_map :
702
766
rich_event .update (self .get_item_project (rich_event ))
@@ -720,21 +784,37 @@ def __get_rich_stargazer(self, item):
720
784
rich_stargazer [f ] = None
721
785
# The real data
722
786
stargazer = item ['data' ]
723
- rich_stargazer ["user_id" ] = stargazer ["id" ]
724
- rich_stargazer ["user_login" ] = stargazer ["login" ]
725
- rich_stargazer ["user_name" ] = stargazer ["name" ]
726
- rich_stargazer ["auhtor_name" ] = stargazer ["name" ]
727
- rich_stargazer ["user_html_url" ] = stargazer ["html_url" ]
728
- rich_stargazer ['user_email' ] = stargazer .get ('email' , None )
729
- rich_stargazer ['user_company' ] = stargazer .get ('company' , None )
730
- rich_stargazer ["user_remark" ] = stargazer ["remark" ]
731
- rich_stargazer ["user_type" ] = stargazer ["type" ]
732
- rich_stargazer ["star_at" ] = stargazer ["star_at" ]
733
- rich_stargazer ["created_at" ] = stargazer ["star_at" ]
787
+ user = stargazer .get ('user_data' , None )
788
+ if user is not None and user :
789
+ rich_stargazer ['user_id' ] = user ['id' ]
790
+ rich_stargazer ["user_login" ] = user ["login" ]
791
+ rich_stargazer ["user_name" ] = user ["name" ]
792
+ rich_stargazer ["auhtor_name" ] = user ["name" ]
793
+ rich_stargazer ["user_html_url" ] = user ["html_url" ]
794
+ rich_stargazer ['user_email' ] = user .get ('email' , None )
795
+ rich_stargazer ["user_domain" ] = self .get_email_domain (user ['email' ]) if user .get ('email' , None ) else None
796
+ rich_stargazer ['user_company' ] = user .get ('company' , None )
797
+ rich_stargazer ["user_remark" ] = user .get ("remark" , None )
798
+ rich_stargazer ["user_type" ] = user ["type" ]
799
+
800
+ else :
801
+ rich_stargazer ['user_id' ] = None
802
+ rich_stargazer ["user_login" ] = stargazer ['login' ]
803
+ rich_stargazer ["user_name" ] = stargazer ['name' ]
804
+ rich_stargazer ["auhtor_name" ] = None
805
+ rich_stargazer ["user_html_url" ] = None
806
+ rich_stargazer ['user_email' ] = None
807
+ rich_stargazer ["user_domain" ] = None
808
+ rich_stargazer ['user_company' ] = None
809
+ rich_stargazer ["user_remark" ] = None
810
+ rich_stargazer ["user_type" ] = None
811
+
812
+ rich_stargazer ["star_at" ] = stargazer ["starred_at" ]
813
+ rich_stargazer ["created_at" ] = stargazer ["starred_at" ]
734
814
735
815
if self .prjs_map :
736
816
rich_stargazer .update (self .get_item_project (rich_stargazer ))
737
- rich_stargazer .update (self .get_grimoire_fields (stargazer ['star_at ' ], "stargazer" ))
817
+ rich_stargazer .update (self .get_grimoire_fields (stargazer ['starred_at ' ], "stargazer" ))
738
818
739
819
return rich_stargazer
740
820
@@ -748,16 +828,31 @@ def __get_rich_fork(self, item):
748
828
rich_fork [f ] = None
749
829
# The real data
750
830
fork = item ['data' ]
751
- fork_owner = fork ['owner' ]
752
- rich_fork ["user_id" ] = fork_owner ["id" ]
753
- rich_fork ["user_login" ] = fork_owner ["login" ]
754
- rich_fork ["user_name" ] = fork_owner ["name" ]
755
- rich_fork ["auhtor_name" ] = fork_owner ["name" ]
756
- rich_fork ["user_html_url" ] = fork_owner ["html_url" ]
757
- rich_fork ['user_email' ] = fork_owner .get ('email' , None )
758
- rich_fork ['user_company' ] = fork_owner .get ('company' , None )
759
- rich_fork ["user_remark" ] = fork_owner ["remark" ]
760
- rich_fork ["user_type" ] = fork_owner ["type" ]
831
+ user = fork .get ('user_data' , None )
832
+ if user is not None and user :
833
+ rich_fork ['user_id' ] = user ['id' ]
834
+ rich_fork ["user_login" ] = user ["login" ]
835
+ rich_fork ["user_name" ] = user ["name" ]
836
+ rich_fork ["auhtor_name" ] = user ["name" ]
837
+ rich_fork ["user_html_url" ] = user ["html_url" ]
838
+ rich_fork ['user_email' ] = user .get ('email' , None )
839
+ rich_fork ["user_domain" ] = self .get_email_domain (user ['email' ]) if user .get ('email' , None ) else None
840
+ rich_fork ['user_company' ] = user .get ('company' , None )
841
+ rich_fork ["user_remark" ] = user .get ("remark" , None )
842
+ rich_fork ["user_type" ] = user ["type" ]
843
+
844
+ else :
845
+ rich_fork ['user_id' ] = None
846
+ rich_fork ["user_login" ] = fork ["owner" ]['login' ]
847
+ rich_fork ["user_name" ] = fork ["owner" ]['name' ]
848
+ rich_fork ["auhtor_name" ] = None
849
+ rich_fork ["user_html_url" ] = None
850
+ rich_fork ['user_email' ] = None
851
+ rich_fork ['user_domain' ] = None
852
+ rich_fork ['user_company' ] = None
853
+ rich_fork ["user_remark" ] = None
854
+ rich_fork ["user_type" ] = None
855
+
761
856
rich_fork ["fork_at" ] = fork ["created_at" ]
762
857
rich_fork ["created_at" ] = fork ["created_at" ]
763
858
@@ -777,15 +872,31 @@ def __get_rich_watch(self, item):
777
872
rich_watch [f ] = None
778
873
# The real data
779
874
watch = item ['data' ]
780
- rich_watch ["user_id" ] = watch ["id" ]
781
- rich_watch ["user_login" ] = watch ["login" ]
782
- rich_watch ["user_name" ] = watch ["name" ]
783
- rich_watch ["auhtor_name" ] = watch ["name" ]
784
- rich_watch ["user_html_url" ] = watch ["html_url" ]
785
- rich_watch ['user_email' ] = watch .get ('email' , None )
786
- rich_watch ['user_company' ] = watch .get ('company' , None )
787
- rich_watch ["user_remark" ] = watch ["remark" ]
788
- rich_watch ["user_type" ] = watch ["type" ]
875
+ user = watch .get ('user_data' , None )
876
+ if user is not None and user :
877
+ rich_watch ['user_id' ] = user ['id' ]
878
+ rich_watch ["user_login" ] = user ["login" ]
879
+ rich_watch ["user_name" ] = user ["name" ]
880
+ rich_watch ["auhtor_name" ] = user ["name" ]
881
+ rich_watch ["user_html_url" ] = user ["html_url" ]
882
+ rich_watch ['user_email' ] = user .get ('email' , None )
883
+ rich_watch ["user_domain" ] = self .get_email_domain (user ['email' ]) if user .get ('email' , None ) else None
884
+ rich_watch ['user_company' ] = user .get ('company' , None )
885
+ rich_watch ["user_remark" ] = user .get ("remark" , None )
886
+ rich_watch ["user_type" ] = user ["type" ]
887
+
888
+ else :
889
+ rich_watch ['user_id' ] = None
890
+ rich_watch ["user_login" ] = watch ['login' ]
891
+ rich_watch ["user_name" ] = watch ['name' ]
892
+ rich_watch ["auhtor_name" ] = None
893
+ rich_watch ["user_html_url" ] = None
894
+ rich_watch ['user_email' ] = None
895
+ rich_watch ['user_demain' ] = None
896
+ rich_watch ['user_company' ] = None
897
+ rich_watch ["user_remark" ] = None
898
+ rich_watch ["user_type" ] = None
899
+
789
900
rich_watch ["watch_at" ] = watch ["watch_at" ]
790
901
rich_watch ["created_at" ] = watch ["watch_at" ]
791
902
0 commit comments