Created
April 5, 2024 03:03
-
-
Save gabrielfeo/9927ffc6af7928ef348b43a39c55b956 to your computer and use it in GitHub Desktop.
releases-to-changelog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# Small script to build a changelog file out of past GitHub releases. | |
# | |
# USAGE: ./releases-to-changelog.py <github-repo-path> | |
# Example: ./releases-to-changelog.py "JetBrains/kotlin" > CHANGELOG.md | |
from subprocess import check_output | |
import sys | |
import json | |
repo_url = f"https://api.github.com/repos/{sys.argv[1]}/releases" | |
output = check_output(f"curl -s {repo_url} " + | |
"| jq '.[] | { body, name, published_at }' " + | |
"| jq -s '.'", shell=True).decode('utf-8') | |
releases = json.loads(output) | |
changelog = """# Changelog | |
All notable changes to this project will be documented in this file. | |
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), | |
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | |
""" | |
for release in releases: | |
date = release['published_at'].split('T')[0] | |
changelog += f"## [{release['name']}] - {date}\n\n{release['body']}\n\n" | |
print(changelog) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment