A Python script to generate a changelog from merged GitHub pull requests based on labels. It organizes changes into categories like New Features, API Changes, and Documentation Changes, and outputs a Markdown file suitable for documentation.
- Fetches merged pull requests from a specified GitHub repository.
- Groups PRs by month and label, with deduplication for Documentation Changes.
- Supports categories: New Features, API Changes, Documentation Changes, Example Updates, Deprecated, and Documentation Platform Updates.
- Configurable via command-line arguments or environment variables.
- Outputs a clean Markdown changelog with a customizable header.
- Python 3.6+
- A GitHub Personal Access Token with
repo
scope. - The
requests
library (pip install requests
).
- Clone or download this repository:
git clone https://github.com/username/changelog-generator.git cd changelog-generator
- Install the required dependency:
pip install requests
- Set your GitHub token as an environment variable:
export GITHUB_TOKEN="your-personal-access-token"
- Run the script, specifying your repository:
python changelog.py --repo "username/repository" --output CHANGELOG.md
Alternatively, use environment variables for configuration:
export CHANGELOG_REPO="username/repository"
export CHANGELOG_TOKEN="your-personal-access-token"
python changelog.py
--repo
: GitHub repository (e.g.,username/repository
). Default:username/repository
orCHANGELOG_REPO
env variable.--token-env
: Environment variable name for the GitHub token. Default:CHANGELOG_TOKEN
orGITHUB_TOKEN
.--output
: Output file for the changelog. Default:CHANGELOG.md
.
Example with custom token variable:
python changelog.py --repo "username/repository" --token-env MY_TOKEN --output my-changelog.md
The script generates a CHANGELOG.md
file (or your specified output file) with the following structure:
This changelog is auto-generated from merged pull requests.
- Added new feature X (#123)
- Updated guide Y (#124)
- Removed deprecated endpoint Z (#125)
To use different labels or categories, edit the LABELS and CATEGORY_ORDER variables in changelog.py. The default configuration supports:
- Labels and Categories:
- New Features → ### ✨ New Features
- API Changes → ### 📚 API Changes
- Documentation and Feature Enhancements, Information Architecture Changes, Documentation Fixes → ### 📝 Documentation Changes
- Example Updates → ### 📋 Example Updates
- Deprecated → ### 🗑 Deprecated
- Platform Updates → ### 🛠 Documentation Platform Updates
- Skip Changelog: Skips PRs with this label.
- Category Order:
- Categories appear in the order defined in
CATEGORY_ORDER
. - Group categories together if you have many labels and you want to consolidate.
- Categories appear in the order defined in
Modify these in the script to match your repository’s labels.
- Ensure your GitHub token has repo scope to access pull request data.
- The script deduplicates PRs under Documentation Changes to avoid repetition when multiple labels apply.
- PRs with the Skip Changelog label are excluded from the output.
MIT License (see LICENSE
file for details).