Skip to content

Commit 832de9a

Browse files
rushilpatel0github-actions[bot]
authored andcommitted
Automated pre-commit update
1 parent 15ff281 commit 832de9a

File tree

4 files changed

+45
-56
lines changed

4 files changed

+45
-56
lines changed

src/codegen/extensions/clients/linear.py

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
11
import json
22
import logging
3-
import requests
43

4+
import requests
55
from pydantic import BaseModel
66

77
logger = logging.getLogger(__name__)
88

99

1010
# --- TYPES
1111

12+
1213
class LinearUser(BaseModel):
1314
id: str
1415
name: str
1516

17+
1618
class LinearComment(BaseModel):
1719
id: str
1820
body: str
1921
user: LinearUser | None = None
2022

23+
2124
class LinearIssue(BaseModel):
2225
id: str
2326
title: str
@@ -49,12 +52,7 @@ def get_issue(self, issue_id: str) -> LinearIssue:
4952
response = requests.post(self.api_endpoint, headers=self.api_headers, json={"query": query, "variables": variables})
5053
data = response.json()
5154
issue_data = data["data"]["issue"]
52-
return LinearIssue(
53-
id=issue_data["id"],
54-
title=issue_data["title"],
55-
description=issue_data["description"]
56-
)
57-
55+
return LinearIssue(id=issue_data["id"], title=issue_data["title"], description=issue_data["description"])
5856

5957
def get_issue_comments(self, issue_id: str) -> list[LinearComment]:
6058
query = """
@@ -69,7 +67,7 @@ def get_issue_comments(self, issue_id: str) -> list[LinearComment]:
6967
name
7068
}
7169
}
72-
70+
7371
}
7472
}
7573
}
@@ -83,21 +81,13 @@ def get_issue_comments(self, issue_id: str) -> list[LinearComment]:
8381
parsed_comments = []
8482
for comment in comments:
8583
user = comment.get("user", None)
86-
parsed_comment = LinearComment(
87-
id=comment["id"],
88-
body=comment["body"],
89-
user=LinearUser(
90-
id=user.get("id"),
91-
name=user.get("name")
92-
) if user else None
93-
)
84+
parsed_comment = LinearComment(id=comment["id"], body=comment["body"], user=LinearUser(id=user.get("id"), name=user.get("name")) if user else None)
9485
parsed_comments.append(parsed_comment)
9586

9687
# Convert raw comments to LinearComment objects
9788
return parsed_comments
9889

99-
100-
def comment_on_issue(self, issue_id: str, body: str) -> dict:
90+
def comment_on_issue(self, issue_id: str, body: str) -> dict:
10191
"""issue_id is our internal issue ID"""
10292
query = """mutation makeComment($issueId: String!, $body: String!) {
10393
commentCreate(input: {issueId: $issueId, body: $body}) {
@@ -106,7 +96,7 @@ def comment_on_issue(self, issue_id: str, body: str) -> dict:
10696
body
10797
url
10898
user {
109-
id
99+
id
110100
name
111101
}
112102
}
@@ -125,8 +115,8 @@ def comment_on_issue(self, issue_id: str, body: str) -> dict:
125115

126116
return comment_data
127117
except:
128-
raise Exception(f"Error creating comment\n{data}")
129-
118+
msg = f"Error creating comment\n{data}"
119+
raise Exception(msg)
130120

131121
def unregister_webhook(self, webhook_id: str):
132122
mutation = """
@@ -153,18 +143,20 @@ def register_webhook(self, webhook_url: str, team_id: str, secret: str, enabled:
153143
}
154144
"""
155145

156-
variables = {"input": {
157-
"url": webhook_url,
158-
"teamId": team_id,
159-
"resourceTypes": resource_types,
160-
"enabled": enabled,
161-
"secret": secret,
162-
}}
163-
146+
variables = {
147+
"input": {
148+
"url": webhook_url,
149+
"teamId": team_id,
150+
"resourceTypes": resource_types,
151+
"enabled": enabled,
152+
"secret": secret,
153+
}
154+
}
155+
164156
response = requests.post(self.api_endpoint, headers=self.api_headers, json={"query": mutation, "variables": variables})
165157
if response.status_code != 200:
166158
return None
167-
159+
168160
body = response.json()
169-
body = body["data"]["webhookCreate"]["webhook"]['id']
161+
body = body["data"]["webhookCreate"]["webhook"]["id"]
170162
return body

src/codegen/extensions/events/app.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import modal
21
import logging
3-
from codegen.extensions.events.linear import Linear
42

3+
import modal
4+
5+
from codegen.extensions.events.linear import Linear
56

67
logger = logging.getLogger(__name__)
78

89

910
class CodegenApp(modal.App):
10-
1111
linear: Linear
1212

1313
def __init__(self, name, modal_api_key, image: modal.Image):
@@ -19,5 +19,3 @@ def __init__(self, name, modal_api_key, image: modal.Image):
1919

2020
# Expose a attribute that provides the event decorator for different providers.
2121
self.linear = Linear(self)
22-
23-

src/codegen/extensions/events/interface.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
21
from typing import Protocol
2+
33
import modal
44

5+
56
class EventHandlerManagerProtocol(Protocol):
67
def subscribe_handler_to_webhook(self, func_name: str, modal_app: modal.App, event_name):
78
pass
9+
810
def unsubscribe_handler_to_webhook(self, func_name: str, modal_app: modal.App, event_name):
911
pass
1012

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
from typing import TYPE_CHECKING, Callable
2-
from anthropic import BaseModel
31
import functools
2+
import logging
43
import os
4+
from typing import Callable
5+
56
import modal
6-
import logging
7+
from anthropic import BaseModel
78

8-
from codegen.extensions.events.interface import EventHandlerManagerProtocol
99
from codegen.extensions.clients.linear import LinearClient
10-
10+
from codegen.extensions.events.interface import EventHandlerManagerProtocol
1111

1212
logger = logging.getLogger(__name__)
1313

@@ -16,28 +16,24 @@ class RegisteredWebhookHandler(BaseModel):
1616
webhook_id: str | None = None
1717
handler_func: Callable
1818

19+
1920
class Linear(EventHandlerManagerProtocol):
2021
def __init__(self, app: modal.App):
2122
self.app = app
22-
self.access_token= os.environ["LINEAR_ACCESS_TOKEN"] # move to extensions config.
23+
self.access_token = os.environ["LINEAR_ACCESS_TOKEN"] # move to extensions config.
2324
self.signing_secret = os.environ["LINEAR_SIGNING_SECRET"]
2425
self.linear_team_id = os.environ["LINEAR_TEAM_ID"]
2526
self.registered_handlers = {}
2627

2728
def subscribe_handler_to_webhook(self, web_url: str, event_name: str):
2829
client = LinearClient(access_token=self.access_token)
2930

30-
result = client.register_webhook(
31-
team_id=self.linear_team_id,
32-
webhook_url=web_url,
33-
enabled=True,
34-
resource_types=[event_name],
35-
secret=self.signing_secret)
31+
result = client.register_webhook(team_id=self.linear_team_id, webhook_url=web_url, enabled=True, resource_types=[event_name], secret=self.signing_secret)
3632
return result
37-
33+
3834
def unsubscribe_handler_to_webhook(self, registered_handler: RegisteredWebhookHandler):
3935
webhook_id = registered_handler.webhook_id
40-
36+
4137
client = LinearClient(access_token=self.access_token)
4238
if webhook_id:
4339
print(f"Unsubscribing from webhook {webhook_id}")
@@ -46,20 +42,19 @@ def unsubscribe_handler_to_webhook(self, registered_handler: RegisteredWebhookHa
4642
else:
4743
print("No webhook id found for handler")
4844
return None
45+
4946
def unsubscribe_all_handlers(self):
5047
for handler in self.registered_handlers:
5148
self.unsubscribe_handler_to_webhook(self.registered_handlers[handler])
5249

53-
54-
5550
def event(self, event_name):
56-
"""
57-
Decorator for registering an event handler.
51+
"""Decorator for registering an event handler.
5852
5953
:param event_name: The name of the event to handle.
6054
:param register_hook: An optional function to call during registration,
6155
e.g., to make an API call to register the webhook.
6256
"""
57+
6358
def decorator(func):
6459
# Register the handler with the app's registry.
6560
modal_ready_func = func
@@ -71,9 +66,11 @@ def decorator(func):
7166

7267
webhook_id = self.subscribe_handler_to_webhook(web_url=web_url, event_name=event_name)
7368
self.registered_handlers[func_name].webhook_id = webhook_id
69+
7470
@functools.wraps(func)
7571
def wrapper(*args, **kwargs):
7672
return func(*args, **kwargs)
73+
7774
return wrapper
78-
75+
7976
return decorator

0 commit comments

Comments
 (0)