Skip to content

Conversation

@codegen-sh
Copy link

@codegen-sh codegen-sh bot commented Mar 23, 2025

Changes

This PR fixes issues with the Linear webhooks and other examples:

  1. Fixed import errors:

    • Changed from codegen.extensions.events.app import CodegenApp to from codegen.extensions.events.codegen_app import CodegenApp
    • This reflects the current structure of the codebase
  2. Fixed initialization errors:

    • Removed unsupported parameters (modal_api_key and image) from the CodegenApp initialization
    • The current CodegenApp class doesn't accept these parameters
  3. Added a standalone version for the Linear webhooks example:

    • Created standalone.py that can be run without Modal
    • Added comprehensive documentation with setup instructions
    • Added requirements.txt file
  4. Updated .env.template with the Zeeeepa team ID

These changes make it easier to get started with the examples, especially for users who want to run them locally without Modal.

Affected files

  • codegen-examples/examples/linear_webhooks/webhooks.py
  • codegen-examples/examples/linear_webhooks/standalone.py (new)
  • codegen-examples/examples/linear_webhooks/requirements.txt (new)
  • codegen-examples/examples/linear_webhooks/README.md (new)
  • codegen-examples/examples/linear_webhooks/.env.template
  • codegen-examples/examples/ticket-to-pr/app.py
  • codegen-examples/examples/pr_review_bot/app.py

Comment on lines +28 to +31
print(f"Error: Missing required environment variables: {', '.join(missing_vars)}")
print("Please create a .env file with the following variables:")
print("\n".join([f"{var}=\"your_{var.lower()}\"" for var in required_vars]))
exit(1)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using print statements for error handling and exit(1) to terminate the application is not recommended for production environments. It's better to use a logging framework for error messages, which offers more flexibility and control over how messages are recorded and viewed. Additionally, consider handling missing environment variables more gracefully by using exceptions or a dedicated error handling mechanism.

Recommended Change:
Replace print statements with logging and consider using exceptions for error handling:

import logging
logging.error(f"Missing required environment variables: {', '.join(missing_vars)}")
raise EnvironmentError("Required environment variables are missing")

print("Listening for Linear events at: http://0.0.0.0:8000/linear/events")
print("Use a tool like ngrok to expose this endpoint to the internet.")
print("Then configure your Linear webhook to point to: https://your-ngrok-url/linear/events")
uvicorn.run(fastapi_app, host="0.0.0.0", port=8000) No newline at end of file

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Listening on all network interfaces (0.0.0.0) can expose the application to unnecessary security risks if not properly secured. It's recommended to bind the server to 127.0.0.1 if it's only meant to be accessed locally or ensure proper security measures are in place (like a firewall) when exposing it to the internet.

Recommended Change:
Change the host to 127.0.0.1 if local access is sufficient:

uvicorn.run(fastapi_app, host="127.0.0.1", port=8000)

from codegen.extensions.events.codegen_app import CodegenApp
import modal

image = modal.Image.debian_slim(python_version="3.13").apt_install("git").pip_install("fastapi[standard]", "codegen>=v0.22.2")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The chaining of apt_install and pip_install methods in the Docker image setup could lead to inefficient caching and larger image sizes. Consider splitting these into separate layers or optimizing the Dockerfile to leverage build caching effectively. This can be achieved by grouping package installations or using multi-stage builds to minimize the final image size.


image = modal.Image.debian_slim(python_version="3.13").apt_install("git").pip_install("fastapi[standard]", "codegen>=v0.22.2")
app = CodegenApp(name="test-linear", modal_api_key="", image=image)
app = CodegenApp(name="test-linear")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The application name "test-linear" is hardcoded in the instantiation of CodegenApp. To enhance flexibility and maintainability, consider externalizing this configuration to an environment variable or a configuration file. This approach allows for easier adjustments in different deployment environments without modifying the codebase.

Comment on lines 1 to 2
import logging
from logging import getLogger

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant Imports

The import statements for logging and from logging import getLogger are redundant. You can remove the specific import of getLogger and use logging.getLogger() instead, which will make the import section cleaner and avoid redundancy.

Recommended Change:

import logging
# from logging import getLogger  # This line can be removed

Comment on lines 31 to 32

@app.github.event("pull_request:labeled")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing Error Handling in Event Registration

The event handler for pull_request:labeled does not include any error handling. This could lead to unhandled exceptions if the event data is not as expected or if there are issues during the handling process. It's recommended to add error handling to ensure the application behaves gracefully under error conditions.

Suggested Improvement:

@app.github.event("pull_request:labeled")
def handle_labeled(event: PullRequestLabeledEvent):
    try:
        # existing code
    except Exception as e:
        logger.error(f"Error handling labeled event: {e}")

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

image = modal.Image.debian_slim(python_version="3.13").apt_install("git").pip_install("fastapi[standard]", "codegen==v0.26.3")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The specified Python version '3.13' in the modal.Image.debian_slim configuration may be incorrect or a typo, as Python 3.13 is not a released version. This could lead to issues when building the image or at runtime.

Recommendation: Verify the intended Python version and update it to a valid version, such as '3.9' or '3.10', to ensure compatibility and avoid deployment failures.

app = CodegenApp("linear-bot")


@app.cls(secrets=[modal.Secret.from_dotenv()], keep_warm=1)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The keep_warm=1 setting in the @app.cls decorator is used to keep the serverless function warm, potentially improving response times. However, this setting might incur additional costs or have other implications depending on the platform's billing and performance characteristics.

Recommendation: Review the necessity and impact of the keep_warm setting in this context. If it's essential for performance, consider documenting its benefits and potential costs. If not, you might want to adjust or remove this setting to optimize resource usage and cost.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants