forked from natarajan-chidambaram/RABBIT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGenerateActivities.py
1526 lines (1255 loc) · 74.4 KB
/
GenerateActivities.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import pandas as pd
import numpy as np
'''
fields that will be present under each activity of the contributor and constants
'''
general = ['date','activity','contributor','repository']
event_general = ['event_id','event_type','login','repository','created_at']
UPPER_TIME_THRESHOLD = '0 days 00:00:02'
LOWER_TIME_THRESHOLD = '-1 days +23:59:58'
'''
Identifying activities from events
'''
def CreatingRepository(df_events, list_event_id_covered, df_all_activities):
'''
args: df_events (DataFrame) - events
list_event_id_covered (list) - a list of event id's that are covered in previous iterations
df_all_activities (DataFrame) - DataFrame of all the previously identified activities for a contributor
returns: df_all_activities (DataFrame) - Updated DataFrame of all activities that are identified for the contributor
list_event_id_covered - Updated list of event id's that are covered in previous iterations
Creating repository: Filter data based on CreateEvent with ref_type as repository
'''
create_repository = (
df_events
[event_general+['ref_type']]
.assign(activity='Creating repository')
.rename(columns={'login':'contributor',
'created_at':'date'})
.assign(date=lambda d: d.date.dt.tz_localize(tz='UTC').map(lambda x: x.isoformat()))
.drop_duplicates()
.sort_values('date')
)
list_event_id_covered.extend(create_repository['event_id'].to_list())
create_repository=create_repository.sort_values('date')
df_all_activities = pd.concat([df_all_activities,create_repository.drop_duplicates()[general]])
return df_all_activities, list_event_id_covered
def merge_misc_related(df_all, df):
'''
args: df_all - DataFrame of all activities
df - DataFrame of issue related activities
return: df_all - DataFrame with all the activities
method: For miscellaneous activities, get the dataframe that has all the activities,
append the new activities with required fields and return dataframe with all activities.
'''
df_all = pd.concat([df_all, df.drop_duplicates()[general]])
return(df_all)
def CreateBranch(df_events, list_event_id_covered, df_all_activities):
'''
args: df_events (DataFrame) - events
list_event_id_covered (list) - a list of event id's that are covered in previous iterations
df_all_activities (DataFrame) - DataFrame of all the previously identified activities for a contributor
returns: df_all_activities (DataFrame) - Updated DataFrame of all activities that are identified for the contributor
list_event_id_covered - Updated list of event id's that are covered in previous iterations
Creating branch: Filter data based on CreateEvent and ref_type as branch
'''
create_branch = (
df_events
[event_general]
.assign(activity = 'Creating branch')
.rename(columns={'login':'contributor',
'created_at':'date'})
.assign(date=lambda d: d.date.dt.tz_localize(tz='UTC').map(lambda x: x.isoformat()))
.assign(type="branch")
.drop_duplicates()
.sort_values('date')
)
list_event_id_covered.extend(create_branch['event_id'].to_list())
df_all_activities = merge_misc_related(df_all_activities, create_branch)
return df_all_activities, list_event_id_covered
def PublishingRelease(df_events, list_event_id_covered, df_all_activities):
'''
args: df_events (DataFrame) - events
list_event_id_covered (list) - a list of event id's that are covered in previous iterations
df_all_activities (DataFrame) - DataFrame of all the previously identified activities for a contributor
returns: df_all_activities (DataFrame) - Updated DataFrame of all activities that are identified for the contributor
list_event_id_covered - Updated list of event id's that are covered in previous iterations
Publishing a release:
Some Releases have a new tag that is created at the moment of creating the release,
whereas the other releases make use of an existing tag. Publishing release is made up of
1. Identifying ReleaseEvent and tag CreateEvent that occurs together
(i) identify the tag CreateEvent that happened within 2 seconds of ReleaseEvent
(ii) identify the ReleaseEvent that happened within 2 seconds of tag CreateEvent
2. Identifying ReleaseEvent that does not have a corresponding tag CreateEvent
'''
if(df_events.columns.isin(['ref']).any()):
df_rel_cr = (
df_events
.drop_duplicates()
[event_general+['tag_name','ref','release_node_id']]
.sort_values(['login','repository','created_at'])
.assign(next_event_id=lambda d: d.event_id.shift(-1))
.assign(next_event=lambda d: d.event_type.shift(-1))
.assign(next_login=lambda d: d.login.shift(-1))
.assign(next_repository=lambda d: d.repository.shift(-1))
.assign(next_ref=lambda d: d.ref.shift(-1))
.assign(next_event_created_at=lambda d: d.created_at.shift(-1))
.assign(cr_event_type=lambda d:
np.where(((d.event_type == "ReleaseEvent") & (d.next_event == "CreateEvent") &
(d.login == d.next_login) & (d.repository == d.next_repository) &
(d.tag_name == d.next_ref)),
d.next_event, np.nan))
.query('event_type == "ReleaseEvent" and cr_event_type == "CreateEvent"')
)
if(df_rel_cr.shape[0]>0):
df_rel_cr = (
df_rel_cr
.rename(columns={'next_event_created_at':'cr_created_at',
'next_ref':'cr_ref',
'next_event_id':'cr_event_id',
'next_repository':'cr_repository',
'next_login':'cr_login'})
.assign(time_diff=lambda d: d.created_at - d.cr_created_at)
[event_general+['tag_name', 'release_node_id',
'cr_event_id','cr_event_type','cr_login','cr_repository','cr_created_at','cr_ref','time_diff']]
)
df_cr_rel = (
df_events
.drop_duplicates()
[event_general+['tag_name','ref','release_node_id']]
.sort_values(['login','repository','created_at'])
.assign(prev_event_id=lambda d: d.event_id.shift(1))
.assign(prev_event=lambda d: d.event_type.shift(1))
.assign(prev_login=lambda d: d.login.shift(1))
.assign(prev_repository=lambda d: d.repository.shift(1))
.assign(prev_ref=lambda d: d.ref.shift(1))
.assign(prev_event_created_at=lambda d: d.created_at.shift(1))
.assign(cr_event_type=lambda d:
np.where(((d.event_type == "ReleaseEvent") & (d.prev_event == "CreateEvent") &
(d.login == d.prev_login) & (d.repository == d.prev_repository) &
(d.tag_name == d.prev_ref)),
d.prev_event, np.nan))
.query('event_type == "ReleaseEvent" and cr_event_type == "CreateEvent"')
)
if(df_cr_rel.shape[0]>0):
df_cr_rel = (
df_cr_rel
.rename(columns={'prev_event_created_at':'cr_created_at',
'prev_ref':'cr_ref',
'prev_event_id':'cr_event_id',
'prev_repository':'cr_repository',
'prev_login':'cr_login'})
.assign(time_diff=lambda d: d.created_at - d.cr_created_at)
[event_general+['release_node_id',
'cr_event_id','cr_event_type','cr_login','cr_repository','cr_created_at','cr_ref','time_diff']]
)
df_release_with_create = pd.concat([df_rel_cr, df_cr_rel]).drop_duplicates('event_id')
if(df_release_with_create.shape[0]>0):
df_release_with_create=df_release_with_create[(df_release_with_create['time_diff'] <= UPPER_TIME_THRESHOLD) &
(df_release_with_create['time_diff'] >= LOWER_TIME_THRESHOLD)]
list_event_id_covered.extend(df_release_with_create['event_id'].to_list())
list_event_id_covered.extend(df_release_with_create['cr_event_id'].to_list())
df_release_with_create_proc = (
df_release_with_create
.rename(columns={'login': 'contributor',
'created_at': 'date'})
.assign(activity='Publishing a release')
.assign(date=lambda d: d.date.dt.tz_localize(tz='UTC').map(lambda x: x.isoformat()))
[general+['release_node_id']]
.drop_duplicates()
.sort_values('date')
)
df_all_activities = pd.concat([df_all_activities, df_release_with_create_proc.drop_duplicates()[general]])
'''
ReleaseEvent that are made without creating a new tag
'''
df_release_without_create = (
df_events
.query('event_type == "ReleaseEvent" and event_id not in @list_event_id_covered')
[event_general+['release_node_id']]
.sort_values(['login','repository','created_at'])
)
if(df_release_without_create.shape[0]>0):
list_event_id_covered.extend(df_release_without_create['event_id'].to_list())
df_release_without_create_proc = (
df_release_without_create
.rename(columns={'login': 'contributor',
'created_at': 'date',
'release_node_id': 'GH_node'})
[['contributor','repository','date','GH_node']]
.assign(activity='Publishing a release')
.assign(date=lambda d: d.date.dt.tz_localize(tz='UTC').map(lambda x: x.isoformat()))
.drop_duplicates()
.sort_values('date')
)
df_release_without_create_proc = df_release_without_create_proc.rename(columns={'GH_node':'release_GH_node'})
df_all_activities = pd.concat([df_all_activities, df_release_without_create_proc.drop_duplicates()[general]])
return df_all_activities, list_event_id_covered
def CreatingTag(df_events, list_event_id_covered, df_all_activities):
'''
args: df_events (DataFrame) - events
list_event_id_covered (list) - a list of event id's that are covered in previous iterations
df_all_activities (DataFrame) - DataFrame of all the previously identified activities for a contributor
returns: df_all_activities (DataFrame) - Updated DataFrame of all activities that are identified for the contributor
list_event_id_covered - Updated list of event id's that are covered in previous iterations
Creating tag: Get the events based on CreateEvent and ref_type as tag that were not covered as part of release activity
'''
create_tag = (
df_events
[event_general]
.assign(activity = 'Creating tag')
.rename(columns={'login':'contributor',
'created_at':'date'})
.assign(date=lambda d: d.date.dt.tz_localize(tz='UTC').map(lambda x: x.isoformat()))
.drop_duplicates()
.sort_values('date')
)
list_event_id_covered.extend(create_tag['event_id'].to_list())
df_all_activities = merge_misc_related(df_all_activities, create_tag)
return df_all_activities, list_event_id_covered
def DeletingTag(df_events, list_event_id_covered, df_all_activities):
'''
args: df_events (DataFrame) - events
list_event_id_covered (list) - a list of event id's that are covered in previous iterations
df_all_activities (DataFrame) - DataFrame of all the previously identified activities for a contributor
returns: df_all_activities (DataFrame) - Updated DataFrame of all activities that are identified for the contributor
list_event_id_covered - Updated list of event id's that are covered in previous iterations
Deleting tag: Filter data based on DeleteEvent and ref_type as tag
'''
delete_tag = (
df_events
[event_general]
.assign(activity = 'Deleting tag')
.rename(columns={'login':'contributor',
'created_at':'date'})
.assign(date=lambda d: d.date.dt.tz_localize(tz='UTC').map(lambda x: x.isoformat()))
.drop_duplicates()
.sort_values('date')
)
list_event_id_covered.extend(delete_tag['event_id'].to_list())
df_all_activities = merge_misc_related(df_all_activities, delete_tag)
return df_all_activities, list_event_id_covered
def DeletingBranch(df_events, list_event_id_covered, df_all_activities):
'''
args: df_events (DataFrame) - events
list_event_id_covered (list) - a list of event id's that are covered in previous iterations
df_all_activities (DataFrame) - DataFrame of all the previously identified activities for a contributor
returns: df_all_activities (DataFrame) - Updated DataFrame of all activities that are identified for the contributor
list_event_id_covered - Updated list of event id's that are covered in previous iterations
Deleting branch: Filter data based on DeleteEvent and ref_type as branch
'''
delete_branch = (
df_events
[event_general]
.assign(activity = 'Deleting branch')
.rename(columns={'login':'contributor',
'created_at':'date'})
.assign(date=lambda d: d.date.dt.tz_localize(tz='UTC').map(lambda x: x.isoformat()))
.drop_duplicates()
.sort_values('date')
)
list_event_id_covered.extend(delete_branch['event_id'].to_list())
df_all_activities = merge_misc_related(df_all_activities, delete_branch)
return df_all_activities, list_event_id_covered
def MakingRepositoryPublic(df_events, list_event_id_covered, df_all_activities):
'''
args: df_events (DataFrame) - events
list_event_id_covered (list) - a list of event id's that are covered in previous iterations
df_all_activities (DataFrame) - DataFrame of all the previously identified activities for a contributor
returns: df_all_activities (DataFrame) - Updated DataFrame of all activities that are identified for the contributor
list_event_id_covered - Updated list of event id's that are covered in previous iterations
Making repository public: Filter data based on PublicEvent
'''
public_event = (
df_events
[event_general]
.assign(activity = 'Making repository public')
.rename(columns={'login':'contributor', 'created_at':'date'})
.assign(date=lambda d: d.date.dt.tz_localize(tz='UTC').map(lambda x: x.isoformat()))
.drop_duplicates()
.sort_values('date')
)
list_event_id_covered.extend(public_event['event_id'].to_list())
df_all_activities = pd.concat([df_all_activities, public_event.drop_duplicates()[general]])
return df_all_activities, list_event_id_covered
def AddingCollaborator(df_events, list_event_id_covered, df_all_activities):
'''
args: df_events (DataFrame) - events
list_event_id_covered (list) - a list of event id's that are covered in previous iterations
df_all_activities (DataFrame) - DataFrame of all the previously identified activities for a contributor
returns: df_all_activities (DataFrame) - Updated DataFrame of all activities that are identified for the contributor
list_event_id_covered - Updated list of event id's that are covered in previous iterations
Adding collaborator to repository: Filter data based on MemberEvent
'''
member_event = (
df_events
[event_general]
.assign(activity = 'Adding collaborator to repository')
.rename(columns={'login':'contributor', 'created_at':'date'})
.assign(date=lambda d: d.date.dt.tz_localize(tz='UTC').map(lambda x: x.isoformat()))
.drop_duplicates()
.sort_values('date')
)
list_event_id_covered.extend(member_event['event_id'].to_list())
df_all_activities = pd.concat([df_all_activities, member_event.drop_duplicates()[general]])
return df_all_activities, list_event_id_covered
def ForkingRepository(df_events, list_event_id_covered, df_all_activities):
'''
args: df_events (DataFrame) - events
list_event_id_covered (list) - a list of event id's that are covered in previous iterations
df_all_activities (DataFrame) - DataFrame of all the previously identified activities for a contributor
returns: df_all_activities (DataFrame) - Updated DataFrame of all activities that are identified for the contributor
list_event_id_covered - Updated list of event id's that are covered in previous iterations
Forking a repository: Filter data based on ForkEvent
'''
forking_repository = (
df_events
[event_general]
.assign(activity = 'Forking repository')
.rename(columns={'login':'contributor', 'created_at':'date'})
.assign(date=lambda d: d.date.dt.tz_localize(tz='UTC').map(lambda x: x.isoformat()))
.drop_duplicates()
.sort_values('date')
)
list_event_id_covered.extend(forking_repository['event_id'].to_list())
df_all_activities = pd.concat([df_all_activities, forking_repository.drop_duplicates()[general]])
return df_all_activities, list_event_id_covered
def StarringRepository(df_events, list_event_id_covered, df_all_activities):
'''
args: df_events (DataFrame) - events
list_event_id_covered (list) - a list of event id's that are covered in previous iterations
df_all_activities (DataFrame) - DataFrame of all the previously identified activities for a contributor
returns: df_all_activities (DataFrame) - Updated DataFrame of all activities that are identified for the contributor
list_event_id_covered - Updated list of event id's that are covered in previous iterations
Starring a repository: Filter data based on WatchEvent
'''
starring_repository = (
df_events
[event_general]
.assign(activity = 'Starring repository')
.rename(columns={'login':'contributor', 'created_at':'date'})
.assign(date=lambda d: d.date.dt.tz_localize(tz='UTC').map(lambda x: x.isoformat()))
.drop_duplicates()
.sort_values('date')
)
list_event_id_covered.extend(starring_repository['event_id'].to_list())
df_all_activities = pd.concat([df_all_activities, starring_repository.drop_duplicates()[general]])
return df_all_activities, list_event_id_covered
def EditingWikiPage(df_events, list_event_id_covered, df_all_activities):
'''
args: df_events (DataFrame) - events
list_event_id_covered (list) - a list of event id's that are covered in previous iterations
df_all_activities (DataFrame) - DataFrame of all the previously identified activities for a contributor
returns: df_all_activities (DataFrame) - Updated DataFrame of all activities that are identified for the contributor
list_event_id_covered - Updated list of event id's that are covered in previous iterations
Editing a wiki page: Filter events based on GollumEvent
'''
df_wiki_page = (
df_events
[event_general]
.rename(columns={'login':'contributor',
'created_at':'date'})
.assign(activity = 'Editing wiki page')
.assign(date=lambda d: d.date.dt.tz_localize(tz='UTC').map(lambda x: x.isoformat()))
.drop_duplicates()
.sort_values('date')
)
list_event_id_covered.extend(df_wiki_page['event_id'].to_list())
df_all_activities = pd.concat([df_all_activities,df_wiki_page.drop_duplicates()[general]])
return df_all_activities, list_event_id_covered
def merge_issue_related(df_all,df):
'''
args: df_all - DataFrame of all activities
df - DataFrame of issue related activities
return: df_all - DataFrame with all the activities (including issue related activities)
method: Get the dataframe that has all the activities, append the activity fields corresponding to
issue and return dataframe with all activities
'''
df_all = pd.concat([df_all,df.drop_duplicates()[general]])
return(df_all)
def TransferingIssue(df_events, list_event_id_covered, df_all_activities):
'''
args: df_events (DataFrame) - events
list_event_id_covered (list) - a list of event id's that are covered in previous iterations
df_all_activities (DataFrame) - DataFrame of all the previously identified activities for a contributor
returns: df_all_activities (DataFrame) - Updated DataFrame of all activities that are identified for the contributor
list_event_id_covered - Updated list of event id's that are covered in previous iterations
Transferring an issue:
Issue is tranferred if
1. action is "opened" with some timestamp in issue_closed_at field - Issue transferred after it is closed
2. action is "opened" without any timestamp in issue_closed_at, but number of comments > 0 - Issue is transferred while it is open
'''
df_transferring_issue = (
df_events
[event_general+['issue_node_id']]
.rename(columns={'login':'contributor', 'created_at':'date'})
.assign(activity = 'Transferring issue')
.assign(date=lambda d: d.date.dt.tz_localize(tz='UTC').map(lambda x: x.isoformat()))
.drop_duplicates()
.sort_values('date')
)
list_event_id_covered.extend(df_transferring_issue['event_id'].to_list())
df_all_activities = merge_issue_related(df_all_activities,df_transferring_issue)
return df_all_activities, list_event_id_covered
def OpeningIssue(df_events, list_event_id_covered, df_all_activities):
'''
args: df_events (DataFrame) - events
list_event_id_covered (list) - a list of event id's that are covered in previous iterations
df_all_activities (DataFrame) - DataFrame of all the previously identified activities for a contributor
returns: df_all_activities (DataFrame) - Updated DataFrame of all activities that are identified for the contributor
list_event_id_covered - Updated list of event id's that are covered in previous iterations
Opening issue: If an issue with action opened is not covered in transferred issue then it is new
'''
df_opening_issue = (
df_events
[event_general+['issue_node_id']]
.rename(columns={'login':'contributor', 'created_at':'date'})
.assign(date=lambda d: d.date.dt.tz_localize(tz='UTC').map(lambda x: x.isoformat()))
.assign(activity='Opening issue')
.drop_duplicates()
.sort_values('date')
)
list_event_id_covered.extend(df_opening_issue['event_id'].to_list())
df_all_activities = merge_issue_related(df_all_activities,df_opening_issue)
return df_all_activities, list_event_id_covered
def ClosingIssue(df_events, list_event_id_covered, df_all_activities):
'''
args: df_events (DataFrame) - events
list_event_id_covered (list) - a list of event id's that are covered in previous iterations
df_all_activities (DataFrame) - DataFrame of all the previously identified activities for a contributor
returns: df_all_activities (DataFrame) - Updated DataFrame of all activities that are identified for the contributor
list_event_id_covered - Updated list of event id's that are covered in previous iterations
Closing issue:
1. Issue is closed with IssueCommentEvent if both the events occur within 2 seconds
2. Issue is close without a comment
'''
df_closing_issue_or_PR_comment = (
df_events
.drop_duplicates()
[event_general+['issue_number','state','issue_node_id']]
.sort_values(['login','repository','created_at'])
)
df_closing_issue_and_comment_1 = df_closing_issue_or_PR_comment[df_closing_issue_or_PR_comment['issue_number'].notnull()]
df_closing_issue_before_comment = (
df_closing_issue_and_comment_1
.assign(next_event_id=lambda d: d.event_id.shift(-1))
.assign(next_event=lambda d: d.event_type.shift(-1))
.assign(next_login=lambda d: d.login.shift(-1))
.assign(next_repository=lambda d: d.repository.shift(-1))
.assign(next_issue_number=lambda d: d.issue_number.shift(-1))
.assign(next_issue_state=lambda d: d.state.shift(-1))
.assign(next_event_created_at=lambda d: d.created_at.shift(-1))
.assign(comm_event_type=lambda d:
np.where(((d.event_type == "IssuesEvent") & (d.next_event == "IssueCommentEvent") &
(d.login == d.next_login) & (d.repository == d.next_repository) &
(d.issue_number == d.next_issue_number) & (d.state == d.next_issue_state)),
d.next_event, np.nan))
.query('event_type == "IssuesEvent" and comm_event_type == "IssueCommentEvent"')
)
if(df_closing_issue_before_comment.shape[0]>0):
df_closing_issue_before_comment = (
df_closing_issue_before_comment
.rename(columns={'next_event_created_at':'comm_created_at','next_repository':'comm_repository',
'next_login':'comm_login', 'next_event_id':'comm_event_id'})
.assign(time_diff=lambda d: d.created_at - d.comm_created_at)
[event_general+['issue_node_id', 'comm_event_id','comm_event_type','comm_login','comm_repository',
'time_diff']]
)
df_closing_issue_after_comment = (
df_closing_issue_and_comment_1
.assign(prev_event_id=lambda d: d.event_id.shift(1))
.assign(prev_event=lambda d: d.event_type.shift(1))
.assign(prev_login=lambda d: d.login.shift(1))
.assign(prev_repository=lambda d: d.repository.shift(1))
.assign(prev_issue_number=lambda d: d.issue_number.shift(1))
.assign(prev_issue_state=lambda d: d.state.shift(1))
.assign(prev_event_created_at=lambda d: d.created_at.shift(1))
.assign(comm_event_type=lambda d:
np.where(((d.event_type == "IssuesEvent") & (d.prev_event == "IssueCommentEvent") &
(d.login == d.prev_login) & (d.repository == d.prev_repository) &
(d.issue_number == d.prev_issue_number) & (d.state == d.prev_issue_state)),
d.prev_event, np.nan))
.query('event_type == "IssuesEvent" and comm_event_type == "IssueCommentEvent"')
)
if(df_closing_issue_after_comment.shape[0]>0):
df_closing_issue_after_comment = (
df_closing_issue_after_comment
.rename(columns={'prev_event_created_at':'comm_created_at','prev_repository':'comm_repository',
'prev_login':'comm_login', 'prev_event_id':'comm_event_id'})
.assign(time_diff=lambda d: d.created_at - d.comm_created_at)
[event_general+['issue_node_id',
'comm_event_id','comm_event_type','comm_login','comm_repository',
'time_diff']]
)
df_closing_issue_with_comment = pd.concat([df_closing_issue_before_comment, df_closing_issue_after_comment]).drop_duplicates()
if(df_closing_issue_with_comment.shape[0]>0):
df_closing_issue_with_comment=df_closing_issue_with_comment[(df_closing_issue_with_comment['time_diff'] <= UPPER_TIME_THRESHOLD) &
(df_closing_issue_with_comment['time_diff'] >= LOWER_TIME_THRESHOLD)]
list_event_id_covered.extend(df_closing_issue_with_comment['event_id'].to_list())
list_event_id_covered.extend(df_closing_issue_with_comment['comm_event_id'].to_list())
df_closing_issue_with_comment_proc = (
df_closing_issue_with_comment
.rename(columns={'login': 'contributor',
'created_at': 'date'})
.assign(date=lambda d: d.date.dt.tz_localize(tz='UTC').map(lambda x: x.isoformat()))
.assign(activity='Closing issue')
[general+['issue_node_id']]
.drop_duplicates()
.sort_values('date')
)
df_all_activities = merge_issue_related(df_all_activities,df_closing_issue_with_comment_proc)
'''
Obtain the closed issue events that did not invovle any commeting activity while closing
'''
df_closing_issue_without_comment= (
df_events
.query('event_type == "IssuesEvent" and action == "closed" and event_id not in @list_event_id_covered')
[event_general+['issue_closed_at','issue_node_id']]
)
if(df_closing_issue_without_comment.shape[0]>0):
list_event_id_covered.extend(df_closing_issue_without_comment['event_id'].to_list())
df_closing_issue_without_comment_proc = (
df_closing_issue_without_comment
.rename(columns={'login': 'contributor',
'created_at': 'date'})
.assign(date=lambda d: d.date.dt.tz_localize(tz='UTC').map(lambda x: x.isoformat()))
.assign(closed_at=lambda d: d.issue_closed_at.dt.tz_localize(tz='UTC').map(lambda x: x.isoformat()))
.assign(activity='Closing issue')
[general + ['issue_node_id','closed_at']]
.drop_duplicates()
)
df_all_activities = merge_issue_related(df_all_activities,df_closing_issue_without_comment_proc)
return df_all_activities, list_event_id_covered
def ReopeningIssue(df_events, list_event_id_covered, df_all_activities):
'''
args: df_events (DataFrame) - events
list_event_id_covered (list) - a list of event id's that are covered in previous iterations
df_all_activities (DataFrame) - DataFrame of all the previously identified activities for a contributor
returns: df_all_activities (DataFrame) - Updated DataFrame of all activities that are identified for the contributor
list_event_id_covered - Updated list of event id's that are covered in previous iterations
Reopening an issue:
1. Issue is reopened with IssueCommentEvent if both the events occur within 2 seconds
2. Issue is reopened without any comment.
'''
df_reopening_issue_or_PR_comment = (
df_events
.drop_duplicates()
[event_general+['issue_number','issue_node_id']]
.sort_values(['login','repository','created_at'])
)
df_reopening_issue_and_comment_1 = df_reopening_issue_or_PR_comment[df_reopening_issue_or_PR_comment['issue_number'].notnull()]
df_reopening_issue_before_comment = (
df_reopening_issue_and_comment_1
.assign(next_event_id=lambda d: d.event_id.shift(-1))
.assign(next_event=lambda d: d.event_type.shift(-1))
.assign(next_login=lambda d: d.login.shift(-1))
.assign(next_repository=lambda d: d.repository.shift(-1))
.assign(next_issue_number=lambda d: d.issue_number.shift(-1))
.assign(next_event_created_at=lambda d: d.created_at.shift(-1))
.assign(comm_event_type=lambda d:
np.where(((d.event_type == "IssuesEvent") & (d.next_event == "IssueCommentEvent") &
(d.login == d.next_login) & (d.repository == d.next_repository) &
(d.issue_number == d.next_issue_number)),
d.next_event, np.nan))
.query('event_type == "IssuesEvent" and comm_event_type == "IssueCommentEvent"')
)
if(df_reopening_issue_before_comment.shape[0]>0):
df_reopening_issue_before_comment = (
df_reopening_issue_before_comment
.rename(columns={'next_event_created_at':'comm_created_at',
'next_repository':'comm_repository', 'next_login':'comm_login',
'next_event_id':'comm_event_id' })
.assign(time_diff=lambda d: d.created_at - d.comm_created_at)
[event_general+['issue_node_id',
'comm_event_id','comm_event_type','comm_login','comm_repository','comm_created_at',
'time_diff']]
)
df_reopening_issue_after_comment = (
df_reopening_issue_and_comment_1
.assign(prev_event_id=lambda d: d.event_id.shift(1))
.assign(prev_event=lambda d: d.event_type.shift(1))
.assign(prev_login=lambda d: d.login.shift(1))
.assign(prev_repository=lambda d: d.repository.shift(1))
.assign(prev_issue_number=lambda d: d.issue_number.shift(1))
.assign(prev_event_created_at=lambda d: d.created_at.shift(1))
.assign(comm_event_type=lambda d:
np.where(((d.event_type == "IssuesEvent") & (d.prev_event == "IssueCommentEvent") &
(d.login == d.prev_login) & (d.repository == d.prev_repository) &
(d.issue_number == d.prev_issue_number)),
d.prev_event, np.nan))
.query('event_type == "IssuesEvent" and comm_event_type == "IssueCommentEvent"')
.rename(columns={'prev_event_created_at':'comm_created_at',
'prev_repository':'comm_repository', 'prev_login':'comm_login',
'prev_event_id':'comm_event_id' })
)
if(df_reopening_issue_after_comment.shape[0]>0):
df_reopening_issue_after_comment = (
df_reopening_issue_after_comment
.rename(columns={'prev_event_created_at':'comm_created_at',
'prev_repository':'comm_repository', 'prev_login':'comm_login',
'prev_event_id':'comm_event_id' })
.assign(time_diff=lambda d: d.created_at - d.comm_created_at)
[event_general+['issue_node_id',
'comm_event_id','comm_event_type','comm_login','comm_repository','comm_created_at',
'time_diff']]
)
df_reopening_issue_with_comment = pd.concat([df_reopening_issue_before_comment, df_reopening_issue_after_comment]).drop_duplicates()
if(df_reopening_issue_with_comment.shape[0]>0):
df_reopening_issue_with_comment = df_reopening_issue_with_comment[(df_reopening_issue_with_comment['time_diff'] <= UPPER_TIME_THRESHOLD) &
(df_reopening_issue_with_comment['time_diff'] >= LOWER_TIME_THRESHOLD)]
list_event_id_covered.extend(df_reopening_issue_with_comment['event_id'].to_list())
list_event_id_covered.extend(df_reopening_issue_with_comment['comm_event_id'].to_list())
df_reopening_issue_with_comment_proc = (
df_reopening_issue_with_comment
.rename(columns={'login': 'contributor',
'created_at': 'date'})
.assign(date=lambda d: d.date.dt.tz_localize(tz='UTC').map(lambda x: x.isoformat()))
.assign(activity='Reopening issue')
[general + ['issue_node_id']]
.drop_duplicates()
.sort_values('date')
)
df_all_activities = merge_issue_related(df_all_activities,df_reopening_issue_with_comment_proc)
'''
Obtain the reopenend issue events that did not invovle any commeting activity while closing
'''
df_reopening_issue_without_comment= (
df_events
.query('event_type == "IssuesEvent" and action == "reopened" and event_id not in @list_event_id_covered')
[event_general+['issue_node_id']]
)
if(df_reopening_issue_without_comment.shape[0]>0):
list_event_id_covered.extend(df_reopening_issue_without_comment['event_id'].to_list())
df_reopening_issue_without_comment_proc = (
df_reopening_issue_without_comment
.rename(columns={'login': 'contributor',
'created_at': 'date'})
.assign(date=lambda d: d.date.dt.tz_localize(tz='UTC').map(lambda x: x.isoformat()))
.assign(activity='Reopening issue')
[general + ['issue_node_id']]
.drop_duplicates()
)
df_all_activities = merge_issue_related(df_all_activities,df_reopening_issue_without_comment_proc)
return df_all_activities, list_event_id_covered
def CommentingIssue(df_events, list_event_id_covered, df_all_activities):
'''
args: df_events (DataFrame) - events
list_event_id_covered (list) - a list of event id's that are covered in previous iterations
df_all_activities (DataFrame) - DataFrame of all the previously identified activities for a contributor
returns: df_all_activities (DataFrame) - Updated DataFrame of all activities that are identified for the contributor
list_event_id_covered - Updated list of event id's that are covered in previous iterations
Commenting in issue: Filter the events based on IssueCommentEvent, where an issue_number exists in html url
'''
df_issue_commenting = (
df_events[df_events['issue_number'].notnull()]
[event_general+['comment_node_id']]
.sort_values(['login','repository','created_at'])
.rename(columns={'login': 'contributor',
'created_at': 'date'})
.assign(date=lambda d: d.date.dt.tz_localize(tz='UTC').map(lambda x: x.isoformat()))
.assign(activity = "Commenting issue")
.drop_duplicates()
.sort_values('date')
)
list_event_id_covered.extend(df_issue_commenting['event_id'].to_list())
df_all_activities = merge_issue_related(df_all_activities,df_issue_commenting)
return df_all_activities, list_event_id_covered
def merge_pr_related(df_all, df):
'''
args: df_all - DataFrame of all activities
df - DataFrame of pr related activities
return: df_all - DataFrame with all the activities (including pr related activities)
method: Get the dataframe that has all the activities, append the activities corresponding to pr and return
dataframe with all activities
'''
df_all = pd.concat([df_all,df.drop_duplicates()[general]])
return(df_all)
def OpeningPullRequest(df_events, list_event_id_covered, df_all_activities):
'''
args: df_events (DataFrame) - events
list_event_id_covered (list) - a list of event id's that are covered in previous iterations
df_all_activities (DataFrame) - DataFrame of all the previously identified activities for a contributor
returns: df_all_activities (DataFrame) - Updated DataFrame of all activities that are identified for the contributor
list_event_id_covered - Updated list of event id's that are covered in previous iterations
Opening pull request: If a PullRequestEvent with action as opened.
'''
df_opening_pullrequest = (
df_events
[event_general+['PR_node_id']]
.rename(columns={'login':'contributor', 'created_at':'date'})
.assign(date=lambda d: d.date.dt.tz_localize(tz='UTC').map(lambda x: x.isoformat()))
.assign(activity='Opening pull request')
.assign(pr_node_id=lambda d: d.PR_node_id)
.drop_duplicates()
.sort_values('date')
)
list_event_id_covered.extend(df_opening_pullrequest['event_id'].to_list())
df_all_activities = merge_pr_related(df_all_activities,df_opening_pullrequest)
return df_all_activities, list_event_id_covered
def ReopeningPullRequest(df_events, list_event_id_covered, df_all_activities):
'''
args: df_events (DataFrame) - events
list_event_id_covered (list) - a list of event id's that are covered in previous iterations
df_all_activities (DataFrame) - DataFrame of all the previously identified activities for a contributor
returns: df_all_activities (DataFrame) - Updated DataFrame of all activities that are identified for the contributor
list_event_id_covered - Updated list of event id's that are covered in previous iterations
Reopening a pull request:
1. Pull request is reopened with IssueCommentEvent if both the events occur within 2 seconds
2. Pull request is reopened without any comment.
'''
df_reopening_issue_or_PR_comment = (
df_events
.drop_duplicates()
[event_general+['PR_number','PR_node_id']]
.sort_values(['login','repository','created_at'])
)
df_reopening_pr_and_comment_1 = df_reopening_issue_or_PR_comment[df_reopening_issue_or_PR_comment['PR_number'].notnull()]
df_reopening_pr_before_comment = (
df_reopening_pr_and_comment_1
.assign(next_event_id=lambda d: d.event_id.shift(-1))
.assign(next_event=lambda d: d.event_type.shift(-1))
.assign(next_login=lambda d: d.login.shift(-1))
.assign(next_repository=lambda d: d.repository.shift(-1))
.assign(next_pr_number=lambda d: d.PR_number.shift(-1))
.assign(next_event_created_at=lambda d: d.created_at.shift(-1))
.assign(comm_event_type=lambda d:
np.where(((d.event_type == "PullRequestEvent") & (d.next_event == "IssueCommentEvent") &
(d.login == d.next_login) & (d.repository == d.next_repository) &
(d.PR_number == d.next_pr_number)),
d.next_event, np.nan))
.query('event_type == "PullRequestEvent" and comm_event_type == "IssueCommentEvent"')
)
if(df_reopening_pr_before_comment.shape[0]>0):
df_reopening_pr_before_comment = (
df_reopening_pr_before_comment
.rename(columns={'next_event_created_at':'comm_created_at',
'next_repository':'comm_repository', 'next_login':'comm_login',
'next_event_id':'comm_event_id'})
.assign(time_diff=lambda d: d.created_at - d.comm_created_at)
[event_general+['PR_node_id',
'comm_event_id','comm_event_type','comm_login','comm_repository','comm_created_at',
'time_diff']]
)
df_reopening_pr_after_comment = (
df_reopening_pr_and_comment_1
.assign(prev_event_id=lambda d: d.event_id.shift(1))
.assign(prev_event=lambda d: d.event_type.shift(1))
.assign(prev_login=lambda d: d.login.shift(1))
.assign(prev_repository=lambda d: d.repository.shift(1))
.assign(prev_pr_number=lambda d: d.PR_number.shift(1))
.assign(prev_event_created_at=lambda d: d.created_at.shift(1))
.assign(comm_event_type=lambda d:
np.where(((d.event_type == "PullRequestEvent") & (d.prev_event == "IssueCommentEvent") &
(d.login == d.prev_login) & (d.repository == d.prev_repository) &
(d.PR_number == d.prev_pr_number)),
d.prev_event, np.nan))
.query('event_type == "PullRequestEvent" and comm_event_type == "IssueCommentEvent"')
)
if(df_reopening_pr_after_comment.shape[0]>0):
df_reopening_pr_after_comment = (
df_reopening_pr_after_comment
.rename(columns={'prev_event_created_at':'comm_created_at',
'prev_repository':'comm_repository', 'prev_login':'comm_login',
'prev_event_id':'comm_event_id'})
.assign(time_diff=lambda d: d.created_at - d.comm_created_at)
[event_general+['PR_node_id',
'comm_event_id','comm_event_type','comm_login','comm_repository','comm_created_at',
'time_diff']]
)
df_reopening_pr_with_comment = pd.concat([df_reopening_pr_before_comment, df_reopening_pr_after_comment]).drop_duplicates()
'''
Save the event_ids that are processed in the PullRequestEvent and its corresponding IssueCommentEvent
Change the field names and create the dataframe in the required format to be saved in .json
text_length>0 = comment and close is done
text_length=0 closed without any comment
'''
if(df_reopening_pr_with_comment.shape[0]>0):
df_reopening_pr_with_comment = df_reopening_pr_with_comment[(df_reopening_pr_with_comment['time_diff'] <= UPPER_TIME_THRESHOLD) &
(df_reopening_pr_with_comment['time_diff'] >= LOWER_TIME_THRESHOLD)]
list_event_id_covered.extend(df_reopening_pr_with_comment['event_id'].to_list())
list_event_id_covered.extend(df_reopening_pr_with_comment['comm_event_id'].to_list())
df_reopening_pr_with_comment_proc = (
df_reopening_pr_with_comment
.rename(columns={'login': 'contributor',
'created_at': 'date'})
.assign(date=lambda d: d.date.dt.tz_localize(tz='UTC').map(lambda x: x.isoformat()))
.assign(activity='Reopening pull request')
.assign(pr_node_id=lambda d: d.PR_node_id)
[general + ['pr_node_id']]
.drop_duplicates()
.sort_values('date')
)
df_all_activities = merge_pr_related(df_all_activities,df_reopening_pr_with_comment_proc)
'''
Obtain the reopenend pull request events that did not invovle any commeting activity while closing
'''
df_reopening_pr_without_comment= (
df_events
.query('event_type == "PullRequestEvent" and action == "reopened" and event_id not in @list_event_id_covered')
[event_general+['PR_node_id']]
)
if(df_reopening_pr_without_comment.shape[0]>0):
df_reopening_pr_without_comment = (
df_reopening_pr_without_comment
.rename(columns={'login':'contributor', 'created_at':'date'})
.assign(date=lambda d: d.date.dt.tz_localize(tz='UTC').map(lambda x: x.isoformat()))
.assign(activity='Reopening pull request')
.assign(pr_node_id=lambda d: d.PR_node_id)
.drop_duplicates()
.sort_values('date')
)
list_event_id_covered.extend(df_reopening_pr_without_comment['event_id'].to_list())
df_all_activities = merge_pr_related(df_all_activities,df_reopening_pr_without_comment)
return df_all_activities, list_event_id_covered
def ClosingPullRequest(df_events, list_event_id_covered, df_all_activities):
'''
args: df_events (DataFrame) - events
list_event_id_covered (list) - a list of event id's that are covered in previous iterations
df_all_activities (DataFrame) - DataFrame of all the previously identified activities for a contributor
returns: df_all_activities (DataFrame) - Updated DataFrame of all activities that are identified for the contributor
list_event_id_covered - Updated list of event id's that are covered in previous iterations
Closing PR
1. Closing PR and merging it (cannot comment) with a push that happened within 2 seconds
2. Closing PR and merging it, no push detected - PR is closed, but its corresponding push event (same sha) has happened long back, no push for some PRs
3. Closing PR and rejecting it, with IssueCommentEvent that happened within 2 seconds
4. Closing PR and rejecting it, without comment
'''
df_pr_merge = (
df_events
.query('event_type == "PullRequestEvent" and action == "closed" and merged == True')
.dropna(axis=1, how='all')
.drop_duplicates('event_id')
)
df_push_events = (