Welcome to the GitHub PR Automation repository!
This project automates the analysis of GitHub Pull Requests (PRs) using a modular service-oriented
architecture powered by Celery, Redis, and AI-backed insights.
- Core logic resides in
app/analysis_pipeline.py. - Contains the
AnalysisPipelineclass with arun()method to initiate PR analysis.
- Asynchronous task processing using Celery.
- Task defined as
analyze_pr_taskinapp/celery_app.py.
Modular services in the services/ directory:
- AI Services:
services/ai_services - GitHub Services:
services/github_services - Logging Services:
services/logging_services - Redis Caching Services:
services/redis_services
- API request/response models:
models/api_models.py - Output data structures:
models/output_model.py
- Centralized logging with
AppLoggerinservices/logging_services/logger.py.
RedisCacheServicehandles Redis operations inservices/redis_services/redis_cache.py.
Clone the repository:
git clone https://github.com/KshitijTardalkar/GithubPRAutomation.git
cd GithubPRAutomation- Obtain GitHub API Key:
- Go to GitHub Developer Settings.
- Click on "Generate new token". Select the scopes you need, typically including
repofor accessing repositories. - Generate and copy the token.
- Pass this token in the POST request to authenticate API calls. This enables higher rate limits and access to private repositories.
- Obtain Gemini API Key:
- Visit the Gemini platform's website or API service.
- Follow their documentation to generate an API key.
- Store the key securely.
-
Set Environment Variables:
Export your Gemini API key directly in your terminal (no
.envfile is used):export GEMINI_API_KEY=<your-gemini-api-key>
-
GitHub Token Usage:
You do not need to set the GitHub token as an environment variable. Instead, pass the token directly in the POST request payload when making authenticated GitHub API calls. This allows access to private repositories and increases your rate limit.
-
Install Required Libraries:
- Ensure you have the necessary libraries installed by running:
pip install -r requirements.txt
- Ensure you have the necessary libraries installed by running:
-
Ensure Services are Running:
- Make sure Redis and Celery services are set up and running as specified in the next section.
- Run Redis(via Docker):
docker run -p 6379:6379 -d redis- Start Celery Worker:
celery -A app.celery_app worker --loglevel=infouvicorn app.main:app --reloadUse the FastAPI endpoints defined in app/main.py to interact with the system programmatically.
You can test them using tools like Postman or cURL.
This command will do one of two things:
- If the PR has been recently analyzed and is present in the Redis cache, it will return the cached result immediately.
- If the PR is not cached or has changed since the last analysis, a new Celery task will be created. The response will include a task_id that can be used to check the status or retrieve results using the GET endpoints described below.
curl -X POST http://127.0.0.1:8000/analyze_pr \
-H "Content-Type: application/json" \
-d '{
"repo_url": <YOUR_GITHUB_URL>,
"pr_number": <PR_NUMBER>,
"github_token": <OPTIONAL_GITHUB_TOKEN>
}'Note: Access to public repositories without a GitHub token is subject to strict rate limits. To access private repositories and increase your rate limit, provide a valid GitHub API token.
curl http://127.0.0.1:8000/status/<task_id>curl http://127.0.0.1:8000/result/<task_id>You can also test the API using test.http.
It works with both JetBrains IDEs and VSCode (with the REST Client extension).
- Fill in the required placeholders manually, or
- Optionally create a
test.http.env.jsonto manage local test values.
Contributions are welcome! Please follow these guidelines when contributing:
- Report Issues: If you encounter any issues or have feature requests, please open an issue on the GitHub repository.
- Submit Pull Requests: Fork the repository and submit a pull request with your changes. Ensure that the code is well-documented and follows the project's coding standards.
This project is licensed under the MIT License.
Feel free to modify and distribute this software as needed for your use cases.
If you have any questions or need further assistance with the GitHub PR Automation project, feel free to reach out:
- Email: kstardalkar@gmail.com
- GitHub: @KshitijTardalkar
Thank you for using the GitHub PR Automation repository!