From bba1184aa11214feaabf2e79717a9d276f12ad5c Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Sat, 21 Aug 2021 00:18:20 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Skip=20check=20on=20`bot:chronograp?= =?UTF-8?q?her:skip`=20label?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ref: https://github.com/sanitizers/chronographer-github-app/issues/12 --- chronographer/event_handlers.py | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/chronographer/event_handlers.py b/chronographer/event_handlers.py index 076dd89..ade2f85 100644 --- a/chronographer/event_handlers.py +++ b/chronographer/event_handlers.py @@ -21,6 +21,7 @@ ) from .labels import ( LABEL_PROVIDED, + LABEL_SKIP, ) try: @@ -108,6 +109,7 @@ async def on_pr(event): event.data['check_suite']['pull_requests'][0] ) pr_author = pull_request['user'] + pr_labels = {label['name'] for label in pull_request['labels']} diff_url = ( f'https://github.com/{repo_slug}' f'/pull/{pull_request["number"]:d}.diff' @@ -117,6 +119,39 @@ async def on_pr(event): gh_api = RUNTIME_CONTEXT.app_installation_client + if LABEL_SKIP in pr_labels: + logger.info( + 'Skipping PR event because the `%s` label is present', + LABEL_SKIP, + ) + await gh_api.post( + check_runs_base_uri, + preview_api_version='antiope', + data=to_gh_query(NewCheckRequest( + head_branch, head_sha, + name='Timeline protection', + status='completed', + started_at=f'{datetime.utcnow().isoformat()}Z', + completed_at=f'{datetime.utcnow().isoformat()}Z', + conclusion='neutral', + output={ + 'title': + 'Timeline protection: ' + 'Nothing to do — change note not required', + 'text': f'Labels: {", ".join(pr_labels)}', + 'summary': + 'Heeeeey!' + '\n\n' + f'This PR has the `{LABEL_SKIP}` label meaning that ' + 'the maintainers do not expect a change note in this ' + 'pull request but you are still welcome to add one if ' + 'you feel like it may be useful in the ' + 'user-facing 📝 changelog.', + }, + )), + ) + return # Interrupt the webhook event processing + repo_config = await get_chronographer_config(ref=head_sha) if is_blacklisted(pr_author, repo_config.get('exclude', {})): logger.info(