The Palos Publishing Company

Follow Us On The X Platform @PalosPublishing
Categories We Write About

Create a changelog analyzer

Here is a functional Changelog Analyzer in Python that parses changelog files (in Markdown format commonly used in CHANGELOG.md) and provides a structured summary of versions, dates, and categorized changes (e.g., Added, Fixed, Changed).

python
import re from collections import defaultdict from pprint import pprint class ChangelogAnalyzer: def __init__(self, changelog_text): self.changelog_text = changelog_text self.entries = defaultdict(dict) def parse(self): # Pattern for version headers like ## [1.0.0] - 2023-12-31 version_header_pattern = re.compile(r'^##s*[?([d.]+)]?s*-s*(d{4}-d{2}-d{2})?', re.MULTILINE) # Pattern for change type headers like ### Added change_type_pattern = re.compile(r'^###s*(Added|Changed|Deprecated|Removed|Fixed|Security)', re.MULTILINE) pos = 0 while True: version_match = version_header_pattern.search(self.changelog_text, pos) if not version_match: break version = version_match.group(1) date = version_match.group(2) or "Unreleased" start = version_match.end() next_version_match = version_header_pattern.search(self.changelog_text, start) end = next_version_match.start() if next_version_match else len(self.changelog_text) version_block = self.changelog_text[start:end] changes = defaultdict(list) for change_match in change_type_pattern.finditer(version_block): change_type = change_match.group(1) change_start = change_match.end() next_change_match = change_type_pattern.search(version_block, change_start) change_end = next_change_match.start() if next_change_match else len(version_block) items_block = version_block[change_start:change_end] items = re.findall(r'- (.+)', items_block) changes[change_type].extend(items) self.entries[version] = { "date": date, "changes": dict(changes) } pos = end def get_summary(self): return dict(self.entries) # Example usage: if __name__ == "__main__": with open("CHANGELOG.md", "r") as file: changelog_content = file.read() analyzer = ChangelogAnalyzer(changelog_content) analyzer.parse() summary = analyzer.get_summary() pprint(summary)

Features:

  • Extracts version numbers and dates.

  • Categorizes changes under headings like Added, Fixed, Changed, etc.

  • Handles Markdown-style changelog formatting (e.g., Keep a Changelog format).

  • Can be extended to export JSON or integrate into CI pipelines.

Let me know if you want a web interface, JSON export, Git integration, or support for alternative changelog formats.

Share this Page your favorite way: Click any app below to share.

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Categories We Write About