Skip to content

Commit 7903a9e

Browse files
authored
GitHub Webhook Fix (#765)
1 parent cb2329e commit 7903a9e

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

codegen-examples/examples/github_checks/README.md

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Github Checks
22

3-
This application is a GitHub integration that analyzes import cycles in Python codebases. It automatically runs when a pull request is labeled and checks for potentially problematic import patterns in the modified codebase.
3+
This application is a GitHub integration that analyzes import cycles in codebases. It automatically runs when a pull request is labeled and checks for potentially problematic import patterns in the modified codebase.
44

55
## Features
66

7-
- Analyzes import relationships in Python codebases
7+
- Analyzes import relationships in codebases
88
- Detects circular import dependencies
99
- Identifies problematic cycles with mixed static and dynamic imports
1010
- Automatically comments on pull requests with detailed analysis
@@ -48,19 +48,20 @@ This application is a GitHub integration that analyzes import cycles in Python c
4848
1. Results are posted as a comment on the pull request
4949

5050
```python
51+
message = ["### Import Cycle Analysis - GitHub Check\n"]
52+
5153
if problematic_loops:
52-
message.append("\n### ⚠️ Problematic Import Cycles")
53-
message.append("(Cycles with mixed static and dynamic imports)")
54-
for i, cycle in enumerate(problematic_loops, 1):
55-
message.append(f"\n#### Problematic Cycle #{i}")
56-
message.append("Mixed imports:")
57-
for (from_file, to_file), imports in cycle["mixed_imports"].items():
58-
message.append(f"\nFrom: `{from_file}`")
59-
message.append(f"To: `{to_file}`")
60-
message.append(f"- Static imports: {imports['static']}")
61-
message.append(f"- Dynamic imports: {imports['dynamic']}")
62-
63-
create_pr_comment(codebase, event.pull_request, number, "\n".join(message))
54+
message.append("\n### ⚠️ Potentially Problematic Import Cycles")
55+
message.append("Cycles with mixed static and dynamic imports, which might recquire attention.")
56+
for i, cycle in enumerate(problematic_loops, 1):
57+
message.append(f"\n#### Problematic Cycle {i}")
58+
for (from_file, to_file), imports in cycle["mixed_imports"].items():
59+
message.append(f"\nFrom: `{from_file}`")
60+
message.append(f"To: `{to_file}`")
61+
message.append(f"- Static imports: {imports['static']}")
62+
message.append(f"- Dynamic imports: {imports['dynamic']}")
63+
else:
64+
message.append("\nNo problematic import cycles found! 🎉")
6465
```
6566

6667
## Setup
@@ -75,14 +76,17 @@ This application is a GitHub integration that analyzes import cycles in Python c
7576

7677
1. Set up your environment variables in a `.env` file
7778

78-
- `GITHUB_TOKEN`: Your GitHub token, configured with `repo` and `workflow` scopes
79+
- `GITHUB_TOKEN`: Your GitHub token, configured with `repo` and `workflow` scopes.
7980

8081
1. Deploy the app using Modal:
8182

8283
```bash
8384
modal deploy app.py
8485
```
8586

87+
- After deployment, configure your GitHub App's webhook URL in its developer settings to point to your Modal endpoint with the endpoint `/github/events`
88+
- The app will analyze imports via the Modal deployment whenever a pull request receives a `Codegen` label
89+
8690
## Technical Details
8791

8892
The application uses Codegen to parse the codebase and a combination of NetworkX and Codegen to analyze the import relationships. The app is structured as a Modal App with a FastAPI server.

codegen-examples/examples/github_checks/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def handle_pr(event: PullRequestLabeledEvent):
144144
)
145145
)
146146

147-
app = modal.App("codegen-test")
147+
app = modal.App("codegen-import-cycles-github-check")
148148

149149

150150
@app.function(image=base_image, secrets=[modal.Secret.from_dotenv()])

0 commit comments

Comments
 (0)