def process_pull_requests(repository, installation):
now = time.time()
# Get issues labeled as 'Close?'
repo = RepoHandler(repository, 'master', installation)
pull_requests = repo.open_pull_requests()
# User config
enable_autoclose = repo.get_config_value(
'autoclose_stale_pull_request', True)
for n in pull_requests:
print(f'Checking {n}')
pr = PullRequestHandler(repository, n, installation)
if 'keep-open' in pr.labels:
print('-> PROTECTED by label, skipping')
continue
commit_time = pr.last_commit_date
dt = now - commit_time
if current_app.stale_pull_requests_close and dt > current_app.stale_pull_requests_close_seconds:
comment_ids = pr.find_comments('astropy-bot[bot]', filter_keep=is_close_epilogue)
if not enable_autoclose:
print(f'-> Skipping issue {n} (auto-close disabled)')
elif len(comment_ids) == 0:
print(f'-> CLOSING issue {n}')
pr.submit_comment(PULL_REQUESTS_CLOSE_EPILOGUE)
pr.close()
else:
print(f'-> Skipping issue {n} (already closed)')
elif dt > current_app.stale_pull_requests_warn_seconds:
comment_ids = pr.find_comments('astropy-bot[bot]', filter_keep=is_close_warning)
if len(comment_ids) == 0:
print(f'-> WARNING issue {n}')
pr.submit_comment(PULL_REQUESTS_CLOSE_WARNING.format(pasttime=naturaldelta(dt),
futuretime=naturaldelta(current_app.stale_pull_requests_close_seconds - current_app.stale_pull_requests_warn_seconds)))
else:
print(f'-> Skipping issue {n} (already warned)')
else:
print(f'-> OK issue {n}')
评论列表
文章目录