This project automates the generation of a README.md file for a GitHub repository using the Gemini API. It analyzes the repository's file structure and content, then leverages the Gemini API to create a comprehensive and informative README file.
- Automated README Generation: Automatically creates a
README.mdfile from a GitHub repository URL. - GitHub API Integration: Fetches file lists and code snippets directly from the GitHub API.
- Gemini API Integration: Utilizes the Gemini API to generate descriptive and informative README content.
- Customizable Prompt: Builds a structured prompt for the Gemini API, including file snippets and instructions.
- File Content Extraction: Extracts relevant code and documentation snippets from the repository.
- Environment Variable Configuration: Uses environment variables for API keys and model selection.
- Error Handling: Includes robust error handling for API requests and data processing.
- Snippet Size Limiting: Limits the size of file snippets to stay within API limits.
- Command-Line Interface: Provides a command-line interface for easy usage.
-
Clone the repository:
git clone https://github.com/versaagonon/auto-generate-readme.md-file-.git cd auto-generate-readme.md-file- -
Install dependencies:
pip install requests python-dotenv
-
Set up environment variables:
-
Create a
.envfile in the project root. -
Add your GitHub token (optional, but recommended for higher API rate limits) and Google API key:
GITHUB_TOKEN=your_github_token GOOGLE_API_KEY=your_google_api_keyYou can also optionally specify the Gemini model to use:
GEMINI_MODEL=gemini-2.0-flashIf
GEMINI_MODELis not set, the default modelgemini-2.0-flashwill be used.
-
Run the automakereadme.py script with the GitHub repository URL as an argument:
python automakereadme.py https://github.com/owner/repoYou can also specify an output file path using the --out argument:
python automakereadme.py https://github.com/owner/repo --out my_readme.mdThis will generate a README.md (or the specified output file) in the project directory.
- Python 3: The script is written in Python 3.
- requests: Used for making HTTP requests to the GitHub and Gemini APIs.
- python-dotenv: Used for loading environment variables from a
.envfile. - GitHub API: Used to fetch repository file structure and content.
- Gemini API: Used to generate the README content.
- More sophisticated file selection: Implement more advanced logic for selecting relevant files based on file type, size, and content. Consider using heuristics to identify important files that might be missed by the current selection criteria.
- Customizable prompt templates: Allow users to customize the prompt sent to the Gemini API to tailor the README generation process to their specific needs. This could involve providing different templates or allowing users to specify keywords or topics to include in the README.
- Automated deployment: Integrate the script into a CI/CD pipeline to