async def on_pull_request_review_requested(*, action, number, pull_request, requested_reviewer, **kwargs): """Someone requested a Pull Request Review, so we notify the Google Hangouts Chat Room.""" _LOGGER.debug( f"on_pull_request_review_requested: working on PR '{pull_request['title']}' {pull_request['html_url']}", ) # we do not notify on standard automated SrcOps if pull_request["title"].startswith("Automatic update of") or pull_request["title"].startswith("Release of"): return for requested_reviewer in pull_request["requested_reviewers"]: if send_notification(kwargs["repository"]["name"], pull_request["id"], requested_reviewer["login"]): _LOGGER.info(f"requesting review by {requested_reviewer['login']} on {pull_request['html_url']}") if requested_reviewer["login"] not in GITHUB_LOGIN_FILTER: notify_channel( "plain", f"π a review by " f"{hangouts_userid(requested_reviewer['login'])}" f" has been requested", f"pull_request_{kwargs['repository']['name']}_{pull_request['id']}", pull_request["html_url"], ) else: _LOGGER.info( f"did not send review notification, as {requested_reviewer['login']} is in GITHUB_LOGIN_FILTER", )
async def on_pull_request_review(*, action, review, pull_request, **kwargs): """React to Pull Request Review event.""" _LOGGER.debug(f"on_pull_request_review: working on PR {pull_request['html_url']}") notification_text = "" needs_rebase = await needs_rebase_label(pull_request) if needs_rebase: await merge_master_into_pullrequest2( pull_request["base"]["user"]["login"], pull_request["base"]["repo"]["name"], pull_request["id"], ) if review["state"] == "approved": notification_text = f"π '{realname(review['user']['login'])}' *approved* this Pull Request!" else: notification_text = f"π some new comment by '{realname(review['user']['login'])}' has arrived..." if realname(review["user"]["login"]) != "Sesheta": notify_channel( "plain", notification_text, f"pull_request_{kwargs['repository']['name']}_{pull_request['id']}", pull_request["html_url"], )
async def on_pr_open_or_edit(*, action, number, pull_request, repository, sender, organization, installation, **kwargs): """React to an opened or changed PR event. Send a status update to GitHub via Checks API. """ _LOGGER.debug( f"on_pr_open_or_edit: working on PR {pull_request['html_url']}") github_api = RUNTIME_CONTEXT.app_installation_client if action in ["opened", "reopened"]: # we do not notify on standard automated SrcOps if not pull_request["title"].startswith( "Automatic ") and not pull_request["title"].startswith( "Release of"): notify_channel( "plain", f"π {pull_request['html_url']} a new Pull Request has been *opened*!", f"pull_request_{repository['name']}_{pull_request['id']}", pull_request["html_url"], ) if (pull_request["title"].startswith("Automatic update of") or pull_request["title"].startswith("Release of version") or pull_request["title"].startswith( "Automatic dependency re-locking")): if pull_request["user"]["login"] not in [ "sesheta", "khebhut[bot]" ]: _LOGGER.error( f"on_pr_open_or_edit: automatic update not by Sesheta?! have a look at {pull_request['html_url']}!", ) _LOGGER.debug( f"on_pr_open_or_edit: automatic update, will auto-approve {pull_request['html_url']}!" ) # Let's approve the PR and put the approved label on it... try: await github_api.post( f"{pull_request['url']}/reviews", preview_api_version="symmetra", data={ "body": "This is an auto-approve of an auto-PR.", "event": "APPROVE" }, ) await github_api.post( f"{pull_request['issue_url']}/labels", preview_api_version="symmetra", data={"labels": ["approved"]}, ) except gidgethub.BadRequest as err: if err.status_code != 202: _LOGGER.error(str(err))
async def on_issue_opened(*, action, issue, repository, sender, **kwargs): """Take actions if an issue got opened.""" _LOGGER.info(f"working on Issue {issue['html_url']}: opened") if issue["title"].startswith("Automatic update of"): _LOGGER.debug( f"{issue['url']} is an 'Automatic update of dependencies', not sending notification" ) return if issue["title"].startswith("Automatic dependency re-locking"): _LOGGER.debug( f"{issue['url']} is an 'Automatic dependency re-locking', not sending notification" ) return if issue["title"].startswith("Initial dependency lock"): _LOGGER.debug( f"{issue['url']} is an 'Initial dependency lock', not sending notification" ) return if issue["title"].startswith("Failed to update dependencies"): _LOGGER.debug( f"{issue['url']} is an 'Failed to update dependencies', not sending notification" ) return # only of the ml-prague-workshop feb26-2021 if issue["title"].startswith("Workshop issue ML Prague"): github_api = RUNTIME_CONTEXT.app_installation_client await github_api.post( f"{issue['url']}/assignees", preview_api_version="symmetra", data={"assignees": ["vpavlin", "pacospace", "tumido"]}, ) if issue["title"].startswith("Release of version"): _LOGGER.debug(f"{issue['url']} is a 'release issue'") github_api = RUNTIME_CONTEXT.app_installation_client await github_api.post( f"{issue['url']}/labels", preview_api_version="symmetra", data={"labels": ["bot"]}, ) notify_channel( "plain", f"{realname(issue['user']['login'])} just opened an issue: *{issue['title']}*... π¨ " f"check {issue['html_url']} for details", f"issue_{repository['name']}_{issue['id']}", issue["html_url"], )
async def on_check_gate(*, action, issue, comment, repository, organization, sender, installation): """Determine if a 'check' gate was passed and the Pull Request is ready for review. If the Pull Request is ready for review, assign a set of reviewers. """ _LOGGER.debug(f"looking for a passed 'check' gate: {issue['url']}") if comment["body"].startswith("Build succeeded."): _LOGGER.debug(f"local/check status might have changed...") pr_url = issue["url"].replace("issues", "pulls") pr_body_ok = False github_api = RUNTIME_CONTEXT.app_installation_client pr = await github_api.getitem(pr_url) do_not_merge_label = await do_not_merge(pr_url) gate_passed = await local_check_gate_passed(pr_url) reviewer_list = await conclude_reviewer_list( pr["base"]["repo"]["owner"]["login"], pr["base"]["repo"]["name"]) current_reviewers = pr["requested_reviewers"] pr_owner = pr["user"]["login"] # TODO check if PR body is ok # TODO check for size label _LOGGER.debug( f"gate passed: {gate_passed}, do_not_merge_label: {do_not_merge_label}, body_ok: {pr_body_ok}" ) if gate_passed and not do_not_merge_label: _LOGGER.debug(f"PR {pr['html_url']} is ready for review!") # we do not notify on standard automated SrcOps if not pr["title"].startswith("Automatic update of dependency" ) and not pr["title"].startswith( "Release of", ): notify_channel( "plain", f"π This Pull Request seems to be *ready for review*... the local/check gate has been passed! π", f"pull_request_{repository['name']}_{pr['id']}", "thoth-station", ) if reviewer_list is not None: _LOGGER.debug( f"PR {pr['html_url']} could be reviewed by {unpack(reviewer_list)}" ) elif not gate_passed and not len(current_reviewers) == 0: # if a review has been started we should not remove the reviewers _LOGGER.debug( f"PR {pr['html_url']} is NOT ready for review! Removing reviewers: {unpack(current_reviewers)}", )
async def on_pr_open_or_edit(*, action, number, pull_request, repository, sender, organization, installation, **kwargs): """React to an opened or changed PR event. Send a status update to GitHub via Checks API. """ _LOGGER.debug(f"on_pr_open_or_edit: working on PR {pull_request['html_url']}") github_api = RUNTIME_CONTEXT.app_installation_client if action in ["opened", "reopened"]: # we do not notify on standard automated SrcOps if not pull_request["title"].startswith("Automatic ") and not pull_request["title"].startswith("Release of"): notify_channel( "plain", f"π {pull_request['html_url']} a new Pull Request has been *opened*!", f"pull_request_{repository['name']}_{pull_request['id']}", pull_request["html_url"], ) if ( pull_request["title"].startswith("Automatic update of") or pull_request["title"].startswith("Release of version") or pull_request["title"].startswith("Automatic dependency re-locking") ): if pull_request["user"]["login"] not in ["sesheta", "khebhut[bot]"]: _LOGGER.error( f"on_pr_open_or_edit: automatic update not by Sesheta?! have a look at {pull_request['html_url']}!", ) _LOGGER.debug(f"on_pr_open_or_edit: automatic update, will auto-approve {pull_request['html_url']}!") if pull_request["user"]["login"] == "thoth-station": # Let's approve the PR and put the approved label on it... # Set ok-to-test for the automatic PR's as we trust khebhut and sesheta try: await github_api.post( f"{pull_request['comments_url']}", preview_api_version="symmetra", data={"body": "This auto-PR is allowed to be tested.\n\n/ok-to-test\n/approve"}, ) except gidgethub.BadRequest as err: if err.status_code != 202: _LOGGER.error(str(err)) else: # Don't approve for the other users , until they explicitly ask for turning on this feature. _LOGGER.info(f"on_pr_open_or_edit: This PR is {pull_request['html_url']} not a part of thoth-station.")
async def on_security_advisory(*, action, security_advisory, **kwargs): """Send a notification to Hangout.""" _LOGGER.warning( f"New information wrt GitHub security advisory {security_advisory['ghsa_id']} '{security_advisory['summary']}'", ) ecosystem_name = security_advisory["vulnerabilities"]["package"]["ecosystem"] references_url = security_advisory["references"]["url"] notify_channel( "plain", f"π π GitHub issued some information on security advisory {security_advisory['ghsa_id']}, " f"it is related to {ecosystem_name} ecosystem: " f"{security_advisory['description']}" f" see also: {references_url}", f"{security_advisory['ghsa_id']}", "thoth-station", )
async def on_pr_open_or_edit(*, action, number, pull_request, repository, sender, organization, installation, **kwargs): """React to an opened or changed PR event. Send a status update to GitHub via Checks API. """ _LOGGER.debug( f"on_pr_open_or_edit: working on PR {pull_request['html_url']}") github_api = RUNTIME_CONTEXT.app_installation_client if action in ["opened", "reopened"]: # we do not notify on standard automated SrcOps if not pull_request["title"].startswith( "Automatic ") and not pull_request["title"].startswith( "Release of"): notify_channel( "plain", f"π {pull_request['html_url']} a new Pull Request has been *opened*!", f"pull_request_{repository['name']}_{pull_request['id']}", pull_request["html_url"], ) try: await manage_label_and_check(github_api, pull_request) await needs_rebase_label(pull_request) await needs_size_label(pull_request) except gidgethub.BadRequest as err: _LOGGER.error( f"manage labels and checks: status_code={err.status_code}, {str(err)}" ) try: await merge_master_into_pullrequest2( pull_request["base"]["user"]["login"], pull_request["base"]["repo"]["name"], pull_request["id"], ) except gidgethub.BadRequest as err: _LOGGER.warning( f"merge_master_into_pullrequest2: status_code={err.status_code}, {str(err)}, {pull_request['html_url']}", )
async def on_pr_closed(*, action, number, pull_request, repository, sender, organization, installation, **kwargs): """React to an closed PR event.""" _LOGGER.debug(f"on_pr_closed: working on PR {pull_request['html_url']}") # we do not notify on standard automated SrcOps ignore_messages = ["Automatic update of dependency", "Release of", "Automatic dependency re-locking"] if not pull_request["title"].startswith(tuple(ignore_messages)): if pull_request["merged"]: notify_channel( "plain", f"π Pull Request *{pull_request['title']}* has been merged by '{realname(sender['login'])}' π»", f"pull_request_{repository['name']}_{pull_request['id']}", pull_request["html_url"], ) else: notify_channel( "plain", f"π Pull Request *{pull_request['title']}* has been *closed* with *unmerged commits*! π§", f"pull_request_{repository['name']}_{pull_request['id']}", pull_request["html_url"], ) elif pull_request["title"].startswith("Release of"): commit_hash, release = await handle_release_pull_request(pull_request) notify_channel( "plain", f" I have tagged {commit_hash} to be release {release} of" f" {pull_request['base']['repo']['full_name']} " + random_positive_emoji2(), f"pull_request_{repository['name']}", pull_request["url"], )
async def on_pr_open_or_edit(*, action, number, pull_request, repository, sender, organization, installation, **kwargs): """React to an opened or changed PR event. Send a status update to GitHub via Checks API. """ _LOGGER.debug(f"on_pr_open_or_edit: working on PR {pull_request['html_url']}") github_api = RUNTIME_CONTEXT.app_installation_client if action in ["opened", "reopened"]: # we do not notify on standard automated SrcOps if not pull_request["title"].startswith("Automatic ") and not pull_request["title"].startswith("Release of"): notify_channel( "plain", f"π {pull_request['html_url']} a new Pull Request has been *opened*!", f"pull_request_{repository['name']}_{pull_request['id']}", pull_request["html_url"], ) # Auto comments and labels added for Release version PR's if pull_request["title"].startswith("Release of version"): if pull_request["user"]["login"] not in ["sesheta", "khebhut[bot]"]: _LOGGER.error( f"on_pr_open_or_edit: automatic update not by Sesheta?! have a look at {pull_request['html_url']}!", ) _LOGGER.debug(f"on_pr_open_or_edit: automatic update, will auto-approve {pull_request['html_url']}!") if pull_request["base"]["user"]["login"] in ["thoth-station", "opendatahub-io"]: # Let's approve the PR and put the approved label on it... # Set ok-to-test for the automatic PR's as we trust khebhut and sesheta try: await github_api.post( f"{pull_request['url']}/reviews", preview_api_version="symmetra", data={"body": "This is an auto-approve of the releases.", "event": "APPROVE"}, ) await github_api.post( f"{pull_request['issue_url']}/labels", preview_api_version="symmetra", data={"labels": ["approved", "ok-to-test"]}, ) except gidgethub.BadRequest as err: if err.status_code != 202: _LOGGER.error(str(err)) else: # Don't approve for the other users, until they explicitly ask for turning on this feature. _LOGGER.info(f"on_pr_open_or_edit: This PR is {pull_request['html_url']} not a part of thoth-station.") # Auto comments and labels added for Package update PR's if pull_request["title"].startswith("Automatic update of") or pull_request["title"].startswith( "Automatic dependency re-locking", ): if pull_request["user"]["login"] not in ["sesheta", "khebhut[bot]"]: _LOGGER.error( f"on_pr_open_or_edit: automatic update not by Sesheta?! have a look at {pull_request['html_url']}!", ) _LOGGER.debug(f"on_pr_open_or_edit: automatic update, will auto-approve {pull_request['html_url']}!") if pull_request["base"]["user"]["login"] == "thoth-station": # Let's approve the PR and put the approved label on it... # Set ok-to-test for the automatic PR's as we trust khebhut and sesheta try: await github_api.post( f"{pull_request['url']}/reviews", preview_api_version="symmetra", data={"body": "This is an auto-approve of an auto-PR.", "event": "APPROVE"}, ) await github_api.post( f"{pull_request['issue_url']}/labels", preview_api_version="symmetra", data={"labels": ["approved", "ok-to-test"]}, ) except gidgethub.BadRequest as err: if err.status_code != 202: _LOGGER.error(str(err)) else: # Don't approve for the other users, until they explicitly ask for turning on this feature. _LOGGER.info(f"on_pr_open_or_edit: This PR is {pull_request['html_url']} not a part of thoth-station.") if pull_request["title"].lower().startswith("bump version of") and pull_request["title"].lower().endswith( "stage", ): _LOGGER.debug(f"on_pr_open_or_edit: {pull_request['html_url']} is a version bump in STAGE") notify_channel( "plain", f"π {pull_request['html_url']} is bumping a version in STAGE, please check if the new tag is available on quay", f"pull_request_{repository['name']}", pull_request["html_url"], )