Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A very quick implementation of fail on labels #91

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions baldrick/plugins/github_block_labels.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from loguru import logger
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol, best package name :)


from baldrick.plugins.github_pull_requests import pull_request_handler

BLOCKED_MESSAGE = 'This pull request is blocked from being merged by labels.'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we have the name of the label, that triggered this, listed, too?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or all of them that triggers this in a repo? (I don't expect all maintainers to always know about this feature)

MERGEABLE_MESSAGE = 'This pull request is not blocked from being merged by labels.'

@pull_request_handler
def fail_check_labels(pr_handler, repo_handler):
"""
Set a failing status if any labels in the config are set
"""
bl_config = pr_handler.get_config_value("fail_check_labels", {})
if not bl_config.get('enabled', False):
logger.debug("Skipping fail label check plugin as disabled in config")
return

logger.debug(f"Checking for blocking labels on {pr_handler.repo}#{pr_handler.number}")

fail_message = bl_config.get("label_present_message", BLOCKED_MESSAGE)
pass_message = bl_config.get("label_absent_message", MERGEABLE_MESSAGE)

pr_labels = set(pr_handler.labels)
blocking_labels = set(cl_config.get('labels', [])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
blocking_labels = set(cl_config.get('labels', [])
blocking_labels = set(cl_config.get('blocking_labels', [])

to remove ambiguity


if pr_labels.intersection(blocking_labels):
return {'blocking_labels': {
'title': fail_message,
'conclusion': 'failure',
'summary': mc_config.get("label_present_message_long", '')
}}
else:
return {'blocking_labels': {
'title': pass_message,
'conclusion': 'success',
'summary': mc_config.get("label_absent_message_long", '')
}}