diff --git a/src/main/python/ddadevops/domain/build_file.py b/src/main/python/ddadevops/domain/build_file.py index 285c6d1..321ab33 100644 --- a/src/main/python/ddadevops/domain/build_file.py +++ b/src/main/python/ddadevops/domain/build_file.py @@ -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 = 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) diff --git a/src/main/python/ddadevops/domain/version.py b/src/main/python/ddadevops/domain/version.py index 5907bfa..41f0dc1 100644 --- a/src/main/python/ddadevops/domain/version.py +++ b/src/main/python/ddadevops/domain/version.py @@ -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 diff --git a/src/test/python/domain/test_build_file.py b/src/test/python/domain/test_build_file.py index 833f0c6..33a5f19 100644 --- a/src/test/python/domain/test_build_file.py +++ b/src/test/python/domain/test_build_file.py @@ -33,19 +33,40 @@ 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", + "name":"c4k-jira", "description": "Generate c4k yaml for a jira deployment.", "author": "meissa GmbH", "version": "1.1.5-SNAPSHOT", "homepage": "https://gitlab.com/domaindrivenarchitecture/c4k-jira#readme", - "bin": { + "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")