Demonstrates two different configuration approaches for FastAPI-GitHubApp with separate, clean examples.
The recommended approach using only environment variables:
app.config = {}
GitHubApp.load_env(app)
github_app = GitHubApp(app)Advantages:
- Clean, simple code
- No hardcoded values
- Easy to configure for different environments
- Follows 12-factor app principles
Alternative approach using constructor parameters:
github_app = GitHubApp(
app,
github_app_id=int(os.getenv("GITHUBAPP_ID")),
github_app_key=os.getenv("GITHUBAPP_PRIVATE_KEY"),
github_app_secret=os.getenv("GITHUBAPP_WEBHOOK_SECRET"),
github_app_route=os.getenv("GITHUBAPP_WEBHOOK_PATH"),
)When to use:
- Need explicit control over configuration
- Dynamic configuration scenarios
- Legacy code integration
Both examples implement identical functionality:
- Issues opened: Automatically close with "You've got an issue? I've got a solution! Closing 😈"
- Issues reopened: Close again with "Nice try! Closing again. 😈"
This demonstrates that both configuration methods work identically.
-
Copy environment template:
cp .env.example .env
-
Configure your GitHub App credentials in
.env -
Run either example:
# Environment variables (recommended) python app.py # Constructor parameters python constructor.py
- Install the GitHub App on a test repository
- Create a new issue → App closes it automatically
- Reopen the issue → App closes it again
Both examples provide identical functionality, demonstrating that the configuration method doesn't affect the app's behavior.
app.py- Environment variables approach (recommended)constructor.py- Constructor parameters approach.env.example- Environment variables templateREADME.md- This documentation
Use the environment variables approach (app.py) for production applications as it provides better security, flexibility, and follows best practices.