refactor: simplify logic

This commit is contained in:
Indranil012 2023-03-18 13:50:49 +05:30
parent 2637bd4f18
commit ee52e4119d

View File

@ -216,7 +216,7 @@ class Releases:
return numeric_str return numeric_str
return string return string
def check_greater(check_string: str, check_with: str) -> bool : def check_greater_or_equal(check_string: str, check_with: str) -> bool :
check_string = to_numeric(check_string) check_string = to_numeric(check_string)
check_with = to_numeric(check_with) check_with = to_numeric(check_with)
diff = abs(len(check_string) - len(check_with)) diff = abs(len(check_string) - len(check_with))
@ -226,11 +226,10 @@ class Releases:
elif len(check_string) < len(check_with): elif len(check_string) < len(check_with):
check_string += "0"*diff check_string += "0"*diff
if int(check_string) > int(check_with): if int(check_string) >= int(check_with):
return True return True
if int(check_string) < int(check_with):
return False return False
return None
releases = await self.httpx_client.get(f"https://api.github.com/repos/{repository}/releases").json() releases = await self.httpx_client.get(f"https://api.github.com/repos/{repository}/releases").json()
target_release = await self.get_tag_release(repository, target_tag) target_release = await self.get_tag_release(repository, target_tag)
@ -245,9 +244,8 @@ class Releases:
commits = [] commits = []
for release in releases: for release in releases:
if check_greater(target_version, current_version): if check_greater_or_equal(target_version, current_version):
if check_greater(release['tag_name'], current_version): if check_greater_or_equal(release['tag_name'], current_version) and check_greater_or_equal(target_version, release['tag_name']):
if check_greater(target_version, release['tag_name']) in (True, None):
if target_prerelease: if target_prerelease:
if release['prerelease']: if release['prerelease']:
commits.extend(cleanup(release['body'])) commits.extend(cleanup(release['body']))
@ -255,12 +253,8 @@ class Releases:
elif not release['prerelease']: elif not release['prerelease']:
commits.extend(cleanup(release['body'])) commits.extend(cleanup(release['body']))
elif check_greater(current_version, target_version): elif check_greater_or_equal(release['tag_name'], target_version) and check_greater_or_equal(target_version, release['tag_name']):
if check_greater(release['tag_name'], target_version) == None:
commits.extend(cleanup(release['body'])) commits.extend(cleanup(release['body']))
break break
else:
break
return commits return commits