1
1
import os
2
2
import re
3
+ import json
3
4
import logging
4
5
import time
5
6
import urllib .parse
11
12
from github .Repository import Repository
12
13
13
14
from utils import IssuePackage , REQUEST_REPO , AUTO_ASSIGN_LABEL , AUTO_PARSE_LABEL , get_origin_link_and_tag ,\
14
- MULTI_LINK_LABEL , INCONSISTENT_TAG
15
+ MULTI_LINK_LABEL , INCONSISTENT_TAG , TYPESPEC_LABEL
15
16
16
17
_LOG = logging .getLogger (__name__ )
17
18
18
19
# assignee dict which will be assigned to handle issues
19
20
_LANGUAGE_OWNER = {'msyyc' }
20
21
21
22
# 'github assignee': 'token'
22
- _BOT_NAME = 'azure-sdk'
23
23
_ASSIGNEE_TOKEN = os .getenv ('AZURESDK_BOT_TOKEN' )
24
24
25
25
_SWAGGER_URL = 'https://github.com/Azure/azure-rest-api-specs/blob/main/specification'
26
26
_SWAGGER_PULL = 'https://github.com/Azure/azure-rest-api-specs/pull'
27
+ _HINTS = ["FirstGA" , "FirstBeta" , "HoldOn" , "OnTime" , "ForCLI" , TYPESPEC_LABEL ]
27
28
28
29
29
30
class IssueProcess :
@@ -67,6 +68,17 @@ def __init__(self, issue_package: IssuePackage, request_repo_dict: Dict[str, Rep
67
68
self .is_open = True
68
69
self .issue_title = issue_package .issue .title .split (": " , 1 )[- 1 ]
69
70
self .spec_repo = Path (os .getenv ('SPEC_REPO' ))
71
+ self .typespec_json = Path (os .getenv ('TYPESPEC_JSON' ))
72
+ self .language_name = "common"
73
+
74
+ @property
75
+ def for_typespec (self ) -> bool :
76
+ with open (str (self .typespec_json ), "r" ) as file :
77
+ data = json .load (file )
78
+ return self .package_name in data .get (self .language_name , [])
79
+
80
+ def has_label (self , label : str ) -> bool :
81
+ return label in self .issue_package .labels_name
70
82
71
83
@property
72
84
def created_date_format (self ) -> str :
@@ -199,8 +211,16 @@ def check_tag_consistency(self) -> None:
199
211
f'it is still `{ self .default_readme_tag } `, please modify the readme.md or your '
200
212
f'**Readme Tag** above ' )
201
213
214
+ def get_package_name (self ) -> None :
215
+ issue_body_list = self .get_issue_body ()
216
+ for line in issue_body_list :
217
+ if line .strip ('\r \n ' ).startswith ('package-name:' ):
218
+ self .package_name = line .split (':' )[- 1 ].strip ('\r \n ' )
219
+ break
220
+
202
221
def auto_parse (self ) -> None :
203
- if AUTO_PARSE_LABEL in self .issue_package .labels_name :
222
+ if self .has_label (AUTO_ASSIGN_LABEL ):
223
+ self .get_package_name ()
204
224
return
205
225
206
226
self .add_label (AUTO_PARSE_LABEL )
@@ -221,8 +241,9 @@ def auto_parse(self) -> None:
221
241
self .edit_issue_body ()
222
242
223
243
def add_label (self , label : str ) -> None :
224
- self .issue_package .issue .add_to_labels (label )
225
- self .issue_package .labels_name .add (label )
244
+ if not self .has_label (label ):
245
+ self .issue_package .issue .add_to_labels (label )
246
+ self .issue_package .labels_name .add (label )
226
247
227
248
def update_assignee (self , assignee_to_del : str , assignee_to_add : str ) -> None :
228
249
if assignee_to_del :
@@ -245,7 +266,7 @@ def auto_assign_policy(self) -> str:
245
266
return assignees [random_idx ]
246
267
247
268
def auto_assign (self ) -> None :
248
- if AUTO_ASSIGN_LABEL in self .issue_package . labels_name :
269
+ if self .has_label ( AUTO_PARSE_LABEL ) :
249
270
self .update_issue_instance ()
250
271
return
251
272
# assign averagely
@@ -283,12 +304,12 @@ def new_comment_policy(self):
283
304
self .bot_advice .append ('new comment.' )
284
305
285
306
def multi_link_policy (self ):
286
- if MULTI_LINK_LABEL in self .issue_package . labels_name :
307
+ if self .has_label ( MULTI_LINK_LABEL ) :
287
308
self .bot_advice .append ('multi readme link!' )
288
309
289
310
def inconsistent_tag_policy (self ):
290
- if INCONSISTENT_TAG in self .issue_package . labels_name :
291
- self .bot_advice .append ('Attention to inconsistent tag' )
311
+ if self .has_label ( INCONSISTENT_TAG ) :
312
+ self .bot_advice .append ('Attention to inconsistent tag. ' )
292
313
293
314
def remind_logic (self ) -> bool :
294
315
return abs (self .date_from_target ) <= 2
@@ -298,14 +319,25 @@ def print_date_from_target_date(self) -> str:
298
319
299
320
def date_remind_policy (self ):
300
321
if self .remind_logic ():
301
- self .bot_advice .append ('close to release date. ' )
322
+ self .bot_advice .append ('close to release date.' )
323
+
324
+ def hint_policy (self ):
325
+ for item in _HINTS :
326
+ if self .has_label (item ):
327
+ self .bot_advice .append (f"{ item } ." )
328
+
329
+ def typespec_policy (self ):
330
+ if self .for_typespec :
331
+ self .add_label (TYPESPEC_LABEL )
302
332
303
333
def auto_bot_advice (self ):
304
334
self .new_issue_policy ()
335
+ self .typespec_policy ()
305
336
self .new_comment_policy ()
306
337
self .multi_link_policy ()
307
338
self .date_remind_policy ()
308
339
self .inconsistent_tag_policy ()
340
+ self .hint_policy ()
309
341
310
342
def get_target_date (self ):
311
343
body = self .get_issue_body ()
@@ -351,6 +383,10 @@ def __init__(self, issues_package: List[IssuePackage], language_owner: Set[str],
351
383
for assignee in self .assignee_candidates :
352
384
self .request_repo_dict [assignee ] = Github (assignee_token ).get_repo (REQUEST_REPO )
353
385
386
+ @staticmethod
387
+ def for_test ():
388
+ return bool (os .getenv ("TEST_ISSUE_NUMBER" ))
389
+
354
390
def log_error (self , message : str ) -> None :
355
391
_LOG .error (message )
356
392
0 commit comments