continuum-task-server-bundle 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. continuum_task_server_bundle/__init__.py +1 -0
  2. continuum_task_server_bundle/daytona/__init__.py +4 -0
  3. continuum_task_server_bundle/daytona/common.py +534 -0
  4. continuum_task_server_bundle/daytona/create_sandbox.py +166 -0
  5. continuum_task_server_bundle/daytona/dispatch.py +125 -0
  6. continuum_task_server_bundle/daytona/execute_sandbox.py +243 -0
  7. continuum_task_server_bundle/daytona/filesystem.py +330 -0
  8. continuum_task_server_bundle/daytona/fs_edit.py +127 -0
  9. continuum_task_server_bundle/daytona/git_ops.py +585 -0
  10. continuum_task_server_bundle/daytona/github_app.py +207 -0
  11. continuum_task_server_bundle/daytona/manage_sandbox.py +104 -0
  12. continuum_task_server_bundle/daytona/plugin.py +18 -0
  13. continuum_task_server_bundle/daytona/s3_transfer.py +207 -0
  14. continuum_task_server_bundle/discord/__init__.py +4 -0
  15. continuum_task_server_bundle/discord/attachment_registry_db.py +127 -0
  16. continuum_task_server_bundle/discord/attachment_resolve.py +213 -0
  17. continuum_task_server_bundle/discord/await_cleanup.py +105 -0
  18. continuum_task_server_bundle/discord/discord_ready.py +39 -0
  19. continuum_task_server_bundle/discord/message_await_apply.py +143 -0
  20. continuum_task_server_bundle/discord/message_await_db.py +197 -0
  21. continuum_task_server_bundle/discord/message_await_inbound.py +54 -0
  22. continuum_task_server_bundle/discord/message_await_logic.py +133 -0
  23. continuum_task_server_bundle/discord/message_await_poller.py +122 -0
  24. continuum_task_server_bundle/discord/message_chunking.py +45 -0
  25. continuum_task_server_bundle/discord/methods.py +408 -0
  26. continuum_task_server_bundle/discord/plugin.py +105 -0
  27. continuum_task_server_bundle/discord/reaction_await_apply.py +238 -0
  28. continuum_task_server_bundle/discord/reaction_await_db.py +174 -0
  29. continuum_task_server_bundle/discord/reaction_await_inbound.py +47 -0
  30. continuum_task_server_bundle/discord/reaction_await_logic.py +118 -0
  31. continuum_task_server_bundle/discord/reaction_await_poller.py +131 -0
  32. continuum_task_server_bundle/discord/s3_attachment_config.py +25 -0
  33. continuum_task_server_bundle/discord/s3_message_attachments.py +139 -0
  34. continuum_task_server_bundle/discord/sql/001_message_awaits.sql +112 -0
  35. continuum_task_server_bundle/discord/sql/002_reaction_awaits.sql +61 -0
  36. continuum_task_server_bundle/github/__init__.py +4 -0
  37. continuum_task_server_bundle/github/awaits/__init__.py +1 -0
  38. continuum_task_server_bundle/github/awaits/apply.py +92 -0
  39. continuum_task_server_bundle/github/awaits/cleanup.py +94 -0
  40. continuum_task_server_bundle/github/awaits/db.py +220 -0
  41. continuum_task_server_bundle/github/awaits/evaluators.py +325 -0
  42. continuum_task_server_bundle/github/awaits/fetch.py +192 -0
  43. continuum_task_server_bundle/github/awaits/poller.py +82 -0
  44. continuum_task_server_bundle/github/awaits/register.py +37 -0
  45. continuum_task_server_bundle/github/ci_status.py +70 -0
  46. continuum_task_server_bundle/github/comment_normalize.py +76 -0
  47. continuum_task_server_bundle/github/errors.py +52 -0
  48. continuum_task_server_bundle/github/github_app.py +291 -0
  49. continuum_task_server_bundle/github/github_http.py +377 -0
  50. continuum_task_server_bundle/github/methods/__init__.py +90 -0
  51. continuum_task_server_bundle/github/methods/_common.py +183 -0
  52. continuum_task_server_bundle/github/methods/awaits.py +107 -0
  53. continuum_task_server_bundle/github/methods/ci.py +158 -0
  54. continuum_task_server_bundle/github/methods/comments.py +214 -0
  55. continuum_task_server_bundle/github/methods/credentials.py +59 -0
  56. continuum_task_server_bundle/github/methods/issues.py +131 -0
  57. continuum_task_server_bundle/github/methods/pulls.py +329 -0
  58. continuum_task_server_bundle/github/methods/repos.py +424 -0
  59. continuum_task_server_bundle/github/methods/search.py +109 -0
  60. continuum_task_server_bundle/github/plugin.py +91 -0
  61. continuum_task_server_bundle/github/sql/001_github_awaits.sql +65 -0
  62. continuum_task_server_bundle/github/webhook_server.py +126 -0
  63. continuum_task_server_bundle/jira/__init__.py +4 -0
  64. continuum_task_server_bundle/jira/await_poller.py +236 -0
  65. continuum_task_server_bundle/jira/await_store.py +271 -0
  66. continuum_task_server_bundle/jira/config.py +68 -0
  67. continuum_task_server_bundle/jira/jira_client.py +382 -0
  68. continuum_task_server_bundle/jira/methods.py +246 -0
  69. continuum_task_server_bundle/jira/plugin.py +86 -0
  70. continuum_task_server_bundle/jira/sql/001_jira_issue_comment_waits.sql +19 -0
  71. continuum_task_server_bundle/jira/webhook.py +70 -0
  72. continuum_task_server_bundle/openrouter/__init__.py +4 -0
  73. continuum_task_server_bundle/openrouter/chat_service.py +1037 -0
  74. continuum_task_server_bundle/openrouter/chat_store.py +849 -0
  75. continuum_task_server_bundle/openrouter/environment.py +29 -0
  76. continuum_task_server_bundle/openrouter/handler.py +59 -0
  77. continuum_task_server_bundle/openrouter/image_context.py +207 -0
  78. continuum_task_server_bundle/openrouter/openrouter_client.py +324 -0
  79. continuum_task_server_bundle/openrouter/plugin.py +37 -0
  80. continuum_task_server_bundle/openrouter/prompt_projection.py +417 -0
  81. continuum_task_server_bundle/openrouter/sql/chat.sql +50 -0
  82. continuum_task_server_bundle/openrouter/sql/migrate_prune_then_chunk_v1.sql +11 -0
  83. continuum_task_server_bundle/roblox/__init__.py +4 -0
  84. continuum_task_server_bundle/roblox/open_cloud.py +335 -0
  85. continuum_task_server_bundle/roblox/plugin.py +30 -0
  86. continuum_task_server_bundle/roblox/storage_s3.py +55 -0
  87. continuum_task_server_bundle-1.0.0.dist-info/METADATA +109 -0
  88. continuum_task_server_bundle-1.0.0.dist-info/RECORD +90 -0
  89. continuum_task_server_bundle-1.0.0.dist-info/WHEEL +5 -0
  90. continuum_task_server_bundle-1.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,90 @@
1
+ """Method name to callable. The name comes from item_definition_json.method."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from continuum_task_server_bundle.github.methods.awaits import await_ci, await_comments, await_pull_request
6
+ from continuum_task_server_bundle.github.methods.ci import dispatch_workflow, get_ci_status, get_job_logs, list_workflow_runs, rerun_failed_jobs
7
+ from continuum_task_server_bundle.github.methods.comments import add_reaction, comment, edit_comment, list_comments, reply_to_review_comment
8
+ from continuum_task_server_bundle.github.methods.credentials import get_installation_token
9
+ from continuum_task_server_bundle.github.methods.issues import add_labels, create_issue, get_issue, list_issues, remove_label, update_issue
10
+ from continuum_task_server_bundle.github.methods.pulls import (
11
+ close_pull_request,
12
+ create_pull_request,
13
+ create_review,
14
+ get_pr_diff,
15
+ get_pull_request,
16
+ list_pr_files,
17
+ list_pull_requests,
18
+ mark_ready_for_review,
19
+ merge_pull_request,
20
+ request_reviewers,
21
+ update_branch,
22
+ update_pull_request,
23
+ )
24
+ from continuum_task_server_bundle.github.methods.repos import (
25
+ compare,
26
+ create_branch,
27
+ create_repo,
28
+ create_repo_from_template,
29
+ delete_branch,
30
+ fork_repo,
31
+ get_branch,
32
+ get_file,
33
+ get_repo,
34
+ list_branches,
35
+ list_commits,
36
+ put_file,
37
+ set_actions_enabled,
38
+ )
39
+ from continuum_task_server_bundle.github.methods.search import search_code, search_issues, search_repos
40
+
41
+ METHODS = {
42
+ "get_installation_token": get_installation_token,
43
+ "search_code": search_code,
44
+ "search_repos": search_repos,
45
+ "search_issues": search_issues,
46
+ "get_repo": get_repo,
47
+ "list_branches": list_branches,
48
+ "get_branch": get_branch,
49
+ "list_commits": list_commits,
50
+ "compare": compare,
51
+ "get_file": get_file,
52
+ "create_branch": create_branch,
53
+ "delete_branch": delete_branch,
54
+ "put_file": put_file,
55
+ "fork_repo": fork_repo,
56
+ "create_repo_from_template": create_repo_from_template,
57
+ "create_repo": create_repo,
58
+ "set_actions_enabled": set_actions_enabled,
59
+ "create_pull_request": create_pull_request,
60
+ "get_pull_request": get_pull_request,
61
+ "list_pull_requests": list_pull_requests,
62
+ "list_pr_files": list_pr_files,
63
+ "get_pr_diff": get_pr_diff,
64
+ "update_pull_request": update_pull_request,
65
+ "mark_ready_for_review": mark_ready_for_review,
66
+ "request_reviewers": request_reviewers,
67
+ "create_review": create_review,
68
+ "update_branch": update_branch,
69
+ "merge_pull_request": merge_pull_request,
70
+ "close_pull_request": close_pull_request,
71
+ "comment": comment,
72
+ "list_comments": list_comments,
73
+ "edit_comment": edit_comment,
74
+ "reply_to_review_comment": reply_to_review_comment,
75
+ "add_reaction": add_reaction,
76
+ "create_issue": create_issue,
77
+ "get_issue": get_issue,
78
+ "list_issues": list_issues,
79
+ "update_issue": update_issue,
80
+ "add_labels": add_labels,
81
+ "remove_label": remove_label,
82
+ "get_ci_status": get_ci_status,
83
+ "list_workflow_runs": list_workflow_runs,
84
+ "get_job_logs": get_job_logs,
85
+ "rerun_failed_jobs": rerun_failed_jobs,
86
+ "dispatch_workflow": dispatch_workflow,
87
+ "await_ci": await_ci,
88
+ "await_comments": await_comments,
89
+ "await_pull_request": await_pull_request,
90
+ }
@@ -0,0 +1,183 @@
1
+ """Shared queue-input helpers for GitHub methods."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass
6
+ from datetime import datetime, timezone
7
+ from typing import Any
8
+ from urllib.parse import quote
9
+
10
+ from continuum_task_server_bundle.github.errors import InputError
11
+
12
+
13
+ @dataclass
14
+ class Call:
15
+ app: Any
16
+ item: Any
17
+
18
+ @property
19
+ def data(self) -> dict[str, Any]:
20
+ raw = self.item.input_data_json or {}
21
+ if not isinstance(raw, dict):
22
+ raise InputError("input_data must be a JSON object")
23
+ return raw
24
+
25
+
26
+ def require_repo(data: dict[str, Any]) -> tuple[str, str]:
27
+ repo = data.get("repo")
28
+ if not isinstance(repo, str) or repo.count("/") != 1:
29
+ raise InputError("repo must be owner/name")
30
+ owner, name = repo.split("/", 1)
31
+ owner = owner.strip()
32
+ name = name.strip()
33
+ if not owner or not name or "/" in name:
34
+ raise InputError("repo must be owner/name")
35
+ return owner, name
36
+
37
+
38
+ def repo_full_name(owner: str, name: str) -> str:
39
+ return f"{owner}/{name}".lower()
40
+
41
+
42
+ def require_str(data: dict[str, Any], key: str) -> str:
43
+ value = data.get(key)
44
+ if not isinstance(value, str) or not value.strip():
45
+ raise InputError(f"{key} is required")
46
+ return value.strip()
47
+
48
+
49
+ def require_number(data: dict[str, Any], *keys: str) -> int:
50
+ for key in keys:
51
+ if data.get(key) is not None:
52
+ try:
53
+ return int(data[key])
54
+ except (TypeError, ValueError) as exc:
55
+ raise InputError(f"{key} must be an integer") from exc
56
+ raise InputError(f"{' or '.join(keys)} is required")
57
+
58
+
59
+ def opt_float(data: dict[str, Any], *keys: str, default: float) -> float:
60
+ for key in keys:
61
+ if data.get(key) is not None:
62
+ try:
63
+ return float(data[key])
64
+ except (TypeError, ValueError) as exc:
65
+ raise InputError(f"{key} must be a number") from exc
66
+ return default
67
+
68
+
69
+ def opt_int(data: dict[str, Any], *keys: str, default: int) -> int:
70
+ for key in keys:
71
+ if data.get(key) is not None:
72
+ try:
73
+ return int(data[key])
74
+ except (TypeError, ValueError) as exc:
75
+ raise InputError(f"{key} must be an integer") from exc
76
+ return default
77
+
78
+
79
+ def as_bool(value: Any, default: bool = False) -> bool:
80
+ if value is None:
81
+ return default
82
+ if isinstance(value, bool):
83
+ return value
84
+ if isinstance(value, str):
85
+ return value.strip().lower() in ("1", "true", "yes", "on")
86
+ return bool(value)
87
+
88
+
89
+ def opt_str_list(data: dict[str, Any], key: str) -> list[str] | None:
90
+ raw = data.get(key)
91
+ if raw is None:
92
+ return None
93
+ if isinstance(raw, str):
94
+ return [raw]
95
+ if not isinstance(raw, list):
96
+ raise InputError(f"{key} must be a list of strings")
97
+ out: list[str] = []
98
+ for item in raw:
99
+ if not isinstance(item, str) or not item.strip():
100
+ raise InputError(f"{key} must be a list of strings")
101
+ out.append(item.strip())
102
+ return out
103
+
104
+
105
+ def repo_names(values: list[str]) -> list[str]:
106
+ """Accept ``name`` or ``owner/name`` and return repository names."""
107
+ names: list[str] = []
108
+ for value in values:
109
+ names.append(value.split("/", 1)[1] if "/" in value else value)
110
+ return names
111
+
112
+
113
+ def git_clone_url(owner: str, repo: str, token: str) -> str:
114
+ safe_token = quote(token, safe="")
115
+ return f"https://x-access-token:{safe_token}@github.com/{owner}/{repo}.git"
116
+
117
+
118
+ def path_segment(value: str) -> str:
119
+ """Encode a path segment but keep slashes (branch names like ``feat/foo``)."""
120
+ return quote(value, safe="/")
121
+
122
+
123
+ def trim_repo(repo: dict[str, Any]) -> dict[str, Any]:
124
+ owner = repo.get("owner") or {}
125
+ return {
126
+ "id": repo.get("id"),
127
+ "node_id": repo.get("node_id"),
128
+ "name": repo.get("name"),
129
+ "full_name": repo.get("full_name"),
130
+ "owner": owner.get("login") if isinstance(owner, dict) else None,
131
+ "private": repo.get("private"),
132
+ "fork": repo.get("fork"),
133
+ "default_branch": repo.get("default_branch"),
134
+ "html_url": repo.get("html_url"),
135
+ "clone_url": repo.get("clone_url"),
136
+ "description": repo.get("description"),
137
+ "archived": repo.get("archived"),
138
+ "language": repo.get("language"),
139
+ "pushed_at": repo.get("pushed_at"),
140
+ "permissions": repo.get("permissions"),
141
+ }
142
+
143
+
144
+ def trim_pr(pull: dict[str, Any], *, review_decision: str | None = None) -> dict[str, Any]:
145
+ head = pull.get("head") or {}
146
+ base = pull.get("base") or {}
147
+ user = pull.get("user") or {}
148
+ head_repo = head.get("repo") if isinstance(head, dict) else None
149
+ base_repo = base.get("repo") if isinstance(base, dict) else None
150
+ return {
151
+ "number": pull.get("number"),
152
+ "node_id": pull.get("node_id"),
153
+ "title": pull.get("title"),
154
+ "body": pull.get("body"),
155
+ "state": pull.get("state"),
156
+ "draft": pull.get("draft"),
157
+ "merged": pull.get("merged"),
158
+ "mergeable": pull.get("mergeable"),
159
+ "mergeable_state": pull.get("mergeable_state"),
160
+ "html_url": pull.get("html_url"),
161
+ "user_login": user.get("login") if isinstance(user, dict) else None,
162
+ "head_ref": head.get("ref") if isinstance(head, dict) else None,
163
+ "head_sha": head.get("sha") if isinstance(head, dict) else None,
164
+ "head_repo": head_repo.get("full_name") if isinstance(head_repo, dict) else None,
165
+ "base_ref": base.get("ref") if isinstance(base, dict) else None,
166
+ "base_sha": base.get("sha") if isinstance(base, dict) else None,
167
+ "base_repo": base_repo.get("full_name") if isinstance(base_repo, dict) else None,
168
+ "review_decision": review_decision,
169
+ }
170
+
171
+
172
+ def parse_time(value: Any) -> datetime | None:
173
+ if value is None:
174
+ return None
175
+ if isinstance(value, datetime):
176
+ if value.tzinfo is None:
177
+ return value.replace(tzinfo=timezone.utc)
178
+ return value.astimezone(timezone.utc)
179
+ text = str(value).replace("Z", "+00:00")
180
+ parsed = datetime.fromisoformat(text)
181
+ if parsed.tzinfo is None:
182
+ parsed = parsed.replace(tzinfo=timezone.utc)
183
+ return parsed.astimezone(timezone.utc)
@@ -0,0 +1,107 @@
1
+ """Long-running GitHub waits.
2
+
3
+ These insert a ``github_awaits`` row and return ``None``. The poller completes
4
+ the queue item. ``fork_repo`` and ``create_repo_from_template`` register
5
+ ``repo_ready`` themselves when ``wait_until_ready`` is set.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from typing import Any
11
+
12
+ from continuum_task_server_bundle.github.awaits.register import register_await
13
+ from continuum_task_server_bundle.github.errors import InputError
14
+ from continuum_task_server_bundle.github.methods._common import (
15
+ Call,
16
+ as_bool,
17
+ opt_float,
18
+ opt_int,
19
+ opt_str_list,
20
+ repo_full_name,
21
+ require_number,
22
+ require_repo,
23
+ )
24
+ from continuum_task_server_bundle.github.methods.ci import _resolve_sha
25
+
26
+
27
+ def await_ci(call: Call) -> None:
28
+ owner, name, sha = _resolve_sha(call)
29
+ data = call.data
30
+ required = opt_str_list(data, "required_checks")
31
+ number = None
32
+ if data.get("pr_number") is not None or (data.get("number") is not None and data.get("ref") is None and data.get("sha") is None):
33
+ number = require_number(data, "pr_number", "number")
34
+ register_await(
35
+ call.item.id,
36
+ kind="await_ci",
37
+ repo_full_name=repo_full_name(owner, name),
38
+ number=number,
39
+ head_sha=sha,
40
+ params={
41
+ "required_checks": required,
42
+ "checks_grace_seconds": opt_float(data, "checks_grace_seconds", default=180.0),
43
+ },
44
+ timeout_seconds=opt_float(data, "timeout_seconds", "timeout", default=1800.0),
45
+ poll_interval_seconds=opt_float(data, "poll_interval_seconds", "poll_interval", default=30.0),
46
+ )
47
+
48
+
49
+ def await_comments(call: Call) -> None:
50
+ owner, name = require_repo(call.data)
51
+ number = require_number(call.data, "number", "pr_number", "issue_number")
52
+ data = call.data
53
+ include = opt_str_list(data, "include") or ["issue_comment", "review_comment", "review"]
54
+ authors = opt_str_list(data, "author_logins")
55
+ app_slug = None
56
+ if as_bool(data.get("ignore_own_app"), default=True):
57
+ app_slug = call.app.slug()
58
+ register_await(
59
+ call.item.id,
60
+ kind="await_comments",
61
+ repo_full_name=repo_full_name(owner, name),
62
+ number=number,
63
+ params={
64
+ "include": include,
65
+ "since": data.get("since"),
66
+ "after_id": data.get("after_id"),
67
+ "ignore_own_app": as_bool(data.get("ignore_own_app"), default=True),
68
+ "app_slug": app_slug,
69
+ "author_logins": authors,
70
+ "limit": opt_int(data, "limit", "message_limit", default=50),
71
+ "quiet_period_seconds": opt_float(data, "quiet_period_seconds", "quiet_period", default=0.0),
72
+ },
73
+ timeout_seconds=opt_float(data, "timeout_seconds", "timeout", default=3600.0),
74
+ poll_interval_seconds=opt_float(data, "poll_interval_seconds", "poll_interval", default=60.0),
75
+ )
76
+
77
+
78
+ def await_pull_request(call: Call) -> None:
79
+ owner, name = require_repo(call.data)
80
+ number = require_number(call.data, "number", "pr_number")
81
+ data = call.data
82
+ until = data.get("until") or "merged"
83
+ if isinstance(until, str):
84
+ until_list = [until]
85
+ elif isinstance(until, list) and until:
86
+ until_list = [str(item) for item in until]
87
+ else:
88
+ raise InputError("until must be a condition or a list of conditions")
89
+ allowed = {"merged", "closed", "approved", "changes_requested", "mergeable"}
90
+ unknown = [item for item in until_list if item not in allowed]
91
+ if unknown:
92
+ raise InputError(
93
+ "until must be one of merged, closed, approved, changes_requested, mergeable"
94
+ )
95
+ repo = f"{owner}/{name}"
96
+ pull = call.app.rest("GET", f"/repos/{owner}/{name}/pulls/{number}", repo=repo).data or {}
97
+ head_sha = (pull.get("head") or {}).get("sha")
98
+ register_await(
99
+ call.item.id,
100
+ kind="await_pull_request",
101
+ repo_full_name=repo_full_name(owner, name),
102
+ number=number,
103
+ head_sha=str(head_sha) if head_sha else None,
104
+ params={"until": until_list},
105
+ timeout_seconds=opt_float(data, "timeout_seconds", "timeout", default=3600.0),
106
+ poll_interval_seconds=opt_float(data, "poll_interval_seconds", "poll_interval", default=30.0),
107
+ )
@@ -0,0 +1,158 @@
1
+ """Check runs, commit statuses, and Actions workflows."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any
6
+
7
+ from continuum_task_server_bundle.github.ci_status import combine_checks, summarize_checks
8
+ from continuum_task_server_bundle.github.errors import InputError
9
+ from continuum_task_server_bundle.github.methods._common import Call, opt_int, require_number, require_repo, require_str
10
+
11
+
12
+ def get_ci_status(call: Call) -> dict[str, Any]:
13
+ owner, name, sha = _resolve_sha(call)
14
+ checks, _runs, _statuses = load_checks(call.app, owner, name, sha)
15
+ return {
16
+ "success": True,
17
+ "state": summarize_checks(checks),
18
+ "head_sha": sha,
19
+ "checks": checks,
20
+ }
21
+
22
+
23
+ def list_workflow_runs(call: Call) -> dict[str, Any]:
24
+ owner, name = require_repo(call.data)
25
+ repo = f"{owner}/{name}"
26
+ per_page = min(100, max(1, opt_int(call.data, "per_page", "limit", default=20)))
27
+ runs = call.app.rest(
28
+ "GET",
29
+ f"/repos/{owner}/{name}/actions/runs",
30
+ repo=repo,
31
+ params={
32
+ "branch": call.data.get("branch"),
33
+ "head_sha": call.data.get("head_sha") or call.data.get("sha"),
34
+ "status": call.data.get("status"),
35
+ "event": call.data.get("event"),
36
+ "per_page": per_page,
37
+ },
38
+ list_key="workflow_runs",
39
+ ).data or {}
40
+ raw_runs = runs.get("workflow_runs") if isinstance(runs, dict) else runs
41
+ trimmed = [_trim_run(run) for run in (raw_runs or [])]
42
+ return {"success": True, "workflow_runs": trimmed, "total_count": (runs or {}).get("total_count") if isinstance(runs, dict) else len(trimmed)}
43
+
44
+
45
+ def get_job_logs(call: Call) -> dict[str, Any]:
46
+ owner, name = require_repo(call.data)
47
+ job_id = require_number(call.data, "job_id")
48
+ repo = f"{owner}/{name}"
49
+ max_bytes = min(1_000_000, max(1, opt_int(call.data, "max_bytes", default=65536)))
50
+ token = call.app.token_for_repo(owner, name)
51
+ text, truncated = call.app.http.read_tail(
52
+ f"/repos/{owner}/{name}/actions/jobs/{job_id}/logs",
53
+ token=token,
54
+ max_bytes=max_bytes,
55
+ )
56
+ return {"success": True, "job_id": job_id, "log": text, "truncated": truncated, "repo": repo}
57
+
58
+
59
+ def rerun_failed_jobs(call: Call) -> dict[str, Any]:
60
+ owner, name = require_repo(call.data)
61
+ run_id = require_number(call.data, "run_id")
62
+ repo = f"{owner}/{name}"
63
+ response = call.app.rest(
64
+ "POST",
65
+ f"/repos/{owner}/{name}/actions/runs/{run_id}/rerun-failed-jobs",
66
+ repo=repo,
67
+ )
68
+ return {"success": True, "run_id": run_id, "status": response.status}
69
+
70
+
71
+ def dispatch_workflow(call: Call) -> dict[str, Any]:
72
+ owner, name = require_repo(call.data)
73
+ workflow = call.data.get("workflow") or call.data.get("workflow_id")
74
+ if workflow is None or workflow == "":
75
+ raise InputError("workflow (id or filename) is required")
76
+ ref = require_str(call.data, "ref")
77
+ repo = f"{owner}/{name}"
78
+ body: dict[str, Any] = {"ref": ref}
79
+ if call.data.get("inputs") is not None:
80
+ if not isinstance(call.data["inputs"], dict):
81
+ raise InputError("inputs must be an object")
82
+ body["inputs"] = call.data["inputs"]
83
+ response = call.app.rest(
84
+ "POST",
85
+ f"/repos/{owner}/{name}/actions/workflows/{workflow}/dispatches",
86
+ repo=repo,
87
+ json_body=body,
88
+ )
89
+ return {"success": True, "workflow": str(workflow), "ref": ref, "status": response.status}
90
+
91
+
92
+ def load_checks(app: Any, owner: str, name: str, sha: str, etags: dict[str, Any] | None = None) -> tuple[list, list, list]:
93
+ """Return ``(combined checks, raw check runs, raw statuses)``."""
94
+ repo = f"{owner}/{name}"
95
+ etags = etags or {}
96
+ runs_response = app.rest(
97
+ "GET",
98
+ f"/repos/{owner}/{name}/commits/{sha}/check-runs",
99
+ repo=repo,
100
+ params={"per_page": 100},
101
+ etag=etags.get("check_runs"),
102
+ paginate=True,
103
+ list_key="check_runs",
104
+ max_pages=5,
105
+ )
106
+ status_response = app.rest(
107
+ "GET",
108
+ f"/repos/{owner}/{name}/commits/{sha}/status",
109
+ repo=repo,
110
+ etag=etags.get("statuses"),
111
+ )
112
+ check_runs = [] if runs_response.not_modified else (runs_response.data or [])
113
+ if isinstance(check_runs, dict):
114
+ check_runs = check_runs.get("check_runs") or []
115
+ status_body = {} if status_response.not_modified else (status_response.data or {})
116
+ statuses = status_body.get("statuses") if isinstance(status_body, dict) else []
117
+ return combine_checks(check_runs, statuses or []), list(check_runs or []), list(statuses or [])
118
+
119
+
120
+ def _resolve_sha(call: Call) -> tuple[str, str, str]:
121
+ owner, name = require_repo(call.data)
122
+ repo = f"{owner}/{name}"
123
+ if call.data.get("pr_number") is not None or (
124
+ call.data.get("number") is not None and call.data.get("ref") is None and call.data.get("sha") is None
125
+ ):
126
+ number = require_number(call.data, "pr_number", "number")
127
+ pull = call.app.rest("GET", f"/repos/{owner}/{name}/pulls/{number}", repo=repo).data or {}
128
+ sha = (pull.get("head") or {}).get("sha")
129
+ if not sha:
130
+ raise InputError("pull request has no head sha")
131
+ return owner, name, str(sha)
132
+ ref = call.data.get("sha") or call.data.get("ref")
133
+ if not isinstance(ref, str) or not ref.strip():
134
+ raise InputError("ref, sha, or pr_number is required")
135
+ commit = call.app.rest(
136
+ "GET",
137
+ f"/repos/{owner}/{name}/commits/{ref.strip()}",
138
+ repo=repo,
139
+ ).data or {}
140
+ sha = commit.get("sha")
141
+ if not sha:
142
+ raise InputError(f"could not resolve {ref!r}")
143
+ return owner, name, str(sha)
144
+
145
+
146
+ def _trim_run(run: dict[str, Any]) -> dict[str, Any]:
147
+ return {
148
+ "id": run.get("id"),
149
+ "name": run.get("name"),
150
+ "status": run.get("status"),
151
+ "conclusion": run.get("conclusion"),
152
+ "head_sha": run.get("head_sha"),
153
+ "event": run.get("event"),
154
+ "run_number": run.get("run_number"),
155
+ "html_url": run.get("html_url"),
156
+ "created_at": run.get("created_at"),
157
+ "updated_at": run.get("updated_at"),
158
+ }