js & gradle works

This commit is contained in:
Michael Jerger 2023-05-11 18:13:40 +02:00
parent 6766691ee7
commit f2c6f7787e
3 changed files with 41 additions and 5 deletions

View file

@ -1,6 +1,7 @@
from enum import Enum
from typing import Optional
from pathlib import Path
import re
import json
from .common import (
Validateable,
@ -48,5 +49,16 @@ class BuildFile(Validateable):
return result
def get_version(self) -> 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)

View file

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

View file

@ -33,9 +33,21 @@ def test_sould_calculate_build_type():
)
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():
sut = BuildFile(
Path("./package.js"),
Path("./package.json"),
"""{
"name":"c4k-jira",
"description": "Generate c4k yaml for a jira deployment.",
@ -44,8 +56,17 @@ def test_sould_parse_version():
"homepage": "https://gitlab.com/domaindrivenarchitecture/c4k-jira#readme",
"bin":{
"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")