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,192 @@
1
+ """Load the GitHub state an await evaluator needs.
2
+
3
+ ETags are stored on the row. A 304 keeps the previous snapshot from ``state_json``
4
+ so the evaluator can still apply timeout and grace rules.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from types import SimpleNamespace
10
+ from typing import Any
11
+
12
+ from continuum_task_server_bundle.github.ci_status import combine_checks
13
+ from continuum_task_server_bundle.github.comment_normalize import (
14
+ normalize_issue_comment,
15
+ normalize_review,
16
+ normalize_review_comment,
17
+ review_is_public,
18
+ )
19
+ from continuum_task_server_bundle.github.errors import GitHubRequestError
20
+ from continuum_task_server_bundle.github.methods._common import trim_pr
21
+ from continuum_task_server_bundle.github.methods.pulls import _review_decision
22
+
23
+
24
+ def fetch_row(app: Any, row: dict[str, Any]) -> tuple[dict[str, Any], dict[str, str]]:
25
+ kind = row.get("kind")
26
+ if kind == "await_ci":
27
+ return _fetch_ci(app, row)
28
+ if kind == "await_comments":
29
+ return _fetch_comments(app, row)
30
+ if kind == "await_pull_request":
31
+ return _fetch_pull(app, row)
32
+ if kind == "repo_ready":
33
+ return _fetch_repo(app, row)
34
+ raise RuntimeError(f"unknown await kind {kind!r}")
35
+
36
+
37
+ def _fetch_ci(app: Any, row: dict[str, Any]) -> tuple[dict[str, Any], dict[str, str]]:
38
+ owner, name = _split(row["repo_full_name"])
39
+ sha = row.get("head_sha")
40
+ if not sha:
41
+ raise RuntimeError("await_ci row is missing head_sha")
42
+ repo = f"{owner}/{name}"
43
+ state = _obj(row.get("state_json"))
44
+ etags = _obj(row.get("etags_json"))
45
+ runs = app.rest(
46
+ "GET",
47
+ f"/repos/{owner}/{name}/commits/{sha}/check-runs",
48
+ repo=repo,
49
+ params={"per_page": 100},
50
+ etag=etags.get("check_runs"),
51
+ paginate=True,
52
+ list_key="check_runs",
53
+ max_pages=5,
54
+ )
55
+ statuses = app.rest(
56
+ "GET",
57
+ f"/repos/{owner}/{name}/commits/{sha}/status",
58
+ repo=repo,
59
+ etag=etags.get("statuses"),
60
+ )
61
+ if runs.not_modified:
62
+ check_runs = list(state.get("check_runs") or [])
63
+ else:
64
+ check_runs = runs.data or []
65
+ if isinstance(check_runs, dict):
66
+ check_runs = list(check_runs.get("check_runs") or [])
67
+ if statuses.not_modified:
68
+ status_list = list(state.get("statuses") or [])
69
+ else:
70
+ body = statuses.data or {}
71
+ status_list = list(body.get("statuses") or []) if isinstance(body, dict) else []
72
+ new_etags = _keep_etag(etags, "check_runs", runs.etag)
73
+ new_etags = _keep_etag(new_etags, "statuses", statuses.etag)
74
+ return (
75
+ {
76
+ "checks": combine_checks(check_runs, status_list),
77
+ "check_runs": check_runs,
78
+ "statuses": status_list,
79
+ },
80
+ new_etags,
81
+ )
82
+
83
+
84
+ def _fetch_comments(app: Any, row: dict[str, Any]) -> tuple[dict[str, Any], dict[str, str]]:
85
+ owner, name = _split(row["repo_full_name"])
86
+ number = row.get("number")
87
+ if number is None:
88
+ raise RuntimeError("await_comments row is missing number")
89
+ repo = f"{owner}/{name}"
90
+ params = _obj(row.get("params_json"))
91
+ include = set(params.get("include") or ["issue_comment", "review_comment", "review"])
92
+ etags = _obj(row.get("etags_json"))
93
+ since = params.get("since")
94
+ comments: list[dict[str, Any]] = []
95
+ new_etags = dict(etags)
96
+
97
+ if "issue_comment" in include:
98
+ response = app.rest(
99
+ "GET",
100
+ f"/repos/{owner}/{name}/issues/{number}/comments",
101
+ repo=repo,
102
+ params={"per_page": 100, "since": since},
103
+ etag=etags.get("issue_comments"),
104
+ paginate=True,
105
+ max_pages=5,
106
+ )
107
+ new_etags = _keep_etag(new_etags, "issue_comments", response.etag)
108
+ if not response.not_modified and isinstance(response.data, list):
109
+ comments.extend(normalize_issue_comment(item) for item in response.data)
110
+
111
+ if "review_comment" in include:
112
+ response = app.rest(
113
+ "GET",
114
+ f"/repos/{owner}/{name}/pulls/{number}/comments",
115
+ repo=repo,
116
+ params={"per_page": 100, "since": since},
117
+ etag=etags.get("review_comments"),
118
+ paginate=True,
119
+ max_pages=5,
120
+ )
121
+ new_etags = _keep_etag(new_etags, "review_comments", response.etag)
122
+ if not response.not_modified and isinstance(response.data, list):
123
+ comments.extend(normalize_review_comment(item) for item in response.data)
124
+
125
+ if "review" in include:
126
+ response = app.rest(
127
+ "GET",
128
+ f"/repos/{owner}/{name}/pulls/{number}/reviews",
129
+ repo=repo,
130
+ params={"per_page": 100},
131
+ etag=etags.get("reviews"),
132
+ paginate=True,
133
+ max_pages=5,
134
+ )
135
+ new_etags = _keep_etag(new_etags, "reviews", response.etag)
136
+ if not response.not_modified and isinstance(response.data, list):
137
+ comments.extend(normalize_review(item) for item in response.data if review_is_public(item))
138
+
139
+ return {"comments": comments}, new_etags
140
+
141
+
142
+ def _fetch_pull(app: Any, row: dict[str, Any]) -> tuple[dict[str, Any], dict[str, str]]:
143
+ """Always refetch the pull request and its reviews.
144
+
145
+ A review does not change the pull request resource ETag, so a 304 would
146
+ hide approvals and change requests.
147
+ """
148
+ owner, name = _split(row["repo_full_name"])
149
+ number = row.get("number")
150
+ if number is None:
151
+ raise RuntimeError("await_pull_request row is missing number")
152
+ repo = f"{owner}/{name}"
153
+ body = app.rest("GET", f"/repos/{owner}/{name}/pulls/{number}", repo=repo).data or {}
154
+ decision = _review_decision(SimpleNamespace(app=app), owner, name, int(number))
155
+ return {"pull": trim_pr(body, review_decision=decision)}, {}
156
+
157
+
158
+ def _fetch_repo(app: Any, row: dict[str, Any]) -> tuple[dict[str, Any], dict[str, str]]:
159
+ full = str(row["repo_full_name"])
160
+ owner, name = _split(full)
161
+ try:
162
+ body = app.rest("GET", f"/repos/{owner}/{name}", repo=full).data or {}
163
+ except GitHubRequestError as exc:
164
+ if exc.status == 404:
165
+ return {"exists": False, "full_name": full}, {}
166
+ raise
167
+ return (
168
+ {
169
+ "exists": True,
170
+ "full_name": body.get("full_name") or full,
171
+ "default_branch": body.get("default_branch"),
172
+ "html_url": body.get("html_url"),
173
+ "clone_url": body.get("clone_url"),
174
+ },
175
+ {},
176
+ )
177
+
178
+
179
+ def _split(full_name: str) -> tuple[str, str]:
180
+ owner, name = str(full_name).split("/", 1)
181
+ return owner, name
182
+
183
+
184
+ def _obj(raw: Any) -> dict[str, Any]:
185
+ return dict(raw) if isinstance(raw, dict) else {}
186
+
187
+
188
+ def _keep_etag(etags: dict[str, Any], key: str, etag: str | None) -> dict[str, str]:
189
+ updated = {str(k): str(v) for k, v in etags.items() if v}
190
+ if etag:
191
+ updated[key] = etag
192
+ return updated
@@ -0,0 +1,82 @@
1
+ """Background polling for Postgres-backed GitHub awaits."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import logging
6
+ import threading
7
+ from typing import Any
8
+ from uuid import UUID
9
+
10
+ from continuum_task_server import TaskServer
11
+ from continuum_task_server.exceptions import ContinuumError
12
+
13
+ import continuum_task_server_bundle.github.awaits.db as db
14
+ from continuum_task_server_bundle.github.awaits.apply import apply_github_await
15
+ from continuum_task_server_bundle.github.awaits.cleanup import heartbeat_claim_or_drop
16
+ from continuum_task_server_bundle.github.awaits.fetch import fetch_row
17
+ from continuum_task_server_bundle.github.errors import GitHubRequestError, GitHubRetryableError
18
+
19
+ logger = logging.getLogger(__name__)
20
+
21
+
22
+ def _fail_row(server: TaskServer, row_id: UUID, message: str, *, type_name: str = "RuntimeError") -> None:
23
+ err = {"error": message, "type": type_name}
24
+ updated = db.mark_failed(row_id=row_id, error=err)
25
+ if updated is None:
26
+ return
27
+ try:
28
+ server.fail_queue_item(updated, error=err)
29
+ except ContinuumError as exc:
30
+ logger.error("fail_queue_item failed for %s: %s", updated, exc)
31
+
32
+
33
+ def _process_row(server: TaskServer, app: Any, row: dict[str, Any]) -> None:
34
+ row_id = UUID(str(row["id"]))
35
+ qid = row["queue_item_id"]
36
+ if isinstance(qid, str):
37
+ qid = UUID(qid)
38
+
39
+ if not heartbeat_claim_or_drop(server, qid):
40
+ return
41
+
42
+ try:
43
+ fetched, etags = fetch_row(app, row)
44
+ except GitHubRetryableError as exc:
45
+ logger.warning("GitHub poll will retry for %s: %s", row_id, exc)
46
+ return
47
+ except GitHubRequestError as exc:
48
+ _fail_row(server, row_id, str(exc), type_name="GitHubRequestError")
49
+ return
50
+ except Exception as exc:
51
+ logger.exception("GitHub poll failed for %s", row_id)
52
+ _fail_row(server, row_id, str(exc), type_name=type(exc).__name__)
53
+ return
54
+
55
+ apply_github_await(server, row_id, fetched, etags)
56
+
57
+
58
+ def poll_github_awaits_tick(server: TaskServer, app: Any) -> None:
59
+ if not db.database_url():
60
+ return
61
+ try:
62
+ rows = db.claim_due(limit=15)
63
+ except Exception:
64
+ logger.exception("claim_due failed")
65
+ return
66
+
67
+ for row in rows:
68
+ try:
69
+ _process_row(server, app, row)
70
+ except Exception:
71
+ logger.exception("process github_await row %s failed", row.get("id"))
72
+
73
+
74
+ def run_github_await_poller(
75
+ server: TaskServer,
76
+ app: Any,
77
+ stop_event: threading.Event,
78
+ *,
79
+ idle_seconds: float = 1.0,
80
+ ) -> None:
81
+ while not stop_event.wait(timeout=idle_seconds):
82
+ poll_github_awaits_tick(server, app)
@@ -0,0 +1,37 @@
1
+ """Register a durable GitHub await for a Continuum queue item."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import logging
6
+ from typing import Any
7
+ from uuid import UUID
8
+
9
+ import continuum_task_server_bundle.github.awaits.db as db
10
+ logger = logging.getLogger(__name__)
11
+
12
+
13
+ def register_await(
14
+ queue_item_id: UUID,
15
+ *,
16
+ kind: str,
17
+ repo_full_name: str,
18
+ number: int | None = None,
19
+ head_sha: str | None = None,
20
+ params: dict[str, Any] | None = None,
21
+ timeout_seconds: float,
22
+ poll_interval_seconds: float,
23
+ ) -> None:
24
+ if not db.database_url():
25
+ raise RuntimeError("DATABASE_URL is not set (required for GitHub awaits)")
26
+ inserted = db.insert_github_await(
27
+ queue_item_id=queue_item_id,
28
+ kind=kind,
29
+ repo_full_name=repo_full_name.strip().lower(),
30
+ number=number,
31
+ head_sha=head_sha,
32
+ params=params or {},
33
+ timeout_seconds=timeout_seconds,
34
+ poll_interval_seconds=poll_interval_seconds,
35
+ )
36
+ if not inserted:
37
+ logger.info("github await already registered for %s (%s)", queue_item_id, kind)
@@ -0,0 +1,70 @@
1
+ """Combine GitHub check runs and commit statuses into one CI snapshot.
2
+
3
+ Pure functions shared by ``get_ci_status`` and ``await_ci``.
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ from typing import Any
9
+
10
+ FAILURE_CONCLUSIONS = {
11
+ "failure",
12
+ "cancelled",
13
+ "timed_out",
14
+ "action_required",
15
+ "startup_failure",
16
+ "stale",
17
+ "error",
18
+ }
19
+
20
+ _STATUS_COMPLETED = {"success", "failure", "error"}
21
+
22
+
23
+ def combine_checks(check_runs: list[dict[str, Any]] | None, statuses: list[dict[str, Any]] | None) -> list[dict[str, Any]]:
24
+ """Normalize check runs and legacy commit statuses into one list."""
25
+ combined: list[dict[str, Any]] = []
26
+ for run in check_runs or []:
27
+ combined.append(
28
+ {
29
+ "name": run.get("name"),
30
+ "source": "check_run",
31
+ "status": run.get("status") or "queued",
32
+ "conclusion": run.get("conclusion"),
33
+ "url": run.get("html_url") or run.get("details_url"),
34
+ }
35
+ )
36
+ for status in statuses or []:
37
+ state = status.get("state") or "pending"
38
+ completed = state in _STATUS_COMPLETED
39
+ combined.append(
40
+ {
41
+ "name": status.get("context"),
42
+ "source": "status",
43
+ "status": "completed" if completed else "pending",
44
+ "conclusion": state if completed else None,
45
+ "url": status.get("target_url"),
46
+ }
47
+ )
48
+ return combined
49
+
50
+
51
+ def summarize_checks(checks: list[dict[str, Any]]) -> str:
52
+ """Return ``pending``, ``success``, ``failure``, or ``no_checks``.
53
+
54
+ ``skipped`` and ``neutral`` conclusions count as success. A check that is
55
+ not ``completed`` keeps the snapshot pending.
56
+ """
57
+ if not checks:
58
+ return "no_checks"
59
+ if any(check.get("status") != "completed" for check in checks):
60
+ return "pending"
61
+ if any((check.get("conclusion") or "") in FAILURE_CONCLUSIONS for check in checks):
62
+ return "failure"
63
+ return "success"
64
+
65
+
66
+ def any_failed(checks: list[dict[str, Any]]) -> bool:
67
+ return any(
68
+ check.get("status") == "completed" and (check.get("conclusion") or "") in FAILURE_CONCLUSIONS
69
+ for check in checks
70
+ )
@@ -0,0 +1,76 @@
1
+ """Normalize GitHub issue comments, review comments, and reviews."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any
6
+
7
+
8
+ def _user_login(obj: dict[str, Any]) -> str | None:
9
+ user = obj.get("user") or {}
10
+ if isinstance(user, dict):
11
+ login = user.get("login")
12
+ return str(login) if login else None
13
+ return None
14
+
15
+
16
+ def _user_id(obj: dict[str, Any]) -> int | None:
17
+ user = obj.get("user") or {}
18
+ if isinstance(user, dict) and user.get("id") is not None:
19
+ return int(user["id"])
20
+ return None
21
+
22
+
23
+ def normalize_issue_comment(comment: dict[str, Any]) -> dict[str, Any]:
24
+ return {
25
+ "id": str(comment.get("id")),
26
+ "kind": "issue_comment",
27
+ "user_login": _user_login(comment),
28
+ "user_id": _user_id(comment),
29
+ "body": comment.get("body") or "",
30
+ "created_at": comment.get("created_at"),
31
+ "updated_at": comment.get("updated_at"),
32
+ "html_url": comment.get("html_url"),
33
+ }
34
+
35
+
36
+ def normalize_review_comment(comment: dict[str, Any]) -> dict[str, Any]:
37
+ reply = comment.get("in_reply_to_id")
38
+ return {
39
+ "id": str(comment.get("id")),
40
+ "kind": "review_comment",
41
+ "user_login": _user_login(comment),
42
+ "user_id": _user_id(comment),
43
+ "body": comment.get("body") or "",
44
+ "created_at": comment.get("created_at"),
45
+ "updated_at": comment.get("updated_at"),
46
+ "html_url": comment.get("html_url"),
47
+ "path": comment.get("path"),
48
+ "line": comment.get("line"),
49
+ "in_reply_to_id": str(reply) if reply is not None else None,
50
+ }
51
+
52
+
53
+ def review_is_public(review: dict[str, Any]) -> bool:
54
+ """Pending reviews are drafts and are not visible to other users."""
55
+ if review.get("state") == "PENDING":
56
+ return False
57
+ return bool(review.get("body") or review.get("state"))
58
+
59
+
60
+ def normalize_review(review: dict[str, Any]) -> dict[str, Any]:
61
+ submitted = review.get("submitted_at") or review.get("created_at")
62
+ return {
63
+ "id": str(review.get("id")),
64
+ "kind": "review",
65
+ "user_login": _user_login(review),
66
+ "user_id": _user_id(review),
67
+ "body": review.get("body") or "",
68
+ "state": review.get("state"),
69
+ "created_at": submitted,
70
+ "updated_at": review.get("submitted_at"),
71
+ "html_url": review.get("html_url"),
72
+ }
73
+
74
+
75
+ def comment_key(comment: dict[str, Any]) -> str:
76
+ return f"{comment.get('kind')}:{comment.get('id')}"
@@ -0,0 +1,52 @@
1
+ """Errors raised while talking to GitHub or reading queue input."""
2
+
3
+ from __future__ import annotations
4
+
5
+
6
+ class GitHubError(Exception):
7
+ """Base error for this task server."""
8
+
9
+
10
+ class InputError(GitHubError):
11
+ """Queue item input is missing or invalid.
12
+
13
+ The handler completes the item (it does not raise) so a workflow can branch
14
+ on ``success: false`` instead of treating the item as killed.
15
+ """
16
+
17
+ def to_output(self) -> dict:
18
+ return {
19
+ "success": False,
20
+ "status": 400,
21
+ "error": str(self),
22
+ "github_message": None,
23
+ }
24
+
25
+
26
+ class GitHubRequestError(GitHubError):
27
+ """GitHub rejected the call (expected 4xx).
28
+
29
+ The handler completes the item with ``success: false`` so deterministic
30
+ workflows can branch. Not raised for rate limits or 5xx.
31
+ """
32
+
33
+ def __init__(self, status: int, message: str, github_message: str | None = None):
34
+ super().__init__(message)
35
+ self.status = status
36
+ self.github_message = github_message if github_message is not None else message
37
+
38
+ def to_output(self) -> dict:
39
+ return {
40
+ "success": False,
41
+ "status": self.status,
42
+ "error": str(self),
43
+ "github_message": self.github_message,
44
+ }
45
+
46
+
47
+ class GitHubRetryableError(GitHubError):
48
+ """Transient GitHub or transport failure. The handler lets this propagate."""
49
+
50
+
51
+ class GitHubUnauthorized(GitHubRetryableError):
52
+ """401 from GitHub. Callers may refresh the installation token and retry once."""