How malikjahanzaib/issue2pr works
Project Type and Purpose
• This is an open-source, backend-only GitHub bot (Issue2PR) whose job is to listen for GitHub issue events, run AI-powered code generation, and automatically open pull requests. It also provides CLI utilities for repository maintenance (closing issues/PRs, deleting branches).
File Structure Analysis
• Top-level scripts:
• main.py – HTTP server entry point (webhook listener)
• ai_engine.py – Encapsulates AI calls (OpenAI API)
• issue_parser.py – Parses incoming issue payloads
• github_handler.py – Wraps GitHub REST API interactions
• config.py – Loads env vars and exposes configuration
• close_issues.py – CLI utility to batch-close issues/PRs
• delete_branches.py – CLI utility to remove stale branches
• test_issue_processing.py – Test harness (test mode, no real PRs)
• scripts/issue_analysis.py – Auxiliary analysis script
• .github/workflows/pylint.yml – CI linting
• requirements.txt, .env.example, .gitignore
README Insights
• The service uses Python 3.8+, Flask (or similar) for webhooks, ngrok for local tunneling, OpenAI and GitHub APIs, optional Slack/Discord notifications, robust logging, and a “test mode.”
• No persistent database is mentioned—state is ephemeral or managed via GitHub branches.
1. Webhook Listener (main.py + HTTP framework)
2. Issue Parser (issue_parser.py)
3. AI Engine (ai_engine.py → OpenAI API)
4. GitHub Handler (github_handler.py → GitHub API)
5. Notification Service (optional Slack/Discord clients)
6. Configuration & Logging (config.py + log files)
7. CLI Utilities (close_issues.py, delete_branches.py, test_issue_processing.py)
• GitHub Webhook → Webhook Listener
• Listener → Issue Parser
• Parser → AI Engine → OpenAI
• AI Engine (diff output) → GitHub Handler → GitHub (branches, commits, PRs)
• GitHub Handler → Notification Service → Slack/Discord (if configured)
• All components → Logging subsystem
• CLI Utilities → GitHub Handler (reuse API layer)
c. Architectural Patterns & Principles
• Layered modular design: Each module has a single responsibility
• External integration points are encapsulated (OpenAI API, GitHub API, Slack/Discord)
• “Test mode” isolates side effects (no real PR creation)
• Utilities reuse core handler code, avoiding duplication
d. Key Technologies & Frameworks
• Python 3.8+
• HTTP framework (e.g., Flask or FastAPI) for the listener
• requests or httpx for API calls
• OpenAI SDK
• GitHub REST API
• ngrok (development)
• Logging library (built-in logging)