js & gradle works

merge-requests/12/head
Michael Jerger 1 year ago
parent 6766691ee7
commit f2c6f7787e

@ -1,6 +1,7 @@
from enum import Enum from enum import Enum
from typing import Optional from typing import Optional
from pathlib import Path from pathlib import Path
import re
import json import json
from .common import ( from .common import (
Validateable, Validateable,
@ -48,5 +49,16 @@ class BuildFile(Validateable):
return result return result
def get_version(self) -> Version: def get_version(self) -> Version:
version = json.loads(self.content)["version"] version = None
match self.build_file_type():
case BuildFileType.JS:
print(json.loads(self.content))
version = json.loads(self.content)["version"]
print(version)
case BuildFileType.JAVA_GRADLE:
version_line = re.search("\nversion = .*", self.content)
version_line_group = version_line.group()
version_string = re.search(
'[0-9]*\\.[0-9]*\\.[0-9]*(-SNAPSHOT)?', version_line_group)
version = version_string.group()
return Version.from_str(version) return Version.from_str(version)

@ -30,6 +30,9 @@ class Version(Validateable):
self.snapshot_suffix = snapshot_suffix self.snapshot_suffix = snapshot_suffix
self.version_string = version_str self.version_string = version_str
def __eq__(self, other):
return other and self.to_string() == other.to_string()
def is_snapshot(self): def is_snapshot(self):
return not self.snapshot_suffix == None return not self.snapshot_suffix == None

@ -33,19 +33,40 @@ def test_sould_calculate_build_type():
) )
assert sut.build_file_type() == BuildFileType.JAVA_CLOJURE assert sut.build_file_type() == BuildFileType.JAVA_CLOJURE
sut = BuildFile(
Path("./build.gradle"),
"content"
)
assert sut.build_file_type() == BuildFileType.JAVA_GRADLE
sut = BuildFile(
Path("./package.json"),
"content"
)
assert sut.build_file_type() == BuildFileType.JS
def test_sould_parse_version(): def test_sould_parse_version():
sut = BuildFile( sut = BuildFile(
Path("./package.js"), Path("./package.json"),
"""{ """{
"name": "c4k-jira", "name":"c4k-jira",
"description": "Generate c4k yaml for a jira deployment.", "description": "Generate c4k yaml for a jira deployment.",
"author": "meissa GmbH", "author": "meissa GmbH",
"version": "1.1.5-SNAPSHOT", "version": "1.1.5-SNAPSHOT",
"homepage": "https://gitlab.com/domaindrivenarchitecture/c4k-jira#readme", "homepage": "https://gitlab.com/domaindrivenarchitecture/c4k-jira#readme",
"bin": { "bin":{
"c4k-jira": "./c4k-jira.js" "c4k-jira": "./c4k-jira.js"
}, }
} }
"""
)
assert sut.get_version() == Version.from_str("1.1.5-SNAPSHOT")
sut = BuildFile(
Path("./build.gradle"),
"""
version = "1.1.5-SNAPSHOT"
""" """
) )
assert sut.get_version() == Version.from_str("1.1.5-SNAPSHOT") assert sut.get_version() == Version.from_str("1.1.5-SNAPSHOT")

Loading…
Cancel
Save