Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a patched version of the GitHub library's create_dispatch method to customize the workflow dispatch behavior. The patch is implemented as a standalone function that replicates the dispatch functionality with modifications.
Key changes:
- Added
patched_create_dispatchfunction that mimics the GitHub library's workflow dispatch method - Updated the
triggermethod to use the patched version instead of calling the library's built-in method - Added necessary imports for GitHub library types (
github,NotSet,Opt)
Comments suppressed due to low confidence (3)
src/libkernelbot/launchers/github.py:196
- Using assert statements for input validation is not recommended in production code, as assertions can be disabled with Python's -O optimization flag. Consider replacing these assertions with proper validation that raises TypeError or ValueError exceptions to ensure input validation always occurs.
assert (
isinstance(ref, github.Branch.Branch)
or isinstance(ref, github.Tag.Tag)
or isinstance(ref, github.Commit.Commit)
or isinstance(ref, str)
), ref
assert inputs is NotSet or isinstance(inputs, dict), inputs
src/libkernelbot/launchers/github.py:296
- The noqa: E501 comment is used to suppress line length warnings. Consider breaking this into multiple lines for better readability instead of suppressing the linting rule.
success = await asyncio.to_thread(
src/libkernelbot/launchers/github.py:189
- The patched_create_dispatch function lacks documentation explaining why this patch is necessary instead of using the library's built-in create_dispatch method. Consider adding a docstring or comment that explains what issue this patch addresses in the original implementation.
def patched_create_dispatch(
workflow: Workflow,
ref: github.Branch.Branch | github.Tag.Tag | github.Commit.Commit | str,
inputs: Opt[dict] = NotSet,
) -> bool:
"""
:calls: `POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches <https://docs.github.com/en/rest/reference/actions#create-a-workflow-dispatch-event>`_
"""
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return status == 200 or status == 204 | ||
|
|
||
|
|
||
|
|
There was a problem hiding this comment.
The function returns a boolean indicating success based only on status codes 200 or 204, but returns False for all other status codes without providing any information about what went wrong. Consider logging the actual status code when it's not 200 or 204, or raising an exception with details about the failure to help with debugging when workflow dispatch fails.
| return status == 200 or status == 204 | |
| if status == 200 or status == 204: | |
| return True | |
| logger.error( | |
| "Workflow dispatch failed for '%s' (ref=%s) with HTTP status %s", | |
| getattr(workflow, "path", workflow), | |
| ref, | |
| status, | |
| ) | |
| return False |
No description provided.