7
7
from .gitorg import get_issue
8
8
9
9
10
+ PRIVATE_INSTANCE_STATUSES = (
11
+ 'ABANDONED' ,
12
+ 'OUT_OF_TIME' ,
13
+ 'PENDING_PARENTAL_CONSENT' ,
14
+ 'UNASSIGNED_BY_MENTOR' ,
15
+ )
16
+
17
+ PRIVATE_INSTANCE_ATTRIBUTES = (
18
+ 'modified' ,
19
+ 'deadline' ,
20
+ )
21
+
10
22
_client = None
11
23
_org = {}
12
24
_tasks = {}
@@ -78,6 +90,37 @@ def get_instances():
78
90
return _instances
79
91
80
92
93
+ def cleanse_tasks (tasks ):
94
+ cleansed_tasks = dict (
95
+ (task_id , task )
96
+ for task_id , task
97
+ in tasks .items ()
98
+ if task ['status' ] == 2
99
+ )
100
+
101
+ for task in cleansed_tasks .values ():
102
+ del task ['mentors' ]
103
+
104
+ return cleansed_tasks
105
+
106
+
107
+ def cleanse_instances (instances ):
108
+ cleansed_instances = dict (
109
+ (instance_id , instance )
110
+ for instance_id , instance
111
+ in instances .items ()
112
+ if instance ['status' ] not in PRIVATE_INSTANCE_STATUSES
113
+ )
114
+
115
+ for instance in cleansed_instances .values ():
116
+ if instance ['status' ] != 'COMPLETED' :
117
+ instance ['status' ] = 'CLAIMED'
118
+ for key in PRIVATE_INSTANCE_ATTRIBUTES :
119
+ del instance [key ]
120
+
121
+ return cleansed_instances
122
+
123
+
81
124
def get_students ():
82
125
students = {}
83
126
for _ , instance in get_instances ().items ():
@@ -99,17 +142,8 @@ def get_students():
99
142
student ['instances' ].append (instance )
100
143
101
144
102
- def get_effective_students (students ):
103
- for student in list (students ):
104
- instances = student ['instances' ]
105
- instances = [instance for instance in instances
106
- if instance ['status' ] != 'ABANDONED' ]
107
- if instances :
108
- yield student
109
-
110
-
111
- def get_issue_related_students (students ):
112
- for student in list (get_effective_students (students )):
145
+ def get_issue_related_students ():
146
+ for student in list (get_students ()):
113
147
instances = student ['instances' ]
114
148
for instance in instances :
115
149
task = get_task (instance ['task_definition_id' ])
@@ -119,8 +153,8 @@ def get_issue_related_students(students):
119
153
break
120
154
121
155
122
- def get_linked_students (students ):
123
- for student in list (get_issue_related_students (students )):
156
+ def get_linked_students ():
157
+ for student in list (get_issue_related_students ()):
124
158
instances = student ['instances' ]
125
159
for instance in instances :
126
160
task = get_task (instance ['task_definition_id' ])
@@ -142,5 +176,7 @@ def get_linked_students(students):
142
176
(task_id , url , ', ' .join (issue .assignees )))
143
177
else :
144
178
student ['username' ] = issue .assignees [0 ]
179
+ print ('student %s is %s because of %s' %
180
+ (student ['id' ], issue .assignees [0 ], url ))
145
181
yield student
146
182
break
0 commit comments