Skip to content

Fix type error in Linear webhooks example #129

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

Draft
wants to merge 2 commits into
base: codegen-bot/update-linear-webhooks-example
Choose a base branch
from
Draft
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
28 changes: 19 additions & 9 deletions codegen-examples/examples/linear_webhooks/webhooks.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import modal
from codegen.extensions.events.app import CodegenApp
from codegen.extensions.linear.types import LinearEvent
from codegen.extensions.linear.types import LinearEvent, LinearIssue, LinearComment
from codegen.shared.logging.get_logger import get_logger

logger = get_logger(__name__)
Expand Down Expand Up @@ -34,14 +34,23 @@ def handle_issue(self, event: LinearEvent):

This endpoint will be triggered when an issue is created, updated, or deleted in Linear.
"""
logger.info(f"Received Linear Issue event: {event.action} - {event.data.title}")
# Process the event data as needed
return {
"status": "success",
"message": f"Processed Linear Issue event: {event.action}",
"issue_id": event.data.id,
"issue_title": event.data.title
}
# Check if the data is an Issue before accessing title
if isinstance(event.data, LinearIssue):
issue_title = event.data.title
logger.info(f"Received Linear Issue event: {event.action} - {issue_title}")
return {
"status": "success",
"message": f"Processed Linear Issue event: {event.action}",
"issue_id": event.data.id,
"issue_title": issue_title
}
else:
logger.warning(f"Received non-Issue data for Issue event: {event.action}")
return {
"status": "warning",
"message": f"Received non-Issue data for Issue event: {event.action}",
"id": event.data.id
}

@modal.web_endpoint(method="POST")
@app.linear.event("Comment")
Expand All @@ -61,3 +70,4 @@ def handle_comment(self, event: LinearEvent):
# If running this file directly, this will deploy the app to Modal
if __name__ == "__main__":
app.serve()