Skip to content
Merged
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
35 changes: 33 additions & 2 deletions src/libkernelbot/launchers/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
import zlib
from typing import Awaitable, Callable, Optional

import github
import requests
from github import Github, UnknownObjectException
from github.GithubObject import NotSet, Opt
from github.Workflow import Workflow
from github.WorkflowRun import WorkflowRun

Expand Down Expand Up @@ -177,6 +179,35 @@ class GitHubArtifact:
_WORKFLOW_FILE_CACHE: dict[str, Workflow] = {}


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>`_
"""
Comment on lines +187 to +189
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

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

The docstring should explain why this patched version exists and what issue it addresses. Consider adding a note that this patches the PyGithub library to handle GitHub API's change from returning 204 to 200 status codes.

Copilot uses AI. Check for mistakes.
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
if isinstance(ref, github.Branch.Branch):
ref = ref.name
elif isinstance(ref, github.Commit.Commit):
ref = ref.sha
elif isinstance(ref, github.Tag.Tag):
ref = ref.name
if inputs is NotSet:
inputs = {}
status, _, _ = workflow._requester.requestJson(
"POST", f"{workflow.url}/dispatches", input={"ref": ref, "inputs": inputs}
)
return status == 200
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

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

The patched function only accepts status code 200, but according to the PR description, GitHub previously returned 204. To maintain backward compatibility and handle both old and new API behavior, consider accepting both status codes. This would prevent issues if GitHub reverts the change or if different GitHub API versions are used.

Suggested change
return status == 200
return status in (200, 204)

Copilot uses AI. Check for mistakes.


class GitHubRun:
def __init__(self, repo: str, token: str, branch: str, workflow_file: str):
gh = Github(token)
Expand Down Expand Up @@ -261,8 +292,8 @@ async def trigger(self, inputs: dict) -> bool:
pprint.pformat(inputs_with_run_id),
)
success = await asyncio.to_thread(
workflow.create_dispatch, self.branch, inputs=inputs_with_run_id
)
patched_create_dispatch, workflow, self.branch, inputs=inputs_with_run_id
) # noqa: E501
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

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

The noqa: E501 comment suppresses line-too-long warnings, but this line appears to be under the 100-character limit specified in .ruff.toml. Consider removing this comment if the line length is within the project's limits.

Suggested change
) # noqa: E501
)

Copilot uses AI. Check for mistakes.

if success:
wait_seconds = 10
Expand Down
Loading