Skip to content

Commit

Permalink
feat: give higher priority to minor versions
Browse files Browse the repository at this point in the history
Major versions will be shown when minor updates are exhausted only.
  • Loading branch information
ankush committed May 4, 2024
1 parent a234e79 commit 45026ae
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions frappe/utils/change_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,16 @@ def check_for_update():
if not owner or not repo:
continue

github_version, org_name = check_release_on_github(owner, repo)
if not github_version or not org_name:
continue

# Get local instance's current version or the app
branch_version = (
apps[app]["branch_version"].split(" ", 1)[0] if apps[app].get("branch_version", "") else ""
)
instance_version = Version(branch_version or apps[app].get("version"))

github_version, org_name = check_release_on_github(owner, repo, instance_version)
if not github_version or not org_name:
continue

# Compare and popup update message
for update_type in updates:
if github_version.__dict__[update_type] > instance_version.__dict__[update_type]:
Expand All @@ -213,7 +214,7 @@ def has_app_update_notifications() -> bool:
return bool(frappe.cache.sismember("update-user-set", frappe.session.user))


def parse_latest_non_beta_release(response: list) -> list | None:
def parse_latest_non_beta_release(response: list, current_version: Version) -> list | None:
"""Parse the response JSON for all the releases and return the latest non prerelease.
Args:
Expand All @@ -226,13 +227,19 @@ def parse_latest_non_beta_release(response: list) -> list | None:
release.get("tag_name").strip("v") for release in response if not release.get("prerelease")
]

def prioritize_minor_update(v: str) -> Version:
target = Version(v)
return (current_version.major == target.major, target)

if version_list:
return sorted(version_list, key=Version, reverse=True)[0]
return sorted(version_list, key=prioritize_minor_update, reverse=True)[0]

return None


def check_release_on_github(owner: str, repo: str) -> tuple[Version, str] | tuple[None, None]:
def check_release_on_github(
owner: str, repo: str, current_version: Version
) -> tuple[Version, str] | tuple[None, None]:
"""Check the latest release for a repo URL on GitHub."""
import requests

Expand All @@ -245,7 +252,7 @@ def check_release_on_github(owner: str, repo: str) -> tuple[Version, str] | tupl
# Get latest version from GitHub
r = requests.get(f"https://api.github.com/repos/{owner}/{repo}/releases")
if r.ok:
latest_non_beta_release = parse_latest_non_beta_release(r.json())
latest_non_beta_release = parse_latest_non_beta_release(r.json(), current_version)
if latest_non_beta_release:
return Version(latest_non_beta_release), owner

Expand Down

0 comments on commit 45026ae

Please sign in to comment.