PlanOpticon

planopticon / video_processor / agent / skills / github_integration.py
Source Blame History 93 lines
0981a08… noreply 1 """Skill: Generate GitHub issues from task breakdown artifacts."""
0981a08… noreply 2
0981a08… noreply 3 import json
0981a08… noreply 4 import shutil
0981a08… noreply 5 import subprocess
0981a08… noreply 6 from typing import List, Optional
0981a08… noreply 7
0981a08… noreply 8 from video_processor.agent.skills.base import AgentContext, Artifact, Skill, register_skill
0981a08… noreply 9
0981a08… noreply 10
0981a08… noreply 11 def _task_to_issue(task: dict) -> dict:
0981a08… noreply 12 """Convert a task dict to a GitHub issue object."""
0981a08… noreply 13 deps = task.get("dependencies", [])
0981a08… noreply 14 body_parts = [
0981a08… noreply 15 f"## Description\n{task.get('description', task.get('title', ''))}",
0981a08… noreply 16 f"**Priority:** {task.get('priority', 'medium')}",
0981a08… noreply 17 f"**Estimate:** {task.get('estimate', 'unknown')}",
0981a08… noreply 18 ]
0981a08… noreply 19 if deps:
0981a08… noreply 20 body_parts.append(f"**Dependencies:** {', '.join(str(d) for d in deps)}")
0981a08… noreply 21 labels = [task.get("priority", "medium")]
0981a08… noreply 22 if task.get("labels"):
0981a08… noreply 23 labels.extend(task["labels"])
0981a08… noreply 24 return {
0981a08… noreply 25 "title": task.get("title", "Untitled task"),
0981a08… noreply 26 "body": "\n\n".join(body_parts),
0981a08… noreply 27 "labels": labels,
0981a08… noreply 28 }
0981a08… noreply 29
0981a08… noreply 30
0981a08… noreply 31 def push_to_github(issues_json: str, repo: str) -> Optional[List[dict]]:
0981a08… noreply 32 """Shell out to `gh issue create` for each issue. Returns None if gh unavailable."""
0981a08… noreply 33 if not shutil.which("gh"):
0981a08… noreply 34 return None
0981a08… noreply 35 issues = json.loads(issues_json)
0981a08… noreply 36 results = []
0981a08… noreply 37 for issue in issues:
0981a08… noreply 38 cmd = [
0981a08… noreply 39 "gh",
0981a08… noreply 40 "issue",
0981a08… noreply 41 "create",
0981a08… noreply 42 "--repo",
0981a08… noreply 43 repo,
0981a08… noreply 44 "--title",
0981a08… noreply 45 issue["title"],
0981a08… noreply 46 "--body",
0981a08… noreply 47 issue["body"],
0981a08… noreply 48 ]
0981a08… noreply 49 for label in issue.get("labels", []):
0981a08… noreply 50 cmd.extend(["--label", label])
0981a08… noreply 51 proc = subprocess.run(cmd, capture_output=True, text=True)
0981a08… noreply 52 results.append(
0981a08… noreply 53 {
0981a08… noreply 54 "title": issue["title"],
0981a08… noreply 55 "returncode": proc.returncode,
0981a08… noreply 56 "stdout": proc.stdout.strip(),
0981a08… noreply 57 "stderr": proc.stderr.strip(),
0981a08… noreply 58 }
0981a08… noreply 59 )
0981a08… noreply 60 return results
0981a08… noreply 61
0981a08… noreply 62
0981a08… noreply 63 class GitHubIssuesSkill(Skill):
0981a08… noreply 64 name = "github_issues"
0981a08… noreply 65 description = "Generate GitHub issues from task breakdown"
0981a08… noreply 66
0981a08… noreply 67 def execute(self, context: AgentContext, **kwargs) -> Artifact:
0981a08… noreply 68 task_artifact = next((a for a in context.artifacts if a.artifact_type == "task_list"), None)
0981a08… noreply 69 if task_artifact:
0981a08… noreply 70 tasks = json.loads(task_artifact.content)
0981a08… noreply 71 else:
0981a08… noreply 72 # Generate minimal task list inline from planning entities
0981a08… noreply 73 tasks = [
0981a08… noreply 74 {
0981a08… noreply 75 "title": str(e),
0981a08… noreply 76 "description": str(e),
0981a08… noreply 77 "priority": "medium",
0981a08… noreply 78 "estimate": "unknown",
0981a08… noreply 79 }
0981a08… noreply 80 for e in context.planning_entities
0981a08… noreply 81 ]
0981a08… noreply 82
0981a08… noreply 83 issues = [_task_to_issue(t) for t in tasks]
0981a08… noreply 84 content = json.dumps(issues, indent=2)
0981a08… noreply 85 return Artifact(
0981a08… noreply 86 name="GitHub Issues",
0981a08… noreply 87 content=content,
0981a08… noreply 88 artifact_type="issues",
0981a08… noreply 89 format="json",
0981a08… noreply 90 )
0981a08… noreply 91
0981a08… noreply 92
0981a08… noreply 93 register_skill(GitHubIssuesSkill())

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button