Skip to content

Commit 23f16a0

Browse files
committed
Add version checking on command
1 parent bdd74b2 commit 23f16a0

File tree

5 files changed

+36
-4
lines changed

5 files changed

+36
-4
lines changed

app/cli.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import click
2+
import requests
23

34
from app.commands import check, download, progress, setup, verify
45
from app.commands.version import version
6+
from app.utils.click_utils import warn
7+
from app.utils.version_utils import Version
8+
from app.version import __version__
59

610

711
@click.group()
@@ -11,6 +15,13 @@ def cli(ctx, verbose) -> None:
1115
"""Git-Mastery CLI"""
1216
ctx.ensure_object(dict)
1317
ctx.obj["VERBOSE"] = verbose
18+
current_version = Version.parse_version_string(__version__)
19+
tags = requests.get("https://api.github.com/repos/git-mastery/app/tags").json()
20+
latest_version = Version.parse_version_string(tags[0]["name"])
21+
if current_version.is_behind(latest_version):
22+
warn(
23+
f"Your version of Git-Mastery CLI {click.style(current_version, bold=True)} is behind the latest version {click.style(latest_version, bold=True, italic=True)}. Please update the CLI."
24+
)
1425

1526

1627
def start() -> None:

app/commands/verify.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from app.commands.progress.constants import (
1717
LOCAL_FOLDER_NAME,
1818
PROGRESS_REPOSITORY_NAME,
19-
STUDENT_PROGRESS_FORK_NAME,
2019
)
2120
from app.utils.click_utils import error, info, warn
2221
from app.utils.gh_cli_utils import get_prs, get_username, pull_request
@@ -45,7 +44,6 @@ def print_output(output: GitAutograderOutput) -> None:
4544

4645
def submit_progress(output: GitAutograderOutput, verbose: bool) -> None:
4746
username = get_username(verbose)
48-
progress_name = STUDENT_PROGRESS_FORK_NAME.format(username=username)
4947

5048
gitmastery_root_path, _, gitmastery_config = require_gitmastery_root()
5149
progress_local = gitmastery_config.get("progress_local", False)

app/commands/version.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import click
22

33
from app.utils.click_utils import info
4+
from app.utils.version_utils import Version
45
from app.version import __version__
56

67

78
@click.command()
89
@click.pass_context
910
def version(_: click.Context) -> None:
10-
info(f"Git-Mastery CLI is currently {__version__}")
11+
current_version = Version.parse_version_string(__version__)
12+
info(f"Git-Mastery CLI is {click.style(current_version, bold=True, italic=True)}")

app/utils/version_utils.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from dataclasses import dataclass
2+
3+
4+
@dataclass
5+
class Version:
6+
major: int
7+
minor: int
8+
patch: int
9+
10+
@staticmethod
11+
def parse_version_string(version: str) -> "Version":
12+
only_version = version[1:]
13+
[major, minor, patch] = only_version.split(".")
14+
return Version(int(major), int(minor), int(patch))
15+
16+
def is_behind(self, other: "Version") -> bool:
17+
"""Returns if the current version is behind the other version based on major and minor versions."""
18+
return (other.major, other.minor) > (self.major, self.minor)
19+
20+
def __repr__(self) -> str:
21+
return f"v{self.major}.{self.minor}.{self.patch}"

app/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.0.0-dev"
1+
__version__ = "v0.0.0"

0 commit comments

Comments
 (0)