Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion baldrick/plugins/github_milestones.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


@pull_request_handler
def process_milestone(pr_handler, repo_handler):
def process_milestone(pr_handler, repo_handler, payload=None):
"""
A very simple set a failing status if the milestone is not set.
"""
Expand Down
8 changes: 4 additions & 4 deletions baldrick/plugins/github_pull_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def pull_request_handler(actions=None):
However, you may pass in a list of strings with subsets of these actions to
control when the checks are run.

They will be passed ``(pr_handler, repo_handler)`` and are expected to
They will be passed ``(pr_handler, repo_handler, payload)`` and are expected to
return a dictionary where the key is a unique string that refers to the
specific check that has been made, and the values are dictionaries with any
arguments to the `~baldrick.github.github_api.PullRequestHandler.set_check`
Expand Down Expand Up @@ -96,11 +96,11 @@ def handle_pull_requests(repo_handler, payload, headers):

return process_pull_request(
repo_handler.repo, number, repo_handler.installation,
action=payload['action'], is_new=is_new)
action=payload['action'], is_new=is_new, payload=payload)


def process_pull_request(repository, number, installation, action,
is_new=False):
is_new=False, *, payload):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does this mean payload has to be a keyword? If so, why is no default assigned?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

because I didn't want to change the signature, but we always should pass payload in.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The other change is already a breaking change, so why not just change the signature here also?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I personally think it makes sense like this though, as a required keyword argument


# TODO: cache handlers and invalidate the internal cache of the handlers on
# certain events.
Expand Down Expand Up @@ -138,7 +138,7 @@ def process_pull_request(repository, number, installation, action,
results = {}
for function, actions in PULL_REQUEST_CHECKS.items():
if actions is None or action in actions:
result = function(pr_handler, repo_handler)
result = function(pr_handler, repo_handler, payload)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does this need to break backward compat? Can this be an optional keyword as above?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this isn't a function sig, we are calling the registered callback functions. The only way to pass this information is to always pass it. We could do some crazy signature introspection stuff but...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah, I see your point... 🤔

# Ignore skipped checks
if result is not None:
# Map old plugin keys to new checks names.
Expand Down
2 changes: 1 addition & 1 deletion baldrick/plugins/github_towncrier_changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def load_towncrier_config(pr_handler):


@pull_request_handler
def process_towncrier_changelog(pr_handler, repo_handler):
def process_towncrier_changelog(pr_handler, repo_handler, payload=None):

cl_config = pr_handler.get_config_value('towncrier_changelog', {})

Expand Down
21 changes: 21 additions & 0 deletions baldrick/plugins/github_welcome.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""
A simple plugin which responds to new PRs and sends a configured welcome message.
"""
from loguru import logger

from baldrick.plugins.github_pull_requests import pull_request_handler


@pull_request_handler
def send_welcome_message(pr_handler, repo_handler, payload):
# Only react on a new PR
if payload['action'] != 'opened':
return

cl_config = pr_handler.get_config_value('welcome_message', {})
message = cl_config.get('message', False)
if not message:
logger.debug("Skipping welcome message, as no message set in config.")
return None

pr_handler.submit_comment(message)