mirror of
https://github.com/Sea-Haven-Industries/open-swe.git
synced 2026-09-30 20:53:15 +00:00
58 lines
1.5 KiB
Python
58 lines
1.5 KiB
Python
"""Linear API utilities."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
import os
|
|
|
|
import httpx
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
LINEAR_API_KEY = os.environ.get("LINEAR_API_KEY", "")
|
|
|
|
|
|
async def comment_on_linear_issue(issue_id: str, comment_body: str) -> bool:
|
|
"""Add a comment to a Linear issue.
|
|
|
|
Args:
|
|
issue_id: The Linear issue ID
|
|
comment_body: The comment text
|
|
|
|
Returns:
|
|
True if successful, False otherwise
|
|
"""
|
|
if not LINEAR_API_KEY:
|
|
return False
|
|
|
|
url = "https://api.linear.app/graphql"
|
|
|
|
mutation = """
|
|
mutation CommentCreate($issueId: String!, $body: String!) {
|
|
commentCreate(input: { issueId: $issueId, body: $body }) {
|
|
success
|
|
comment {
|
|
id
|
|
}
|
|
}
|
|
}
|
|
"""
|
|
|
|
async with httpx.AsyncClient() as http_client:
|
|
try:
|
|
response = await http_client.post(
|
|
url,
|
|
headers={
|
|
"Authorization": LINEAR_API_KEY,
|
|
"Content-Type": "application/json",
|
|
},
|
|
json={
|
|
"query": mutation,
|
|
"variables": {"issueId": issue_id, "body": comment_body},
|
|
},
|
|
)
|
|
response.raise_for_status()
|
|
result = response.json()
|
|
return bool(result.get("data", {}).get("commentCreate", {}).get("success"))
|
|
except Exception: # noqa: BLE001
|
|
return False
|