(self, issue_number: int, comment: str, author: str)
| 277 | return {"success": False, "error": str(e)} |
| 278 | |
| 279 | async def add_comment(self, issue_number: int, comment: str, author: str) -> dict: |
| 280 | |
| 281 | if not self._has_auth(): |
| 282 | return {"success": False, "error": "GitHub token not configured"} |
| 283 | |
| 284 | url = f"https://api.github.com/repos/{config.github_repo}/issues/{issue_number}/comments" |
| 285 | |
| 286 | body = f"{comment}\n\n---\n**From:** `{author}`\n\n*Added via Discord*" |
| 287 | |
| 288 | try: |
| 289 | session = await self.get_session() |
| 290 | async with session.post( |
| 291 | url, |
| 292 | json={"body": body}, |
| 293 | headers=await self._get_headers(), |
| 294 | timeout=aiohttp.ClientTimeout(total=10), |
| 295 | ) as response: |
| 296 | if response.status == 201: |
| 297 | logger.info(f"Comment added to issue #{issue_number}") |
| 298 | return { |
| 299 | "success": True, |
| 300 | "issue_url": f"https://github.com/{config.github_repo}/issues/{issue_number}", |
| 301 | } |
| 302 | elif response.status == 403: |
| 303 | error_text = await response.text() |
| 304 | logger.error(f"403 Forbidden adding comment: {error_text[:200]}") |
| 305 | return { |
| 306 | "success": False, |
| 307 | "error": "Permission denied - check bot's GitHub token permissions", |
| 308 | } |
| 309 | elif response.status == 404: |
| 310 | return { |
| 311 | "success": False, |
| 312 | "error": f"Issue #{issue_number} not found", |
| 313 | } |
| 314 | else: |
| 315 | error_text = await response.text() |
| 316 | logger.error(f"Error adding comment: {response.status} - {error_text[:200]}") |
| 317 | return { |
| 318 | "success": False, |
| 319 | "error": f"GitHub API error: {response.status}", |
| 320 | } |
| 321 | except Exception as e: |
| 322 | logger.error(f"Error adding comment: {e}") |
| 323 | return {"success": False, "error": str(e)} |
| 324 | |
| 325 | async def _get_comment(self, comment_id: int) -> dict | None: |
| 326 | """Fetch a comment by ID to verify ownership.""" |
no test coverage detected