Skip to content

Commit 6c303a1

Browse files
Fix formatting issues to pass pre-commit checks
1 parent 07c2fa0 commit 6c303a1

File tree

97 files changed

+6219
-5813
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+6219
-5813
lines changed

PLAN/PLAN.md

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,48 @@
11
# Project Plan for codegen
22

33
## Overview
4+
45
This project plan outlines the development roadmap for codegen.
56

67
## Objectives
8+
79
- Define project scope and requirements
810
- Create implementation plan
911
- Set milestones and deliverables
1012
- Assign responsibilities
1113

1214
## Requirements
15+
1316
- [Requirement 1]
1417
- [Requirement 2]
1518
- [Requirement 3]
1619

1720
## Implementation Plan
21+
1822
- [Step 1]
1923
- [Step 2]
2024
- [Step 3]
2125

2226
## Timeline
23-
- [Milestone 1]: [Date]
24-
- [Milestone 2]: [Date]
25-
- [Milestone 3]: [Date]
27+
28+
-
29+
-
30+
-
2631

2732
## Resources
33+
2834
- [Resource 1]
2935
- [Resource 2]
3036
- [Resource 3]
3137

3238
## Risks and Mitigations
33-
- [Risk 1]: [Mitigation Strategy]
34-
- [Risk 2]: [Mitigation Strategy]
35-
- [Risk 3]: [Mitigation Strategy]
39+
40+
- \[Risk 1\]: [Mitigation Strategy]
41+
- \[Risk 2\]: [Mitigation Strategy]
42+
- \[Risk 3\]: [Mitigation Strategy]
3643

3744
## Team
38-
- [Team Member 1]: [Role]
39-
- [Team Member 2]: [Role]
40-
- [Team Member 3]: [Role]
45+
46+
-
47+
-
48+
-

codegen-examples/examples/linear_webhooks/README.md

Lines changed: 71 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,136 +1,135 @@
11
# Linear Webhooks Example
22

3-
This example demonstrates how to set up a webhook handler for Linear events using the Codegen SDK and Modal. The webhook handler can process events from Linear such as issue creation, updates, comments, and more.
3+
This example demonstrates how to handle Linear webhook events using the Codegen SDK and Modal. It provides a simple webhook handler that processes different types of Linear events, such as Issue and Comment events.
4+
5+
## Features
6+
7+
- Receive and process Linear webhook events
8+
- Handle specific event types (Issues, Comments)
9+
- Deploy as a serverless application using Modal
10+
- Secure webhook verification using Linear's signing secret
411

512
## Prerequisites
613

7-
- [Modal](https://modal.com/) account
8-
- [Linear](https://linear.app/) account with admin access
914
- Python 3.13 or higher
15+
- A Linear account with admin access
16+
- A Modal account (for deployment)
17+
- Codegen SDK (version 0.26.3 or higher)
1018

1119
## Setup
1220

13-
### 1. Install Dependencies
21+
### 1. Clone the Repository
1422

1523
```bash
16-
# Clone the repository
17-
git clone https://github.com/Zeeeepa/codegen.git
18-
cd codegen/codegen-examples/examples/linear_webhooks
19-
20-
# Install dependencies
21-
pip install -e .
24+
git clone https://github.com/your-username/your-repo.git
25+
cd your-repo/examples/linear_webhooks
2226
```
2327

24-
### 2. Configure Environment Variables
25-
26-
Copy the `.env.template` file to `.env` and fill in your credentials:
28+
### 2. Create a Virtual Environment
2729

2830
```bash
29-
cp .env.template .env
31+
python -m venv venv
32+
source venv/bin/activate # On Windows: venv\Scripts\activate
3033
```
3134

32-
Edit the `.env` file with your Linear API credentials:
35+
### 3. Install Dependencies
3336

34-
```
35-
LINEAR_ACCESS_TOKEN="your_linear_api_token"
36-
LINEAR_SIGNING_SECRET="your_linear_webhook_signing_secret"
37-
LINEAR_TEAM_ID="your_linear_team_id"
38-
MODAL_API_KEY="your_modal_api_key" # Optional
37+
```bash
38+
pip install -e ".[dev]"
3939
```
4040

41-
To get these credentials:
41+
### 4. Set Up Environment Variables
4242

43-
- **LINEAR_ACCESS_TOKEN**: Go to Linear → Settings → API → Create Key
44-
- **LINEAR_SIGNING_SECRET**: Created when you set up a webhook in Linear
45-
- **LINEAR_TEAM_ID**: Found in Linear team settings or via the API
46-
- **MODAL_API_KEY**: Your Modal API key (if not using Modal CLI authentication)
43+
Create a `.env` file in the project root with the following variables:
4744

48-
### 3. Authenticate with Modal
49-
50-
```bash
51-
modal token new
45+
```
46+
LINEAR_API_KEY=your_linear_api_key
47+
LINEAR_SIGNING_SECRET=your_linear_webhook_signing_secret
48+
MODAL_API_KEY=your_modal_api_key
5249
```
5350

54-
## Deployment Commands
51+
You can get your Linear API key from the Linear dashboard under Settings > API > Personal API Keys.
5552

56-
### Deploy to Modal
53+
## Local Development
54+
55+
For local development and testing, you can run the webhook handler locally:
5756

5857
```bash
59-
# Deploy the webhook handler to Modal
6058
python webhooks.py
6159
```
6260

63-
This will deploy the webhook handler to Modal and provide you with a URL that you can use to configure the webhook in Linear.
61+
This will start a local server that you can use for testing. However, for Linear to send webhooks to your local machine, you'll need to use a tool like ngrok to expose your local server to the internet.
6462

65-
### Get Deployment Status
63+
## Deployment
6664

67-
```bash
68-
# Check the status of your Modal deployment
69-
modal app status linear-webhooks
70-
```
65+
### Deploy to Modal
7166

72-
### View Logs
67+
To deploy the webhook handler to Modal, run:
7368

7469
```bash
75-
# View logs from your Modal deployment
76-
modal app logs linear-webhooks
70+
modal deploy webhooks.py
7771
```
7872

79-
### Update Deployment
73+
This will deploy the webhook handler to Modal and provide you with a URL that you can use to configure the Linear webhook.
74+
75+
### Update the Deployment
76+
77+
To update an existing deployment:
8078

8179
```bash
82-
# Update your Modal deployment after making changes
83-
python webhooks.py
80+
modal deploy webhooks.py
8481
```
8582

86-
### Stop Deployment
83+
### Stop the Deployment
84+
85+
To stop the deployment:
8786

8887
```bash
89-
# Stop your Modal deployment
9088
modal app stop linear-webhooks
9189
```
9290

9391
## Configuring Linear Webhooks
9492

9593
1. Go to Linear → Settings → API → Webhooks
96-
2. Click "New Webhook"
97-
3. Enter the URL provided by Modal when you deployed the webhook handler
98-
4. Select the events you want to receive (e.g., Issues, Comments)
99-
5. Copy the signing secret and add it to your `.env` file as `LINEAR_SIGNING_SECRET`
100-
6. Click "Create Webhook"
94+
1. Click "New Webhook"
95+
1. Enter the URL provided by Modal when you deployed the webhook handler
96+
1. Select the events you want to receive (e.g., Issues, Comments)
97+
1. Copy the signing secret and add it to your `.env` file as `LINEAR_SIGNING_SECRET`
98+
1. Click "Create Webhook"
10199

102100
## Customizing Event Handlers
103101

104-
The example includes handlers for Issue and Comment events. You can customize these handlers or add new ones by modifying the `webhooks.py` file:
102+
You can customize the event handlers in `webhooks.py` to handle different types of Linear events. The example includes handlers for Issue and Comment events, but you can add handlers for other event types as well.
103+
104+
To add a new event handler, add a new method to the `LinearEventHandlers` class and decorate it with `@app.linear.event("EventType")`:
105105

106106
```python
107-
@modal.web_endpoint(method="POST")
108-
@app.linear.event("YourEventType")
109-
def handle_your_event(self, event: LinearEvent):
107+
@app.linear.event("Project")
108+
def handle_project(self, event: LinearEvent):
109+
"""Handle Linear Project events"""
110+
logger.info(f"Received Linear Project event: {event.action}")
110111
# Process the event
111-
return {"status": "success"}
112+
return {"status": "success", "message": f"Processed Linear Project event: {event.action}"}
112113
```
113114

114-
## Available Event Types
115-
116-
Linear supports the following event types:
117-
118-
- `Issue`
119-
- `Comment`
120-
- `Project`
121-
- `Cycle`
122-
- `Reaction`
123-
- And more...
115+
## Event Types
124116

125-
Refer to the [Linear API documentation](https://developers.linear.app/docs/graphql/webhooks) for a complete list of event types.
117+
Linear supports various event types, including:
126118

127-
## Troubleshooting
119+
- Issue
120+
- Comment
121+
- Project
122+
- Cycle
123+
- Team
124+
- User
125+
- Attachment
126+
- Reaction
127+
- Label
128+
- State
128129

129-
- **Webhook not receiving events**: Verify that your Linear webhook is configured correctly and that the URL is accessible.
130-
- **Authentication errors**: Check that your LINEAR_ACCESS_TOKEN and LINEAR_SIGNING_SECRET are correct.
131-
- **Modal deployment issues**: Run `modal app logs linear-webhooks` to view logs and diagnose issues.
130+
Refer to the [Linear API documentation](https://developers.linear.app/docs/graphql/webhooks) for a complete list of event types and their payloads.
132131

133-
## Additional Resources
132+
## Resources
134133

135134
- [Codegen Documentation](https://docs.codegen.sh/)
136135
- [Modal Documentation](https://modal.com/docs)
Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
[project]
2-
name = "linear-webhook-example"
2+
name = "linear-webhooks"
33
version = "0.1.0"
44
description = "Linear webhook example for Codegen"
55
requires-python = ">=3.13"
66
dependencies = [
7-
"codegen>=0.26.3",
8-
"modal>=0.73.25",
9-
"fastapi>=0.110.0",
10-
"uvicorn>=0.27.0",
11-
"pydantic>=2.0.0"
7+
"codegen>=0.26.3",
8+
"modal>=0.73.25",
9+
"fastapi>=0.110.0",
10+
"uvicorn>=0.27.0",
11+
"pydantic>=2.0.0",
1212
]
1313

1414
[project.optional-dependencies]
15-
dev = [
16-
"black>=23.0.0",
17-
"isort>=5.12.0",
18-
"mypy>=1.0.0",
19-
"ruff>=0.0.270"
20-
]
15+
dev = ["black>=23.0.0", "isort>=5.12.0", "mypy>=1.0.0", "ruff>=0.0.270"]
2116

0 commit comments

Comments
 (0)