Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sweep: add a new webhook endpoint to receive events from Linear. Users should be allowed to tag a linear ticket with the Sweep label and invoke Sweep. #3685

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions sweepai/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.handlers.stack_pr import stack_pr
from sweepai.utils.buttons import (
Expand Down Expand Up @@ -330,14 +331,14 @@ def webhook(
logger.info(f"Received event: {x_github_event}, {action}")
return handle_request(request_dict, event=x_github_event)

@app.post("/jira")
def jira_webhook(
@app.post("/linear")
def linear_webhook(
request_dict: dict = Body(...),
) -> None:
def call_jira_ticket(*args, **kwargs):
thread = threading.Thread(target=handle_jira_ticket, args=args, kwargs=kwargs)
def call_linear_ticket(*args, **kwargs):
thread = threading.Thread(target=handle_linear_ticket, args=args, kwargs=kwargs)
thread.start()
call_jira_ticket(event=request_dict)
call_linear_ticket(event=request_dict)

# Set up cronjob for this
@app.get("/update_sweep_prs_v2")
Expand Down
5 changes: 4 additions & 1 deletion sweepai/config/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,12 @@
DEPLOYMENT_GHA_ENABLED = os.environ.get("DEPLOYMENT_GHA_ENABLED", "true").lower() == "true"

JIRA_USER_NAME = os.environ.get("JIRA_USER_NAME", None)
JIRA_API_TOKEN = os.environ.get("JIRA_API_TOKEN", None)
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)
LINEAR_LABEL_NAME = os.environ.get("LINEAR_LABEL_NAME", "sweep")

SLACK_API_KEY = os.environ.get("SLACK_API_KEY", None)

LICENSE_KEY = os.environ.get("LICENSE_KEY", None)
Expand Down
21 changes: 21 additions & 0 deletions sweepai/handlers/on_linear_ticket.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import os
from typing import Any, Dict

from loguru import logger

LINEAR_LABEL_NAME = os.environ.get("LINEAR_LABEL_NAME", "sweep")

def handle_linear_ticket(event: Dict[str, Any]):
try:
ticket_data = event["data"]
ticket_labels = ticket_data.get("labels", [])

if any(label["name"].lower() == LINEAR_LABEL_NAME.lower() for label in ticket_labels):
logger.info(f"Sweep label detected on Linear ticket {ticket_data['id']}")
# TODO: Implement Sweep workflow logic here
# Reference on_jira_ticket.py for how to process the ticket and kick off Sweep
else:
logger.info(f"Sweep label not found on Linear ticket {ticket_data['id']}")

except Exception as e:
logger.exception(f"Error processing Linear webhook event: {e}")
Loading