def check_news(event, gh, *args, **kwargs):
pr_number = event.data['number']
pull_request = event.data['pull_request']
# For some unknown reason there isn't any files URL in a pull request
# payload.
files_url = f'/repos/python/cpython/pulls/{pr_number}/files'
# Could have collected all the filenames in an async set comprehension,
# but doing it this way potentially minimizes the number of API calls.
in_next_dir = file_found = False
async for file_data in gh.getiter(files_url):
filename = file_data['filename']
if not filename.startswith(NEWS_NEXT_DIR):
continue
in_next_dir = True
file_path = pathlib.PurePath(filename)
if len(file_path.parts) != 5: # Misc, NEWS.d, next, <subsection>, <entry>
continue
file_found = True
if FILENAME_RE.match(file_path.name):
status = create_status(util.StatusState.SUCCESS,
description='News entry found in Misc/NEWS.d')
break
else:
issue = await util.issue_for_PR(gh, pull_request)
if util.skip("news", issue):
status = SKIP_LABEL_STATUS
else:
if not in_next_dir:
description = f'No news entry in {NEWS_NEXT_DIR} or "skip news" label found'
elif not file_found:
description = "News entry not in an appropriate directory"
else:
description = "News entry file name incorrectly formatted"
status = create_status(util.StatusState.FAILURE,
description=description,
target_url=DEVGUIDE_URL)
await gh.post(pull_request['statuses_url'], data=status)
评论列表
文章目录