Skip to content

Commit 55526df

Browse files
BigCat20196RAY-316msyyc
authored
[auto-issue-status]auto-assign and refactor (#20722)
* release_iseus_status_auto_reply * issue_aoto_close_revert * Update main.py * Update main.py * Update update_issue_body.py * Update reply_generator.py * Update reply_generator.py * Update update_issue_body.py * Update main.py * Update update_issue_body.py * Update update_issue_body.py * Update main.py * Update reply_generator.py * Update main.py * Update update_issue_body.py * Update main.py * Update scripts/release_issue_status/update_issue_body.py * Update update_issue_body.py * Update main.py * Update reply_generator.py * Update update_issue_body.py * Update main.py * Update scripts/release_issue_status/main.py * Update main.py * Update scripts/release_issue_status/main.py * Update scripts/release_issue_status/main.py * Update scripts/release_issue_status/main.py * Update scripts/release_issue_status/update_issue_body.py * Update scripts/release_issue_status/main.py * Update scripts/release_issue_status/update_issue_body.py * Update reply_generator.py * Update main.py * Update scripts/release_issue_status/update_issue_body.py Co-authored-by: msyyc <[email protected]> * Update scripts/release_issue_status/update_issue_body.py Co-authored-by: msyyc <[email protected]> * Update reply_generator.py * Update update_issue_body.py * Update main.py * Update main.py * Update update_issue_body.py * Update main.py * Update scripts/release_issue_status/main.py * Update main.py * Update reply_generator.py * Update main.py * Update main.py * Update main.py * Update main.py * Update main.py * Update main.py * Update main.py * Update main.py * Update main.py * Update update_issue_body.py * Update main.py * Update update_issue_body.py * Update reply_generator.py * Update update_issue_body.py * Update main.py * Update update_issue_body.py * Update update_issue_body.py * Update update_issue_body.py * Update update_issue_body.py * Update update_issue_body.py * Update main.py * Update main.py * Update release_issue_status.yml for Azure Pipelines * Update main.py * Update reply_generator.py * Add files via upload * Update reply_generator.py * Update update_issue_body.py * Update reply_generator.py * Update auto_pipeline_run.py * Update auto_pipeline_run.py * add auto-close * Update release_issue_status.yml for Azure Pipelines * Update auto_close.py * Update main.py * Update release_issue_status.yml for Azure Pipelines * Update auto_pipeline_run.py * fix bug * Update main.py * Update auto_close.py * Update auto_close.py * Update main.py * Update reply_generator.py * Update main.py * Update main.py * Update auto_close.py * Update main.py * Update auto-close * Update auto_pipeline_run.py * Update update_issue_body.py * Update auto_pipeline_run.py * Update release_issue_status.yml for Azure Pipelines * Update auto_pipeline_run.py * Update release_issue_status.yml for Azure Pipelines * Update auto_pipeline_run.py * Update auto_pipeline_run.py * Add pipeline link * Update pipeline link * Update auto_pipeline_run.py * Update release_issue_status.yml for Azure Pipelines * Update auto_pipeline_run.py * Update requirement.txt * Update auto_pipeline_run.py * Add get_python_pipeline * Update auto_pipeline_run.py * test * test * add outputfolder * add label * Update main.py * Update get_python_pipeline.py * Update main.py * Update auto_pipeline_run.py * Add utils * Update main.py * Update main.py * Delete old py * Update reply_generator.py * Update main.py * Update main.py * Update main.py * Update main.py * Update main.py * Update utils.py * Update utils.py * Update main.py * Update main.py * Update reply_generator.py * Update utils.py * Add get_changelog function * Update utils.py * Update reply_generator.py * Update main.py * Update reply_generator.py * Update function * del useless code * Update utils.py * Update main.py * Update reply_generator.py * Update main.py * Update utils.py * Update utils.py * Update utils.py * Update utils.py * Update reply_generator.py * Update main.py * Update main.py * Update main.py * Update release_issue_status.yml for Azure Pipelines * Update main.py * Update release_issue_status.yml for Azure Pipelines * Update release_issue_status.yml for Azure Pipelines * Update main.py * Update utils.py Co-authored-by: Zed <[email protected]> Co-authored-by: Zed Lei <[email protected]> Co-authored-by: msyyc <[email protected]>
1 parent 6bba532 commit 55526df

File tree

8 files changed

+279
-303
lines changed

8 files changed

+279
-303
lines changed

scripts/release_issue_status/auto_close.py

Lines changed: 0 additions & 36 deletions
This file was deleted.

scripts/release_issue_status/auto_pipeline_run.py

Lines changed: 0 additions & 47 deletions
This file was deleted.

scripts/release_issue_status/get_python_pipeline.py

Lines changed: 0 additions & 27 deletions
This file was deleted.

scripts/release_issue_status/main.py

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,22 @@
44
from datetime import date, datetime
55
import subprocess as sp
66
import traceback
7+
import logging
78

89
from github import Github
910
from azure.storage.blob import BlobClient
1011

1112
import reply_generator as rg
12-
from update_issue_body import update_issue_body, find_readme_and_output_folder
13-
from auto_close import auto_close_issue
14-
from get_python_pipeline import get_python_pipelines, get_pipeline_url
13+
from utils import update_issue_body, get_readme_and_output_folder, \
14+
get_python_pipelines, get_pipeline_url, auto_close_issue
1515

1616

1717
_NULL = ' '
1818
_FILE_OUT = 'release_issue_status.csv'
1919
_FILE_OUT_PYTHON = 'release_python_status.md'
2020
_PYTHON_SDK_ADMINISTRATORS = {'msyyc', 'RAY-316', 'BigCat20196'}
21+
logging.basicConfig(level=logging.INFO,
22+
format='[auto-reply log] - %(funcName)s[line:%(lineno)d] - %(levelname)s: %(message)s')
2123

2224
def my_print(cmd):
2325
print('==' + cmd + ' ==\n')
@@ -127,46 +129,42 @@ def _latest_comment_time(comments, delay_from_create_date):
127129

128130

129131
def auto_reply(item, request_repo, rest_repo, sdk_repo, duplicated_issue, python_piplines):
130-
print("==========new issue number: {}".format(item.issue_object.number))
131-
if 'Configured' in item.labels:
132-
item.labels.remove('Configured')
132+
logging.info("new issue number: {}".format(item.issue_object.number))
133133

134134
if 'auto-link' not in item.labels:
135-
item.labels.append('auto-link')
136-
item.issue_object.set_labels(*item.labels)
135+
item.issue_object.add_to_labels('auto-link')
137136
try:
138137
package_name, readme_link, output_folder = update_issue_body(request_repo, rest_repo, item.issue_object.number)
139-
print("pkname, readme", package_name, readme_link)
138+
logging.info("pkname, readme", package_name, readme_link)
140139
item.package = package_name
141140
key = ('Python', item.package)
142141
duplicated_issue[key] = duplicated_issue.get(key, 0) + 1
143142
except Exception as e:
144143
item.bot_advice = 'failed to modify the body of the new issue. Please modify manually'
145-
item.labels.append('attention')
146-
item.issue_object.set_labels(*item.labels)
147-
print(e)
144+
item.issue_object.add_to_labels('attention')
145+
logging.info(e)
148146
raise
149147
else:
150148
try:
151-
readme_link, output_folder = find_readme_and_output_folder(request_repo, rest_repo, item.issue_object.number)
149+
readme_link, output_folder = get_readme_and_output_folder(request_repo, rest_repo, item.issue_object.number)
152150
except Exception as e:
153-
print('Issue: {} updates body failed'.format(item.issue_object.number))
154-
item.bot_advice = 'failed to find Readme link, Please check !!'
155-
item.labels.append('attention')
156-
item.issue_object.set_labels(*item.labels)
151+
logging.info('Issue: {} get pkname and output folder failed'.format(item.issue_object.number))
152+
item.bot_advice = 'failed to find Readme link and output folder. Please check !!'
153+
item.issue_object.add_to_labels('attention')
154+
logging.info(e)
157155
raise
158156
try:
159-
print("*********************")
160-
print(python_piplines)
157+
logging.info(python_piplines)
161158
pipeline_url = get_pipeline_url(python_piplines, output_folder)
162159
rg.begin_reply_generate(item=item, rest_repo=rest_repo, readme_link=readme_link,
163160
sdk_repo=sdk_repo, pipeline_url=pipeline_url)
161+
if 'Configured' in item.labels:
162+
item.issue_object.remove_from_labels('Configured')
164163
except Exception as e:
165164
item.bot_advice = 'auto reply failed, Please intervene manually !!'
166-
print('Error from auto reply ========================')
167-
print('Issue:{}'.format(item.issue_object.number))
168-
print(traceback.format_exc())
169-
print('==============================================')
165+
logging.info('Error from auto reply')
166+
logging.info('Issue:{}'.format(item.issue_object.number))
167+
logging.info(traceback.format_exc())
170168

171169

172170
def main():
@@ -220,10 +218,19 @@ def main():
220218
# rule6: if delay from created date is over 30 days and owner never reply, close it.
221219
# rule7: if delay from created date is over 15 days and owner never reply, remind owner to handle it.
222220
for item in issue_status:
221+
if item.language == 'Python':
222+
issue_status_python.append(item)
223223
if item.status == 'release':
224224
item.bot_advice = 'better to release asap.'
225225
elif (item.comment_num == 0 or 'Configured' in item.labels) and 'Python' in item.labels:
226226
item.bot_advice = 'new issue and better to confirm quickly.'
227+
if 'assigned' not in item.labels:
228+
time.sleep(0.1)
229+
assign_count = int(str(time.time())[-1]) % 2
230+
if assign_count == 1:
231+
item.issue_object.remove_from_assignees(*['RAY-316'])
232+
item.issue_object.add_to_assignees(*['BigCat20196'])
233+
item.issue_object.add_to_labels('assigned')
227234
try:
228235
auto_reply(item, request_repo, rest_repo, sdk_repo, duplicated_issue, python_piplines)
229236
except Exception as e:
@@ -237,25 +244,20 @@ def main():
237244
auto_close_issue(request_repo, item)
238245
except Exception as e:
239246
item.bot_advice = 'auto-close failed, please check!'
240-
print(f"=====issue: {item.issue_object.number}, {e}")
247+
logging.info(f"=====issue: {item.issue_object.number}, {e}")
241248

242249
if item.days_from_latest_commit >= 30 and item.language == 'Python' and '30days attention' not in item.labels:
243-
item.labels.append('30days attention')
244-
item.issue_object.set_labels(*item.labels)
250+
item.issue_object.add_to_labels('30days attention')
245251
item.issue_object.create_comment(f'hi @{item.author}, the issue is closed since there is no reply for a long time. Please reopen it if necessary or create new one.')
246252
item.issue_object.edit(state='close')
247253
elif item.days_from_latest_commit >= 15 and item.language == 'Python' and '15days attention' not in item.labels:
248254
item.issue_object.create_comment(f'hi @{item.author}, this release-request has been delayed more than 15 days,'
249255
' please deal with it ASAP. We will close the issue if there is still no response after 15 days!')
250-
item.labels.append('15days attention')
251-
item.issue_object.set_labels(*item.labels)
256+
item.issue_object.add_to_labels('15days attention')
252257

253258
# judge whether there is duplicated issue for same package
254259
if item.package != _NULL and duplicated_issue.get((item.language, item.package)) > 1:
255260
item.bot_advice = f'Warning:There is duplicated issue for {item.package}. ' + item.bot_advice
256-
257-
if item.language == 'Python':
258-
issue_status_python.append(item)
259261

260262
# output result
261263
output_python_md(issue_status_python)

scripts/release_issue_status/release_issue_status.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ jobs:
3838
export TOKEN=$(USR_TOKEN)
3939
export HEADERS=$(PIPELINE_HEADERS)
4040
export URL=$(PIPELINE_URL)
41-
export PIPELINE_TOKEN = $(PIPELINE_TOKEN)
41+
export PIPELINE_TOKEN=$(USR_PIPELINE_TOKEN)
42+
export COOKIE=$(USR_TOKEN)
4243
4344
# create virtual env
4445
python -m venv venv-sdk
Lines changed: 31 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
import auto_pipeline_run as apr
1+
from utils import run_pipeline
22
import re
3+
import logging
34

45
issue_object_rg = None
6+
logging.basicConfig(level=logging.INFO,
7+
format='[auto-reply log] - %(funcName)s[line:%(lineno)d] - %(levelname)s: %(message)s')
58

69

7-
def weather_change_readme(rest_repo, link_dict, labels):
10+
def readme_comparison(rest_repo, link_dict, labels):
811
# to see whether need change readme
912
contents = str(rest_repo.get_contents(link_dict['readme_path']).decoded_content)
1013
pattern_tag = re.compile(r'tag: package-[\w+-.]+')
@@ -13,6 +16,8 @@ def weather_change_readme(rest_repo, link_dict, labels):
1316
whether_multi_api = 'multi-api' in readme_python_contents
1417
whether_same_tag = link_dict['readme_tag'] in package_tag
1518
whether_change_readme = not whether_same_tag or whether_multi_api and not 'MultiAPI' in labels
19+
if 'Configured' in labels:
20+
whether_change_readme = False
1621
return whether_change_readme
1722

1823

@@ -47,76 +52,46 @@ def get_latest_pr_from_readme(rest_repo, link_dict):
4752
return latest_pr_number_int[-1]
4853

4954

50-
def latest_pr_parse(rest_repo, latest_pr_number):
51-
latest_pr = rest_repo.get_issue(latest_pr_number)
52-
latest_pr_comments = latest_pr.get_comments()
53-
b = [i for i in latest_pr_comments]
54-
for comment in latest_pr_comments:
55-
if '<h3>Swagger Generation Artifacts</h3>' in comment.body:
56-
return swagger_generator_parse(comment.body, latest_pr_number)
57-
58-
59-
def swagger_generator_parse(context, latest_pr_number):
60-
track1_info_model = ''
61-
try:
62-
if '<b> azure-sdk-for-python</b>' in context:
63-
pattern_python_t1 = re.compile('<b> azure-sdk-for-python</b>.+?</details>', re.DOTALL)
64-
python_t1 = re.search(pattern_python_t1, context).group()
65-
prttern_python_track1 = re.compile('<ul>\s+?<li>\s+?<a.+</ul>', re.DOTALL)
66-
python_track1_info = re.search(prttern_python_track1, python_t1).group()
67-
track1_info_model = '<details open><summary><b> python-track1</b></summary>{} </details>'.format(
68-
python_track1_info)
69-
except Exception as e:
70-
print('track1 generate error')
71-
pattern_python = re.compile('<b> azure-sdk-for-python-track2</b>.+?</details>', re.DOTALL)
72-
python = re.search(pattern_python, context).group()
73-
# the way that reply not contains [Release SDK Changes]
74-
# pattern_python_track2 = re.compile('<ul>\s*?<li>\s*?<a.*</ul>', re.DOTALL)
75-
pattern_python_track2 = re.compile('<b>track2_.*</ul>', re.DOTALL)
76-
python_track2_info = re.search(pattern_python_track2, python).group()
77-
track2_info_model = '<details open><summary><b> python-track2</b></summary>{} </details>'.format(
78-
python_track2_info)
79-
pattern_sdk_changes = re.compile('/azure-sdk-for-python/pull/\d*">Release SDK Changes</a>', re.DOTALL)
80-
sdk_link = re.search(pattern_sdk_changes, python_track2_info).group()
81-
sdk_link_number = re.search(re.compile('[0-9]+'), sdk_link).group()
82-
info_model = 'hi @{} Please check the package whether works well and the changelog info is as below:\n' \
83-
'{}\n{}\n' \
84-
'\n* (The version of the package is only a temporary version for testing)\n' \
85-
'\nhttps://github.com/Azure/azure-rest-api-specs/pull/{}\n' \
86-
.format(issue_object_rg.user.login, track1_info_model, track2_info_model, str(latest_pr_number))
87-
88-
return info_model, sdk_link_number
89-
90-
9155
def reply_owner(reply_content):
9256
issue_object_rg.create_comment(reply_content)
9357

9458

95-
def add_label(label_name, labels):
96-
if label_name not in labels:
97-
labels.append(label_name)
98-
issue_object_rg.set_labels(*labels)
59+
60+
def get_reply_and_sdk_number_from_readme(rest_repo, link_dict):
61+
commits = rest_repo.get_commits(path=link_dict['resource_manager'])
62+
latest_commit = commits[0]
63+
check_run_id = latest_commit.get_check_runs(check_name='SDK azure-sdk-for-python-track2')[0].id
64+
latest_pr_number = latest_commit.get_pulls()[0].number
65+
details = rest_repo.get_check_run(check_run_id).output.text
66+
sdk_link_number = re.findall(r'/azure-sdk-for-python/pull/(\d*)">Release SDK Changes</a>', details)[0]
67+
changelog = '<details open><summary><b> python-track2</b></summary> track2_azure-mgmt-{} </details>'.format(
68+
details.split('</code><b>track2_azure-mgmt-')[-1])
69+
info_model = 'hi @{} Please check the package whether works well and the changelog info ' \
70+
'is as below:\n{}\n' \
71+
'\n* (The version of the package is only a temporary version for testing)\n' \
72+
'\nhttps://github.com/Azure/azure-rest-api-specs/pull/{}\n' \
73+
.format(issue_object_rg.user.login, changelog, str(latest_pr_number))
74+
return info_model, sdk_link_number
9975

10076

10177
def begin_reply_generate(item, rest_repo, readme_link, sdk_repo, pipeline_url):
10278
global issue_object_rg
10379
issue_object_rg = item.issue_object
10480
link_dict = get_links(readme_link)
10581
labels = item.labels
106-
whether_change_readme = weather_change_readme(rest_repo, link_dict, labels)
82+
whether_change_readme = readme_comparison(rest_repo, link_dict, labels)
10783

10884
if not whether_change_readme:
109-
latest_pr_number = get_latest_pr_from_readme(rest_repo, link_dict)
110-
reply_content, sdk_link_number = latest_pr_parse(rest_repo, latest_pr_number)
111-
run_pipeline = apr.run_pipeline(issue_link=issue_object_rg.html_url,
85+
reply_content, sdk_link_number = get_reply_and_sdk_number_from_readme(rest_repo, link_dict)
86+
res_run = run_pipeline(issue_link=issue_object_rg.html_url,
11287
sdk_issue_object=sdk_repo.get_pull(int(sdk_link_number)),
11388
pipeline_url=pipeline_url
11489
)
115-
if run_pipeline:
116-
print(f'{issue_object_rg.number} run pipeline successfully')
90+
if res_run:
91+
logging.info(f'{issue_object_rg.number} run pipeline successfully')
11792
else:
118-
print(f'{issue_object_rg.number} run pipeline fail')
93+
logging.info(f'{issue_object_rg.number} run pipeline fail')
11994
reply_owner(reply_content)
120-
add_label('auto-ask-check', labels)
95+
issue_object_rg.add_to_labels('auto-ask-check')
12196
else:
122-
print('issue {} need config readme***********'.format(issue_object_rg.number))
97+
logging.info('issue {} need config readme'.format(issue_object_rg.number))

0 commit comments

Comments
 (0)