|
11 | 11 | import zlib |
12 | 12 | from typing import Awaitable, Callable, Optional |
13 | 13 |
|
| 14 | +import github |
14 | 15 | import requests |
15 | 16 | from github import Github, UnknownObjectException |
| 17 | +from github.GithubObject import NotSet, Opt |
16 | 18 | from github.Workflow import Workflow |
17 | 19 | from github.WorkflowRun import WorkflowRun |
18 | 20 |
|
@@ -177,6 +179,35 @@ class GitHubArtifact: |
177 | 179 | _WORKFLOW_FILE_CACHE: dict[str, Workflow] = {} |
178 | 180 |
|
179 | 181 |
|
| 182 | +def patched_create_dispatch( |
| 183 | + workflow: Workflow, |
| 184 | + ref: github.Branch.Branch | github.Tag.Tag | github.Commit.Commit | str, |
| 185 | + inputs: Opt[dict] = NotSet, |
| 186 | +) -> bool: |
| 187 | + """ |
| 188 | + :calls: `POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches <https://docs.github.com/en/rest/reference/actions#create-a-workflow-dispatch-event>`_ |
| 189 | + """ |
| 190 | + assert ( |
| 191 | + isinstance(ref, github.Branch.Branch) |
| 192 | + or isinstance(ref, github.Tag.Tag) |
| 193 | + or isinstance(ref, github.Commit.Commit) |
| 194 | + or isinstance(ref, str) |
| 195 | + ), ref |
| 196 | + assert inputs is NotSet or isinstance(inputs, dict), inputs |
| 197 | + if isinstance(ref, github.Branch.Branch): |
| 198 | + ref = ref.name |
| 199 | + elif isinstance(ref, github.Commit.Commit): |
| 200 | + ref = ref.sha |
| 201 | + elif isinstance(ref, github.Tag.Tag): |
| 202 | + ref = ref.name |
| 203 | + if inputs is NotSet: |
| 204 | + inputs = {} |
| 205 | + status, _, _ = workflow._requester.requestJson( |
| 206 | + "POST", f"{workflow.url}/dispatches", input={"ref": ref, "inputs": inputs} |
| 207 | + ) |
| 208 | + return status == 200 |
| 209 | + |
| 210 | + |
180 | 211 | class GitHubRun: |
181 | 212 | def __init__(self, repo: str, token: str, branch: str, workflow_file: str): |
182 | 213 | gh = Github(token) |
@@ -261,8 +292,8 @@ async def trigger(self, inputs: dict) -> bool: |
261 | 292 | pprint.pformat(inputs_with_run_id), |
262 | 293 | ) |
263 | 294 | success = await asyncio.to_thread( |
264 | | - workflow.create_dispatch, self.branch, inputs=inputs_with_run_id |
265 | | - ) |
| 295 | + patched_create_dispatch, workflow, self.branch, inputs=inputs_with_run_id |
| 296 | + ) # noqa: E501 |
266 | 297 |
|
267 | 298 | if success: |
268 | 299 | wait_seconds = 10 |
|
0 commit comments