@@ -83,12 +83,12 @@ def parse_version(self, version):
8383
8484 def get_version_from_string (self , version ):
8585 '''
86- Split version to find PrestaShop version, PHP version and container type
86+ Split version to find PrestaShop version, branch version, PHP version and container type
8787
8888 @param version: The version you want
8989 @type version: str
90- @return: A tuple containing ('PS_VERSION', (PHP_VERSIONS), 'CONTAINER_TYPE')
91- or ('PS_VERSION', 'PHP_VERSION', 'CONTAINER_TYPE')
90+ @return: A tuple containing ('PS_VERSION', 'BRANCH_VERSION', (PHP_VERSIONS), 'CONTAINER_TYPE')
91+ or ('PS_VERSION', 'BRANCH_VERSION', ' PHP_VERSION', 'CONTAINER_TYPE')
9292 @rtype: tuple
9393 '''
9494 matches = self .parse_version_from_string (version )
@@ -108,12 +108,83 @@ def get_version_from_string(self, version):
108108 if matches .group ('container' ):
109109 container_version = matches .group ('container' )
110110
111+ split_version = self .split_prestashop_version (ps_version )
112+ if split_version is None :
113+ branch_version = 'develop'
114+ elif split_version ['patch' ] == 'x' :
115+ # ps_version actually already contains the branch
116+ branch_version = ps_version
117+ # We need to transform the branch into the next patch version
118+ patch_index = ps_version .rindex ('.' )
119+ last_patch = self .get_last_patch_from_version (ps_version )
120+ if last_patch is None :
121+ last_patch = '0'
122+ else :
123+ last_patch = str (int (last_patch ) + 1 )
124+ ps_version = ps_version [:patch_index + 1 ] + last_patch
125+ else :
126+ # Transform the last patch version into an x to get the branch, we ignore any -rc that may be present
127+ real_version = split_version ['version' ]
128+ patch_index = real_version .rindex ('.' )
129+ branch_version = real_version [:patch_index + 1 ] + 'x'
130+
111131 return {
112132 'ps_version' : ps_version ,
133+ 'branch_version' : branch_version ,
113134 'php_versions' : php_versions ,
114135 'container_version' : container_version
115136 }
116137
138+ def get_last_patch_from_version (self , version ):
139+ '''
140+ Get last patch version for the specified version based on the VERSIONS list
141+ @param version: The version you need the match from
142+ @type version: str
143+ @return: Return None if no patch is found otherwise an int with the patch.
144+ @rtpe: None|int
145+ '''
146+ split_version = self .split_prestashop_version (version )
147+ if (split_version is None ):
148+ return None
149+
150+ lastPatch = None
151+ for ps_version , php_versions in VERSIONS .items ():
152+ split_ps_version = self .split_prestashop_version (ps_version )
153+ if split_ps_version is None :
154+ continue
155+ if (split_ps_version ['major' ] != split_version ['major' ] or split_ps_version ['minor' ] != split_version ['minor' ]):
156+ continue
157+ if split_ps_version ['patch' ] == 'x' :
158+ continue
159+ if (lastPatch is None or int (split_ps_version ['patch' ]) > int (lastPatch )):
160+ lastPatch = split_ps_version ['patch' ]
161+ return lastPatch
162+
163+ def split_prestashop_version (self , version ):
164+ '''
165+ Split the version into major minor patch object, it is a custom-tailed alternative to semver.VersionInfo.parse
166+ that can handle our development branches like 1.7.8.x, 8.0.x, ...
167+ @param version: The version you need to split
168+ @type version: str
169+ @return: Return None if no patch is found otherwise an int with the patch.
170+ @rtpe: None|tuple
171+ '''
172+ regex = r"^(?P<major>(1.)?[0-9]+)\.(?P<minor>[0-9]+)\.(?P<patch>[0-9x]+)(?P<prerelease>-(alpha|beta|rc)(?:\.\d+)?(?:\+\d+)?)?"
173+ matches = re .search (regex , version )
174+
175+ if (matches and matches .group () and matches .group ('major' ) and matches .group ('major' ) and matches .group ('major' )):
176+ # Remove the initial matched -
177+ prerelease = matches .group ('prerelease' )[1 :] if matches .group ('prerelease' ) else None
178+
179+ return {
180+ 'version' : matches .group ('major' ) + '.' + matches .group ('minor' ) + '.' + matches .group ('patch' ),
181+ 'major' : matches .group ('major' ),
182+ 'minor' : matches .group ('minor' ),
183+ 'patch' : matches .group ('patch' ),
184+ 'prerelease' : prerelease ,
185+ }
186+ return None
187+
117188 def parse_version_from_string (self , version ):
118189 '''
119190 Parse version from string based on a regex
@@ -122,7 +193,7 @@ def parse_version_from_string(self, version):
122193 @return: Return None if no position in the string matches the pattern otherwise a Match object.
123194 @rtpe: None|Match
124195 '''
125- regex = r"^(?P<version>(?:[0-9]+\.){0,3}(?:[0-9]+|nightly)(?:-(?:alpha|beta|rc)(?:\.\d+)?(?:\+\d+)?)?)(?:-(?P<php>\d+\.\d+))?(?:-(?P<container>fpm|apache))?$"
196+ regex = r"^(?P<version>(?:[0-9]+\.){0,3}(?:[0-9]+|nightly|x )(?:-(?:alpha|beta|rc)(?:\.\d+)?(?:\+\d+)?)?)(?:-(?P<php>\d+\.\d+))?(?:-(?P<container>fpm|apache))?$"
126197 return re .search (regex , version )
127198
128199 def get_aliases (self ):
@@ -150,7 +221,7 @@ def get_aliases(self):
150221 if alias_version != 'latest' :
151222 self .append_to_aliases (aliases , ps_version , php_version , PREFERED_CONTAINER , alias_version + '-' + php_version )
152223
153- # Check prefered container
224+ # Check preferred container
154225 self .append_to_aliases (aliases , ps_version , alias_php_version , PREFERED_CONTAINER , alias_version )
155226
156227 # Check containers
@@ -184,6 +255,14 @@ def get_ps_versions_aliases(self):
184255 }
185256 continue
186257
258+ # Ignore branch versions
259+ split_version = self .split_prestashop_version (ps_version )
260+ if split_version ['patch' ] == 'x' :
261+ aliases [ps_version ] = {
262+ 'value' : ps_version
263+ }
264+ continue
265+
187266 # PrestaShop versions before 8 are in format 1.MAJOR.MINOR.PATCH
188267 # Starting version 8, format is MAJOR.MINOR.PATCH
189268 splitted_version = ps_version .split ('.' , 1 )
0 commit comments