forked from commitizen-tools/commitizen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscm_provider.py
More file actions
36 lines (28 loc) · 1.05 KB
/
scm_provider.py
File metadata and controls
36 lines (28 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from __future__ import annotations
from packaging.version import InvalidVersion
from commitizen.git import get_tags
from commitizen.providers.base_provider import VersionProvider
from commitizen.tags import TagRules
class ScmProvider(VersionProvider):
"""
A provider fetching the current/last version from the repository history
The version is fetched using `git describe` and is never set.
It is meant for `setuptools-scm` or any package manager `*-scm` provider.
"""
def get_version(self) -> str:
rules = TagRules.from_settings(self.config.settings)
tags = get_tags(reachable_only=True)
version_tags = rules.get_version_tags(tags)
versions = []
for t in version_tags:
try:
versions.append(rules.extract_version(t))
except InvalidVersion:
continue
versions = sorted(versions)
if not versions:
return "0.0.0"
return str(versions[-1])
def set_version(self, version: str):
# Not necessary
pass