-
Notifications
You must be signed in to change notification settings - Fork 9
A new plugin to post a welcome comment #94
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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` | ||
|
|
@@ -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): | ||
|
|
||
| # TODO: cache handlers and invalidate the internal cache of the handlers on | ||
| # certain events. | ||
|
|
@@ -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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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...
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
|
|
||
| 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean
payloadhas to be a keyword? If so, why is no default assigned?There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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