Git Product home page Git Product logo

easy-changelog's Introduction

README.md


Changelog Generator Tool

This Python script is a changelog generator that creates a detailed changelog for a project based on git commit history. It identifies version changes, associates commits with issues from an issue tracker (currently supports Redmine), and generates a markdown file summarizing these changes.

Features

  • Supports different version containers like Maven (pom.xml), NPM (package.json), and environment files.
  • Identifies commits associated with version changes.
  • Extracts issue information from commit messages for Redmine.
  • Generates a changelog in markdown format.

Prerequisites

  • Python 3
  • packaging (It's temporary)
  • Git repository
  • Redmine issue tracker (for advanced commit information)

Setup

  • Ensure Python 3 is installed on your system.
  • Install packaging:
pip install packaging

Usage

  1. Clone your git repository locally, if you haven't already.
  2. Navigate to the root directory of this script.
  3. Run the script via the command line, adjusting the arguments as needed.

Sample Command

python easy_changelog.py --issue-tracker-url YOUR_ISSUE_TRACKER_URL --issue-tracker-token YOUR_API_KEY --version-control-system-commit-url YOUR_VCS_COMMIT_BASE_URL -C PATH_TO_YOUR_GIT_REPO

Replace placeholders (YOUR_ISSUE_TRACKER_URL, YOUR_API_KEY, YOUR_VCS_COMMIT_BASE_URL, PATH_TO_YOUR_GIT_REPO) with applicable values.

Command Line Arguments

  • --issue-tracker-type: Optional. Issue tracker type. Currently, only redmine is supported.
  • --issue-tracker-url: Required. Base URL of your issue tracker.
  • --issue-tracker-token: Required. API key or token for the issue tracker.
  • --version-control-system-commit-url: Required. Base URL used in the changelog to link commits.
  • -C / --repository-path: Optional. Path to the git directory. If not provided, the current working directory is used by default.
  • --version-container-type: Optional. The type of version container (maven, npm, env). Default is maven.
  • --version-container-path: Optional. Path to the version file relative to the repository root. Default is pom.xml for Maven projects.
  • -o / --output-file: Optional. Path to the output changelog file. Default is CHANGELOG.md.
  • --version-compare-mode: Optional. Version comparison mode (full,major,minor,patch,labels). Perform the comparison up to specified version component and ignore others. It's useful for example if dev-branch contains patches or labels like -alpha or -rc.0 and you want to include these changes to changelog file but do not separate it by different versions. Default is full which means compare all components.

Output

The script generates a CHANGELOG.md file (or another specified file) in the root directory of this script, documenting all notable changes in the format recommended by Keep a Changelog.

easy-changelog's People

Contributors

siberianlove avatar

Watchers

 avatar

easy-changelog's Issues

Trying to locate pom.xml when "--version-container-path .env" specified

> python3 easy_changelog.py --issue-tracker-url "[MASKED]" --issue-tracker-token [MASKED] --version-control-system-commit-url "url" --version-container-type env --version-container-path .env
~/easy_changelog/easy_changelog.py:189: SyntaxWarning: invalid escape sequence '\d'
  result = re.search("#\d+", title)
[CMD]: git -C '' log --pretty=format:%h%n%s%n%d%ci -s -z --reverse --no-merges -- .env
[CMD]: git -C '' show cc1fa8d:pom.xml
[ERROR]: fatal: path 'pom.xml' does not exist in 'cc1fa8d'

Detect if repo is shallow clone

Sometimes CI/CD tools do shallow clone by default (gitlab for example). To build changelog we need full copy of the repository, cause this tool uses repository changes history under the hood.

Development of a Tool for Generating Changelogs Based on Git Commit History and Issues

Description:

Task to develop a tool that automates the generation of changelogs for majority kind of projects. The aim is to create a solution that extracts version history and corresponding changes from git commit logs and a file defining the app version (initially pom.xml). Furthermore, each commit message typically references an issue from issue tracker, allowing for a comprehensive changelog linking directly to resolved issues for more detailed context. Initially, the tool should integrate with the Redmine issue tracker to pull in detailed descriptions and titles from issues referenced in commit messages.

Requirements:

  1. Git Commit History Parsing: The tool should analyze the git commit history to identify version changes and associated commits. Version changes can be detected through changes to a specific file (e.g., pom.xml), where a new version number is defined.

  2. Issue Tracker Integration (Redmine): Upon identifying the relevant commits for a version change, the tool must fetch detailed information (e.g., title, description) from the Redmine issue tracker based on issues referenced in the commit messages.

  3. Changelog Generation: Leverage the information gathered from the git history and Redmine to generate a comprehensive changelog. The changelog should include version numbers, dates, list of changes (with emphasis on features, fixes, and breaking changes), and links to the detailed issue pages for users to explore further.

  4. User Interface: While the first iteration can focus on a Command-Line Interface (CLI), plans for a simple graphical user interface (GUI) for configuring and running the tool would be cool.

  5. Flexibility and Extensibility: The tool should be designed with extensibility in mind, allowing future support for other issue trackers (e.g., Jira, GitHub Issues) and different file types for version management beyond pom.xml (e.g., package.json, csproj).

Deliverables:

  • A working tool capable of generating changelogs as described above.
  • Documentation on how to set up, configure, and use the tool.
  • A brief report outlining the approach taken, challenges faced, and suggestions for future extensions.

Error on version_parser when package.json have trailing commas

Error log:

[CMD]: git -C '' show 7a87605e4:package.json
    main()
  File "/builds/project/./easy-changelog.py", line 584, in main
    version_container_changes = find_version_container_changes(
  File "/builds/project/./easy-changelog.py", line 493, in find_version_container_changes
    version = version_parser(result)
  File "/builds/project/./easy-changelog.py", line 215, in parse_version_npm
    file_json = json.loads(file_content)
  File "/usr/lib/python3.9/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.9/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.9/json/decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 106 column 3 (char 3314)

package.json:


 100.     "file-loader": "3.0.1",
 101.     "html-webpack-plugin": "4.3.0",
 102.     "image-webpack-loader": "4.6.0",
 103.     "jest": "25.5.4",
 104.     "jest-localstorage-mock": "2.4.2",
>105.     "nodemon": "2.0.20",
 106.   },
 107.   "browserslist": [
 108.     "> 0.1%",
 109.     "ie >= 8"
 110.   ],

possible solutions:

Error when between versions changes nothing to fill

[REQUEST]: curl https://redmine_url/issues.json?issue_id=&limit=0&status_id=*
[WARN]: Error while getting issue info from redmine: STATUS: 422 REASON: Unprocessable Entity BODY: b''
    fill_commits_info_redmine(
  File "/builds/easy_changelog.py", line 230, in fill_commits_info_redmine
    fill_commits_info_redmine_batch(batch, issue_tool_url, issue_tool_api_key)
  File "/builds/easy_changelog.py", line 270, in fill_commits_info_redmine_batch
    for issue in result_json["issues"]:
KeyError: 'issues'

redmine response:

{
  "errors": [
    "issue_id cannot be empty"
  ]
}

Provide single executable

Since one of the main ideas of this tool is simplicity - should be relatively easy to install and run. Dependencies ruins this approach cause when you have dependencies you need to do more steps to configure system environment before run, especially in stuff like ci/cd.

One of the ways to do this - build python source code to single native executable with tools like pyinstaller. So user can just download & run. I thing we should try this first.

Also we can do it by provide single python script so user can run it using python interpreter since it's common tool.

Error when git log from one version up to another does not contains any commits or only one version exists in repository

> python3 easy_changelog.py --issue-tracker-url "[MASKED]" --issue-tracker-token [MASKED] --version-control-system-commit-url "url" --version-container-type env --version-container-path .env
~/easy_changelog/easy_changelog.py:189: SyntaxWarning: invalid escape sequence '\d'
  result = re.search("#\d+", title)
[CMD]: git -C '' log --pretty=format:%h%n%s%n%d%ci -s -z --reverse --no-merges -- .env
[CMD]: git -C '' show cc1fa8d:.env
[INFO]: found versions ['0.0.1']
Traceback (most recent call last):
  File "~/easy_changelog/easy_changelog.py", line 477, in <module>
    sort_inside_versions(detailed_commits)
  File "~/easy_changelog/easy_changelog.py", line 283, in sort_inside_versions
    version: str = commits[0].version
                   ~~~~~~~^^^
IndexError: list index out of range

Error parsing env version container

> python3 easy_changelog.py --issue-tracker-url "[MASKED]" --issue-tracker-token [MASKED] --version-control-system-commit-url "url" --version-container-type env --version-container-path .env
~/easy_changelog/easy_changelog.py:189: SyntaxWarning: invalid escape sequence '\d'
  result = re.search("#\d+", title)
[CMD]: git -C '' log --pretty=format:%h%n%s%n%d%ci -s -z --reverse --no-merges -- .env
[CMD]: git -C '' show cc1fa8d:.env
Traceback (most recent call last):
  File "~/easy_changelog/easy_changelog.py", line 454, in <module>
    version_container_changes = find_version_container_changes(
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/easy_changelog/easy_changelog.py", line 384, in find_version_container_changes
    version: str = version_parser(result)
                   ^^^^^^^^^^^^^^^^^^^^^^
  File "~/easy_changelog/easy_changelog.py", line 171, in parse_version_env
    key, value = line.replace("export ", "", 1).strip().split("=", 1)
    ^^^^^^^^^^
ValueError: not enough values to unpack (expected 2, got 1)
```command

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.