Class: CIRunner::VersionVerifier

Inherits:
Object
  • Object
show all
Defined in:
lib/ci_runner/version_verifier.rb

Overview

Class used to check if a newer version of CI Runner has been released. This is used to inform the user to update its gem.

The check only runs every week.

Constant Summary collapse

SEVEN_DAYS =
86_400 * 7

Instance Method Summary collapse

Instance Method Details

#last_checkedPathname

Path of a file used to store when we last checked for a release.

Returns:

  • (Pathname)


40
41
42
# File 'lib/ci_runner/version_verifier.rb', line 40

def last_checked
  Configuration::User.instance.config_directory.join("last-checked")
end

#new_ci_runner_version?Boolean

Check if the user is running the latest version of CI Runner.

Returns:

  • (Boolean)


16
17
18
19
20
21
22
23
# File 'lib/ci_runner/version_verifier.rb', line 16

def new_ci_runner_version?
  return false unless check?

  fetch_upstream_version
  FileUtils.touch(last_checked)

  upstream_version > Gem::Version.new(VERSION)
end

#upstream_versionGem::Version Also known as: fetch_upstream_version

Makes a request to GitHub to get the latest release on the Edouard-chin/ci_runner repository

Returns:

  • (Gem::Version)

    An instance of Gem::Version



28
29
30
31
32
33
34
# File 'lib/ci_runner/version_verifier.rb', line 28

def upstream_version
  @upstream_version ||= begin
    release = Client::Github.new(Configuration::User.instance.github_token).latest_release("Edouard-chin/ci_runner")

    Gem::Version.new(release["tag_name"].sub(/\Av/, ""))
  end
end