Skip to content

Commit 11fd092

Browse files
authored
[Release helper] support generation from typespec (#35181)
* make hint_policy common for all language * support generate from tsp * update * fix python * for debug * small optimization * enable trigger auto release with typespec folder * add java assignee * fix var name * update excel * change another folder * fix env var * small optimization * optimize hint
1 parent 9f7ae58 commit 11fd092

File tree

9 files changed

+129
-54
lines changed

9 files changed

+129
-54
lines changed

scripts/release_helper/common.py

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import re
3+
import json
34
import logging
45
import time
56
import urllib.parse
@@ -11,19 +12,19 @@
1112
from github.Repository import Repository
1213

1314
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
1516

1617
_LOG = logging.getLogger(__name__)
1718

1819
# assignee dict which will be assigned to handle issues
1920
_LANGUAGE_OWNER = {'msyyc'}
2021

2122
# 'github assignee': 'token'
22-
_BOT_NAME = 'azure-sdk'
2323
_ASSIGNEE_TOKEN = os.getenv('AZURESDK_BOT_TOKEN')
2424

2525
_SWAGGER_URL = 'https://github.com/Azure/azure-rest-api-specs/blob/main/specification'
2626
_SWAGGER_PULL = 'https://github.com/Azure/azure-rest-api-specs/pull'
27+
_HINTS = ["FirstGA", "FirstBeta", "HoldOn", "OnTime", "ForCLI", TYPESPEC_LABEL]
2728

2829

2930
class IssueProcess:
@@ -67,6 +68,17 @@ def __init__(self, issue_package: IssuePackage, request_repo_dict: Dict[str, Rep
6768
self.is_open = True
6869
self.issue_title = issue_package.issue.title.split(": ", 1)[-1]
6970
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
7082

7183
@property
7284
def created_date_format(self) -> str:
@@ -199,8 +211,16 @@ def check_tag_consistency(self) -> None:
199211
f'it is still `{self.default_readme_tag}`, please modify the readme.md or your '
200212
f'**Readme Tag** above ')
201213

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+
202221
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()
204224
return
205225

206226
self.add_label(AUTO_PARSE_LABEL)
@@ -221,8 +241,9 @@ def auto_parse(self) -> None:
221241
self.edit_issue_body()
222242

223243
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)
226247

227248
def update_assignee(self, assignee_to_del: str, assignee_to_add: str) -> None:
228249
if assignee_to_del:
@@ -245,7 +266,7 @@ def auto_assign_policy(self) -> str:
245266
return assignees[random_idx]
246267

247268
def auto_assign(self) -> None:
248-
if AUTO_ASSIGN_LABEL in self.issue_package.labels_name:
269+
if self.has_label(AUTO_PARSE_LABEL):
249270
self.update_issue_instance()
250271
return
251272
# assign averagely
@@ -283,12 +304,12 @@ def new_comment_policy(self):
283304
self.bot_advice.append('new comment.')
284305

285306
def multi_link_policy(self):
286-
if MULTI_LINK_LABEL in self.issue_package.labels_name:
307+
if self.has_label(MULTI_LINK_LABEL):
287308
self.bot_advice.append('multi readme link!')
288309

289310
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.')
292313

293314
def remind_logic(self) -> bool:
294315
return abs(self.date_from_target) <= 2
@@ -298,14 +319,25 @@ def print_date_from_target_date(self) -> str:
298319

299320
def date_remind_policy(self):
300321
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)
302332

303333
def auto_bot_advice(self):
304334
self.new_issue_policy()
335+
self.typespec_policy()
305336
self.new_comment_policy()
306337
self.multi_link_policy()
307338
self.date_remind_policy()
308339
self.inconsistent_tag_policy()
340+
self.hint_policy()
309341

310342
def get_target_date(self):
311343
body = self.get_issue_body()
@@ -351,6 +383,10 @@ def __init__(self, issues_package: List[IssuePackage], language_owner: Set[str],
351383
for assignee in self.assignee_candidates:
352384
self.request_repo_dict[assignee] = Github(assignee_token).get_repo(REQUEST_REPO)
353385

386+
@staticmethod
387+
def for_test():
388+
return bool(os.getenv("TEST_ISSUE_NUMBER"))
389+
354390
def log_error(self, message: str) -> None:
355391
_LOG.error(message)
356392

scripts/release_helper/go.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@
77

88

99
class IssueProcessGo(IssueProcess):
10-
pass
10+
def __init__(self, *args, **kwargs):
11+
super().__init__(*args, **kwargs)
12+
self.language_name = 'go'
1113

1214

1315
class Go(Common):
1416
def __init__(self, issues, language_owner, sdk_assignees):
1517
super(Go, self).__init__(issues, language_owner, sdk_assignees)
16-
self.file_out_name = 'release_go_status.md'
18+
if not self.for_test():
19+
self.file_out_name = 'release_go_status.md'
1720

1821

1922
def go_process(issues: List[Any]) -> Go:

scripts/release_helper/java.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,21 @@
33

44
# assignee dict which will be assigned to handle issues
55
_JAVA_OWNER = {'azure-sdk'}
6-
_JS_ASSIGNEE = {'weidongxu-microsoft', 'haolingdong-msft', 'XiaofeiCao'}
6+
_JAVA_ASSIGNEE = {'weidongxu-microsoft', 'haolingdong-msft', 'XiaofeiCao', 'v-hongli1'}
77

88

99
class IssueProcessJava(IssueProcess):
10-
pass
10+
def __init__(self, *args, **kwargs):
11+
super().__init__(*args, **kwargs)
12+
self.language_name = 'java'
1113

1214

1315
class Java(Common):
1416
def __init__(self, issues, language_owner, sdk_assignees):
1517
super(Java, self).__init__(issues, language_owner, sdk_assignees)
16-
self.file_out_name = 'release_java_status.md'
18+
if not self.for_test():
19+
self.file_out_name = 'release_java_status.md'
1720

1821

1922
def java_process(issues: List[Any]) -> Java:
20-
return Java(issues, _JAVA_OWNER, _JS_ASSIGNEE)
23+
return Java(issues, _JAVA_OWNER, _JAVA_ASSIGNEE)

scripts/release_helper/js.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99

1010
class IssueProcessJs(IssueProcess):
11+
def __init__(self, *args, **kwargs):
12+
super().__init__(*args, **kwargs)
13+
self.language_name = 'js'
14+
1115
def auto_assign_policy(self) -> str:
1216
weeks = datetime.datetime.now().isocalendar()[1]
1317
assignees = list(self.assignee_candidates)
@@ -19,9 +23,9 @@ def auto_assign_policy(self) -> str:
1923
class Js(Common):
2024
def __init__(self, issues, language_owner, sdk_assignees):
2125
super(Js, self).__init__(issues, language_owner, sdk_assignees)
22-
self.file_out_name = 'release_js_status.md'
2326
self.issue_process_function = IssueProcessJs
24-
27+
if not self.for_test():
28+
self.file_out_name = 'release_js_status.md'
2529

2630
def js_process(issues: List[Any]) -> Js:
2731
return Js(issues, _JS_OWNER, _JS_ASSIGNEE)

scripts/release_helper/main.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ def collect_open_issues() -> List[IssuePackage]:
3939
hub = Github(os.getenv('AZURESDK_BOT_TOKEN'))
4040
request_repo = hub.get_repo(REQUEST_REPO)
4141
mgmt_label = request_repo.get_label('ManagementPlane')
42-
open_issues = request_repo.get_issues(state='open', labels=[mgmt_label])
42+
issue_number = os.getenv("TEST_ISSUE_NUMBER")
43+
if issue_number:
44+
open_issues = [request_repo.get_issue(int(issue_number))]
45+
else:
46+
open_issues = request_repo.get_issues(state='open', labels=[mgmt_label])
4347
rest_repo = hub.get_repo(REST_REPO)
4448
issues = [IssuePackage(issue, rest_repo) for issue in open_issues]
4549
_LOG.info(f'collect {len(issues)} open issues')

0 commit comments

Comments
 (0)