fix: duplicate commits

This commit is contained in:
Indranil012 2023-03-15 13:32:10 +05:30
parent dfd8a3c68e
commit bf5f8ef442
2 changed files with 17 additions and 9 deletions

View File

@ -197,7 +197,7 @@ class Releases:
return contributors return contributors
async def get_commits(self, repository: str, current_version: str, target_tag: str = "latest") -> str: async def get_commits(self, repository: str, current_version: str, target_tag: str = "latest") -> list:
"""Get commit history from a given repository. """Get commit history from a given repository.
Args: Args:
@ -206,11 +206,13 @@ class Releases:
target_tag (str): lateset(default), prerelease, recent, tag_name target_tag (str): lateset(default), prerelease, recent, tag_name
Returns: Returns:
str: string containing the repository's commits between version list: list containing the repository's commits between version
""" """
commits = "" commits = []
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_version = await self.get_tag_release(repository, target_tag)['tag_name'] target_release = await self.get_tag_release(repository, target_tag)
target_version = target_release['tag_name']
target_version = "".join(findall("\d+", target_version)) target_version = "".join(findall("\d+", target_version))
current_version = "".join(findall("\d+", current_version)) current_version = "".join(findall("\d+", current_version))
@ -225,10 +227,16 @@ class Releases:
for release in releases: for release in releases:
if target_version > current_version and release['tag_name'] > current_version: if target_version > current_version and release['tag_name'] > current_version:
commits += release['body'] if release['prerelease'] and target_release['prerelease']:
commits.append(release['body'])
elif not target_release['prerelease'] and not release['prerelease']:
commits.append(release['body'])
elif target_version < current_version and release['tag_name'] == target_version: elif target_version < current_version and release['tag_name'] == target_version:
commits += release['body'] commits.append(release['body'])
else: else:
break break
# commits need cleanup # commits need cleanup
return commits return commits

View File

@ -13,7 +13,7 @@ config: dict = load_config()
@router.get('/commits/{repository}/{current_version}/{target_tag}', response_model=ResponseModels.ChangelogsResponseModel, tags=['ReVanced Tools']) @router.get('/commits/{repository}/{current_version}/{target_tag}', response_model=ResponseModels.ChangelogsResponseModel, tags=['ReVanced Tools'])
@cache(config['cache']['expire']) @cache(config['cache']['expire'])
async def commits(repository: str, current_version: str, target_tag: str = "latest") -> str: async def commits(repository: str, current_version: str, target_tag: str = "latest") -> list:
"""Get commit history from a given repository. """Get commit history from a given repository.
Args: Args:
@ -22,7 +22,7 @@ async def commits(repository: str, current_version: str, target_tag: str = "late
target_tag (str): lateset(default), prerelease, recent, tag_name target_tag (str): lateset(default), prerelease, recent, tag_name
Returns: Returns:
str: string containing the repository's commits between version list: string containing the repository's commits between version
""" """
return await releases.get_commits(repository, current_version, target_tag) return await releases.get_commits(repository, current_version, target_tag)