diff --git a/sweepai/api.py b/sweepai/api.py index e30f68765b..1d84529796 100644 --- a/sweepai/api.py +++ b/sweepai/api.py @@ -57,6 +57,7 @@ ) from sweepai.handlers.on_comment import on_comment from sweepai.handlers.on_jira_ticket import handle_jira_ticket +from sweepai.handlers.on_linear_ticket import handle_linear_ticket from sweepai.handlers.on_ticket import on_ticket from sweepai.utils.buttons import ( check_button_activated, @@ -333,13 +334,22 @@ def call_jira_ticket(*args, **kwargs): thread.start() call_jira_ticket(event=request_dict) -# Set up cronjob for this +@app.post("/linear") +def linear_webhook( + request_dict: dict = Body(...), +) -> None: + def call_linear_ticket(*args, **kwargs): + thread = threading.Thread(target=handle_linear_ticket, args=args, kwargs=kwargs) + thread.start() + call_linear_ticket(event=request_dict) + +# Set up cronjob for this @app.get("/update_sweep_prs_v2") def update_sweep_prs_v2(repo_full_name: str, installation_id: int): # Get a Github client _, g = get_github_client(installation_id) - # Get the repository + # Get the repository repo = g.get_repo(repo_full_name) config = SweepConfig.get_config(repo) diff --git a/sweepai/config/server.py b/sweepai/config/server.py index 5141c20992..31030fd2f7 100644 --- a/sweepai/config/server.py +++ b/sweepai/config/server.py @@ -160,7 +160,7 @@ ENV = "prod" if GITHUB_BOT_USERNAME != TEST_BOT_NAME else "dev" PROGRESS_BASE_URL = os.environ.get( - "PROGRESS_BASE_URL", "https://progress.sweep.dev" + "PROGRESS_BASE_URL", "https://progress.sweep.dev" ).rstrip("/") DISABLED_REPOS = os.environ.get("DISABLED_REPOS", "").split(",") @@ -200,7 +200,9 @@ JIRA_API_TOKEN = os.environ.get("JIRA_API_TOKEN", None) JIRA_URL = os.environ.get("JIRA_URL", None) +LINEAR_API_KEY = os.environ.get("LINEAR_API_KEY", None) + SLACK_API_KEY = os.environ.get("SLACK_API_KEY", None) -LICENSE_KEY = os.environ.get("LICENSE_KEY", None) +LICENSE_KEY = os.environ.get("LICENSE_KEY", None) ALTERNATE_AWS = os.environ.get("ALTERNATE_AWS", "none").lower() == "true" \ No newline at end of file diff --git a/sweepai/handlers/on_linear_ticket.py b/sweepai/handlers/on_linear_ticket.py new file mode 100644 index 0000000000..f7ff86c156 --- /dev/null +++ b/sweepai/handlers/on_linear_ticket.py @@ -0,0 +1,34 @@ +from typing import Dict + +from sweepai.utils.event_logger import logger + +def handle_linear_ticket(event: Dict): + """Handle a Linear ticket event.""" + logger.info(f"Received Linear ticket event: {event}") + + # Extract relevant information from the event payload + ticket_id = event["data"]["id"] + + + + # Check if the ticket has the "Sweep" label + has_sweep_label = any(label["name"] == "Sweep" for label in event["data"]["labels"]["nodes"]) + + if has_sweep_label: + # Invoke the Sweep workflow for the Linear ticket + logger.info(f"Linear ticket {ticket_id} has the Sweep label, invoking Sweep workflow") + from sweepai.handlers.on_ticket import on_ticket + + ticket_description = event["data"]["description"] + on_ticket( + title=f"Linear Ticket {ticket_id}: {event['data']['title']}", + summary=ticket_description, + issue_number=ticket_id, + issue_url=event["url"], + username=event["data"]["creator"]["name"], + repo_full_name="linear_repo", # Get repo name from Linear ticket + repo_description="", + installation_id=0, # Map Linear user to GitHub installation ID + ) + else: + logger.info(f"Linear ticket {ticket_id} does not have the Sweep label, ignoring") \ No newline at end of file