Skip to content

Commit 993f2b9

Browse files
committed
fix move from example to sdk
1 parent f398107 commit 993f2b9

File tree

4 files changed

+2044
-310
lines changed

4 files changed

+2044
-310
lines changed

codegen-examples/examples/snapshot_event_handler/event_handlers.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Literal
22
from dotenv import load_dotenv
3-
from fastapi import Depends, FastAPI, Request
3+
from fastapi import FastAPI, Request
44

55
from codegen.extensions.github.types.pull_request import PullRequestLabeledEvent
66
load_dotenv(".env")
@@ -11,9 +11,8 @@
1111
from codegen.extensions.events.codegen_app import CodegenApp
1212
from codegen.extensions.linear.types import LinearEvent
1313
from codegen.extensions.slack.types import SlackEvent
14-
from codegen.git.clients.git_repo_client import GitRepoClient
15-
from codegen.git.schemas.repo_config import RepoConfig
16-
from lib import CodebaseEventsApp, EventRouterAPI
14+
15+
from codegen.extensions.events.modal.base import CodebaseEventsApp, EventRouterMixin
1716
from pr_tasks import lint_for_dev_import_violations, review_with_codegen_agent
1817
from classy_fastapi import Routable, post
1918

@@ -26,7 +25,7 @@
2625

2726

2827
REPO_URL = "https://github.com/codegen-sh/codegen-sdk.git"
29-
COMMIT_ID = "5d8d18eac60ac926d312d1d205c584d9012d078f"
28+
COMMIT_ID = "f398107d31bbd53fc77bc9c5f8763d2dc8fcae5b"
3029

3130
# Create the base image with dependencies
3231
base_image = (
@@ -55,7 +54,8 @@ class CustomEventHandlersAPI(CodebaseEventsApp):
5554
commit: str = modal.parameter(default="79114f67ccfe8700416cd541d1c7c43659a95342")
5655
repo_org: str = modal.parameter(default="codegen-sh")
5756
repo_name: str = modal.parameter(default="Kevin-s-Adventure-Game")
58-
57+
snapshot_index_id: str = SNAPSHOT_DICT_ID
58+
5959
def setup_handlers(self, cg: CodegenApp):
6060
@cg.slack.event("app_mention")
6161
async def handle_mention(event: SlackEvent):
@@ -112,17 +112,18 @@ def handle_issue(event: LinearEvent):
112112

113113

114114
@codegen_events_app.cls(image=base_image, secrets=[modal.Secret.from_dotenv('.env')])
115-
class WebhookEventRouterAPI(EventRouterAPI, Routable):
115+
class WebhookEventRouterAPI(EventRouterMixin, Routable):
116116

117-
def __init__(self):
118-
super().__init__()
117+
snapshot_index_id: str = SNAPSHOT_DICT_ID
118+
119119

120120
def get_event_handler_cls(self):
121121
modal_cls = modal.Cls.from_name(app_name="Events", name="CustomEventHandlersAPI")
122122
return modal_cls
123123

124124
@post("/{org}/{repo}/{provider}/events")
125125
async def handle_event(self, org: str, repo: str, provider: Literal["slack", "github", "linear"], request: Request):
126+
# Define the route for the webhook url sink, it will need to indicate the repo repo org, and the provider
126127
return await super().handle_event(org, repo, provider, request)
127128

128129
@modal.asgi_app()
@@ -134,13 +135,12 @@ def api(self):
134135
return event_api
135136

136137

138+
# Setup a cron job to trigger updates to the codebase snapshots.
137139
@codegen_events_app.function(schedule=modal.Cron("*/10 * * * *"), image=base_image, secrets=[modal.Secret.from_dotenv(".env")])
138140
def refresh_repository_snapshots():
139141
WebhookEventRouterAPI().refresh_repository_snapshots(snapshot_index_id=SNAPSHOT_DICT_ID)
140142

141143

142-
143-
144144
app = modal.App("Events", secrets=[modal.Secret.from_dotenv('.env')])
145145
app.include(event_handlers_app)
146146
app.include(codegen_events_app)

codegen-examples/examples/snapshot_event_handler/lib.py

Lines changed: 0 additions & 226 deletions
This file was deleted.

codegen-examples/examples/snapshot_event_handler/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ dependencies = [
99
"modal>=0.73.72",
1010
"fastapi-restful[all]>=0.6.0",
1111
"classy-fastapi>=0.6.1",
12+
"codegen@git+https://github.com/codegen-sh/codegen-sdk.git@f398107d31bbd53fc77bc9c5f8763d2dc8fcae5b",
1213
]
1314
license = { file = "LICENSE" }
1415
classifiers = [

0 commit comments

Comments
 (0)