Files

55 lines
1.6 KiB
Python

import os
import json
from google.cloud import pubsub_v1
def publish_issue_ready_for_code(
owner: str, repo: str, issue_number: int, workable_spec: dict
) -> None:
"""
Publishes an issue-ready-for-code event to Pub/Sub to trigger the
downstream Code Generation Workflow.
Args:
owner: GitHub repository owner name.
repo: GitHub repository name.
issue_number: GitHub issue number.
workable_spec: Structured Workable Spec dictionary generated by triage.
"""
project_id = os.environ.get("PROJECT_ID")
topic_id = os.environ.get("READY_FOR_CODE_TOPIC_ID")
if not project_id:
print("[WORKER] Warning: Missing PROJECT_ID, skipping ready-for-code event.")
return
if not topic_id:
print(
"[WORKER] Warning: Missing READY_FOR_CODE_TOPIC_ID, "
"skipping ready-for-code event."
)
return
payload = {
"github_metadata": {
"owner": owner,
"repo": repo,
"issue_number": issue_number,
},
"workable_spec": workable_spec,
}
try:
publisher = pubsub_v1.PublisherClient()
topic_path = publisher.topic_path(project_id, topic_id)
data = json.dumps(payload).encode("utf-8")
future = publisher.publish(topic_path, data)
message_id = future.result()
print(
f"[WORKER] Published ready-for-code event to Pub/Sub ({topic_id}). "
f"Message ID: {message_id}"
)
except Exception as e:
print(f"[WORKER] Error publishing ready-for-code event to Pub/Sub: {e}")
raise