Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions app/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ def invoke(self, ctx: click.Context) -> None:

CONTEXT_SETTINGS = {"max_content_width": 120}

# Bound the release check so the CLI cannot hang on an unresponsive network
LATEST_RELEASE_TIMEOUT_SECONDS = 5
Comment thread
jovnc marked this conversation as resolved.


@click.group(
cls=LoggingGroup,
Expand All @@ -39,14 +42,28 @@ def cli(ctx: click.Context, verbose: bool) -> None:

current_version = Version.parse_version_string(__version__)
ctx.obj[CliContextKey.VERSION] = current_version
latest_version = (
requests.get(
"https://github.com/git-mastery/app/releases/latest", allow_redirects=False

latest_version = None
try:
response = requests.get(
"https://github.com/git-mastery/app/releases/latest",
allow_redirects=False,
timeout=LATEST_RELEASE_TIMEOUT_SECONDS,
)
.headers["Location"]
.rsplit("/", 1)[-1]
)
if current_version.is_behind(Version.parse_version_string(latest_version)):
# GitHub redirects to the tag of the latest release; without the redirect
# there is no version to compare against
location = response.headers.get("Location")
if location is None:
warn(
"Unable to verify the latest version release: no redirect to the latest "
f"release tag (status {response.status_code})"
)
else:
latest_version = Version.parse_version_string(location.rsplit("/", 1)[-1])
except (requests.exceptions.RequestException, ValueError) as e:
warn(f"Unable to verify the latest version release: {e}")

if latest_version is not None and current_version.is_behind(latest_version):
warn(
click.style(
f"Your version of Git-Mastery app {current_version} is behind the latest version {latest_version}.",
Expand Down