Skip to main content

Produces GitLab changelog release notes for projects that follow SemVer

Project description

GitLabChangelog

CI Python Version Code style: black

Produces GitLab changelog release notes for projects that follow SemVer. The changelog produced for each release based on the issues that have been closed and the merge requests that have been merged.

Installation

To install this just install it into a virtualenv like so:

cd GitLabChangelog
python3 -m venv venv
. venv/bin/activate

pip install --upgrade pip
pip install -e .

Contributing

This package uses the python-gitlab package to interact with GitLab. It's useful to refer to their documentation when making changes. You can test using their API locally by generating a Personal Access Token and setting it in the included local_test.py script.

You can run tests locally by running in the virtualenv you installed the package in:

tox

New releases will automatically publish the package to TestPyPi and PyPi via GitHub Actions. Don't forget to bump the version in gitlabchangelog/VERSION before tagging a new release.

Changelog format

The changelog is completely customizable with the Jinja templating engine. To supply your own template, use the template parameter when creating Changelogs:

from os import environ as env

import gitlab
from tagbotgitlab.changelog import Changelog

# Set some environment variables required for import.
env["GITLAB_URL"] = "https://gitlab.example.ca"
env["GITLAB_API_TOKEN"] = "<the-personal-access-token-you-created>"
client = gitlab.Gitlab(env["GITLAB_URL"], private_token=env["GITLAB_API_TOKEN"])

repo = "example/TestRepo"
p = client.projects.get(repo, lazy=True)

template = """
This is release {{ version }} of {{ package }}.
    {% if merge_requests %}
    **Summary:**
    {% for merge_request in merge_requests %}
        - [{{ merge_request.labels }}] {{ merge_request.title }} (!{{ merge_request.number }})
    {% endfor %}
    {% endif %}

    {% if previous_release %}
    **Changeset:** {{ compare_url }})
    {% endif %}
"""
changelog = Changelog(p, template)

commit = "abcdefgh"
version = "v1.0.1"
release_notes = changelog.get(version, commit)
print(release_notes)

The data available to you looks like this:

{
  "compare_url": "https://gitlab.com/Owner/Repo/-/compare/previous_version...current_version (or null for first release)",
  "issues": [
    {
      "author": {
        "name": "Real Name",
        "url": "https://gitlab.com/username",
        "username": "their login"
      },
      "description": "issue description",
      "labels": ["label1", "label2"],
      "number": 123,
      "title": "issue title",
      "url": "https://gitlab.com/Owner/Repo/issues/123"
    }
  ],
  "package": "PackageName",
  "previous_release": "v1.1.2 (or null for first release)",
  "merge_requests": [
    {
      "author": {"same format as": "issue author"},
      "description": "merge request description",
      "labels": ["label1", "label2"],
      "merger": {"same format as": "issue author"},
      "number": 123,
      "title": "merge request title",
      "url": "https://gitlab.com/Owner/Repo/pull/123"
    }
  ],
  "sha": "commit SHA",
  "version": "v1.2.3",
  "version_url": "https://gitlab.com/Owner/Repo/tree/v1.2.3"
}

You can see the default template in gitlabchangelog/changelog.py.

Ignore labels

Issues and pull requests with specified labels are not included in the changelog data. By default, the following labels are ignored:

  • changelog skip
  • duplicate
  • exclude from changelog
  • invalid
  • no changelog
  • question
  • wont fix

White-space, case, dashes, and underscores are ignored when comparing labels.

License

gitlabchangelog is provided under an MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

GitLabChangelog-0.2.1.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

GitLabChangelog-0.2.1-py2.py3-none-any.whl (7.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file GitLabChangelog-0.2.1.tar.gz.

File metadata

  • Download URL: GitLabChangelog-0.2.1.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for GitLabChangelog-0.2.1.tar.gz
Algorithm Hash digest
SHA256 55673c80f73209617fa1a2605bbfbca5a6afe9227780c72ae0eedc91b15f72fe
MD5 82ea613b027edae50e57fdf6c7ed5152
BLAKE2b-256 a6347d9e3f0227db4b3aae00bac546a27e129033c0264bdaee4f89ecfcbb2469

See more details on using hashes here.

File details

Details for the file GitLabChangelog-0.2.1-py2.py3-none-any.whl.

File metadata

  • Download URL: GitLabChangelog-0.2.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for GitLabChangelog-0.2.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 80e16351c11e6486e82d7ad78f426d8b0463a6e15177b2d2f8aab71c7f394f0b
MD5 3de4ed0deab0be94262395f5df50b759
BLAKE2b-256 e4fbc3025ef7e8f4d2c3d7e9ebdc65f883ad9106108aa27f3c392ce1eb1f9f7b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page