Skip to content

Conversation

@johnharris85
Copy link
Collaborator

This PR adds an online version check when running deck version that will notify the user if there is a newer version, when it was released, and where they can download it. This check can be skipped by passing --suppress-version-check to deck version.

@johnharris85 johnharris85 requested a review from Copilot July 30, 2025 22:36
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds online version checking functionality to the deck version command that notifies users when a newer version is available by querying the GitHub API.

Key changes:

  • Adds GitHub API integration to check for latest release version
  • Implements semantic version comparison logic with comprehensive test coverage
  • Provides a flag to suppress the version check for users who prefer not to have online connectivity

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
cmd/version.go Implements GitHub API client, version comparison logic, and updates version command with optional online checking
cmd/version_test.go Adds comprehensive test coverage for version comparison logic and documents expected API behavior
Comments suppressed due to low confidence (4)

cmd/version_test.go:61

  • The checkLatestVersion function is not actually tested here. Consider refactoring the function to accept a base URL parameter or use dependency injection to make it testable with the mock server.
		// We would need to modify checkLatestVersion to accept a custom URL for testing

cmd/version_test.go:71

  • This test case documents expected behavior but doesn't actually verify it. The error handling behavior of checkLatestVersion should be explicitly tested.
		// The function should return an error but not crash

cmd/version_test.go:81

  • This test case documents expected behavior but doesn't actually verify it. The JSON parsing error handling of checkLatestVersion should be explicitly tested.
		// The function should handle JSON decode errors gracefully

cmd/version_test.go:92

  • This test case documents expected behavior but doesn't actually verify it. The timeout behavior of checkLatestVersion should be explicitly tested.
		// The function should timeout after 2 seconds

Comment on lines +75 to +76
fmt.Sscanf(currentParts[i], "%d", &currentNum)
fmt.Sscanf(latestParts[i], "%d", &latestNum)
Copy link

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fmt.Sscanf ignores errors and will silently fail to parse non-numeric version parts. This could lead to incorrect version comparisons. Consider using strconv.Atoi and handle the error explicitly to ensure reliable version parsing.

Suggested change
fmt.Sscanf(currentParts[i], "%d", &currentNum)
fmt.Sscanf(latestParts[i], "%d", &latestNum)
currentNum, err := strconv.Atoi(currentParts[i])
if err != nil {
// Handle invalid version part (e.g., log error and treat as 0)
currentNum = 0
}
latestNum, err := strconv.Atoi(latestParts[i])
if err != nil {
// Handle invalid version part (e.g., log error and treat as 0)
latestNum = 0
}

Copilot uses AI. Check for mistakes.
Comment on lines +75 to +76
fmt.Sscanf(currentParts[i], "%d", &currentNum)
fmt.Sscanf(latestParts[i], "%d", &latestNum)
Copy link

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fmt.Sscanf ignores errors and will silently fail to parse non-numeric version parts. This could lead to incorrect version comparisons. Consider using strconv.Atoi and handle the error explicitly to ensure reliable version parsing.

Suggested change
fmt.Sscanf(currentParts[i], "%d", &currentNum)
fmt.Sscanf(latestParts[i], "%d", &latestNum)
currentNum, err := strconv.Atoi(currentParts[i])
if err != nil {
currentNum = 0 // Treat invalid parts as 0
}
latestNum, err := strconv.Atoi(latestParts[i])
if err != nil {
latestNum = 0 // Treat invalid parts as 0
}

Copilot uses AI. Check for mistakes.
{"reverse mixed v prefix", "v1.49.2", "1.50.0", true},
{"longer version newer", "1.49.2", "1.49.2.1", true},
{"longer version older", "1.49.2.1", "1.49.2", false},
{"dev version", "dev", "1.49.2", true},
Copy link

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test expects compareVersions("dev", "1.49.2") to return true, but the compareVersions function will treat "dev" as a numeric value (which will parse as 0) and compare it against 1, returning true incorrectly. This test case reveals that the version comparison logic doesn't handle non-semantic version strings properly.

Copilot uses AI. Check for mistakes.
@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 34.42623% with 40 lines in your changes missing coverage. Please review.
✅ Project coverage is 28.26%. Comparing base (933b11b) to head (77435d4).

Files with missing lines Patch % Lines
cmd/version.go 34.42% 40 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1712      +/-   ##
==========================================
+ Coverage   28.19%   28.26%   +0.07%     
==========================================
  Files          67       67              
  Lines        6949     7006      +57     
==========================================
+ Hits         1959     1980      +21     
- Misses       4848     4884      +36     
  Partials      142      142              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants