Skip to content

GitHub Webhook Fix #765

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

Merged
merged 2 commits into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
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
34 changes: 19 additions & 15 deletions codegen-examples/examples/github_checks/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Github Checks

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.
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.

## Features

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

```python
message = ["### Import Cycle Analysis - GitHub Check\n"]

if problematic_loops:
message.append("\n### ⚠️ Problematic Import Cycles")
message.append("(Cycles with mixed static and dynamic imports)")
for i, cycle in enumerate(problematic_loops, 1):
message.append(f"\n#### Problematic Cycle #{i}")
message.append("Mixed imports:")
for (from_file, to_file), imports in cycle["mixed_imports"].items():
message.append(f"\nFrom: `{from_file}`")
message.append(f"To: `{to_file}`")
message.append(f"- Static imports: {imports['static']}")
message.append(f"- Dynamic imports: {imports['dynamic']}")

create_pr_comment(codebase, event.pull_request, number, "\n".join(message))
message.append("\n### ⚠️ Potentially Problematic Import Cycles")
message.append("Cycles with mixed static and dynamic imports, which might recquire attention.")
for i, cycle in enumerate(problematic_loops, 1):
message.append(f"\n#### Problematic Cycle {i}")
for (from_file, to_file), imports in cycle["mixed_imports"].items():
message.append(f"\nFrom: `{from_file}`")
message.append(f"To: `{to_file}`")
message.append(f"- Static imports: {imports['static']}")
message.append(f"- Dynamic imports: {imports['dynamic']}")
else:
message.append("\nNo problematic import cycles found! 🎉")
```

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

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

- `GITHUB_TOKEN`: Your GitHub token, configured with `repo` and `workflow` scopes
- `GITHUB_TOKEN`: Your GitHub token, configured with `repo` and `workflow` scopes.

1. Deploy the app using Modal:

```bash
modal deploy app.py
```

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

## Technical Details

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.
Expand Down
2 changes: 1 addition & 1 deletion codegen-examples/examples/github_checks/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def handle_pr(event: PullRequestLabeledEvent):
)
)

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


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