Skip to content

Commit

Permalink
Check for new version on status command
Browse files Browse the repository at this point in the history
  • Loading branch information
Scheirle committed Mar 7, 2024
1 parent 4045e1d commit 4038802
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions git_gerrit/cli/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from git_gerrit.utils.remotechange import RemoteChange
from git_gerrit.utils.branch import LocalBranch
from git_gerrit.utils.gerrit import Gerrit
from git_gerrit.utils.version import Version

class Status(plumbum.cli.Application):
'''Show status of remote and local changes'''
Expand Down Expand Up @@ -66,3 +67,4 @@ def add_row(nr, subject, status, remote, local, update, owner):
c.update.strftime("%Y-%m-%d %H:%M"),
remote.owner)
console.print(table)
Version.print_version_check()
30 changes: 30 additions & 0 deletions git_gerrit/utils/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# SPDX-FileCopyrightText: 2024-present Bernhard Scheirle
# SPDX-License-Identifier: GPL-3.0-or-later

import packaging.version
import requests
import rich.console

from git_gerrit.__about__ import __version__

class Version:
version = __version__

@staticmethod
def get_latest_version() -> str:
try:
r = requests.get("https://pypi.org/pypi/git-gerrit-bridge/json")
return r.json()["info"]["version"]
except:
return Version.version

@staticmethod
def print_version_check():
latest = packaging.version.parse(Version.get_latest_version())
current = packaging.version.parse(Version.version)
if current < latest:
console = rich.console.Console()
console.print()
console.print(
(" [red]![/] New version of [turquoise2]git gerrit[/] available: "
f"{latest} (Currently installed {current})"))
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ classifiers = [
"Topic :: Software Development :: Version Control :: Git",
]
dependencies = [
"packaging",
"plumbum",
"requests",
"rich",
]

Expand Down

0 comments on commit 4038802

Please sign in to comment.