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. #3687

Open
wants to merge 3 commits 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
14 changes: 12 additions & 2 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.utils.buttons import (
check_button_activated,
Expand Down Expand Up @@ -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)

Expand Down
6 changes: 4 additions & 2 deletions sweepai/config/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(",")
Expand Down Expand Up @@ -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"
34 changes: 34 additions & 0 deletions sweepai/handlers/on_linear_ticket.py
Original file line number Diff line number Diff line change
@@ -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")
Loading