release: 发布版本 60176fa,RuboCop 零告警,网页新增版本号展示
This commit is contained in:
+13
-9
@@ -18,7 +18,7 @@ require 'net/http'
|
||||
require 'uri'
|
||||
|
||||
# @type const RELEASE_SERIAL_CODE: String
|
||||
RELEASE_SERIAL_CODE = 'b43527c'
|
||||
RELEASE_SERIAL_CODE = '60176fa'
|
||||
# @type const CHANNEL: String
|
||||
CHANNEL = 'master'
|
||||
# @type const VERSION_LIST_URL: String
|
||||
@@ -27,42 +27,46 @@ VERSION_LIST_URL = "https://raw.giteeusercontent.com/scu_team/minesentinel/#{CHA
|
||||
RECURSIVE_RETRY_DEPTH = 3
|
||||
|
||||
class UpdateManager
|
||||
# rubocop:disable Metrics/MethodLength
|
||||
# @return [String]
|
||||
def self.fetch
|
||||
MethodExecutor.record("debug", "updates", "Fetching version list from #{VERSION_LIST_URL}")
|
||||
MethodExecutor.record('debug', 'updates', "Fetching version list from #{VERSION_LIST_URL}")
|
||||
uri = URI(VERSION_LIST_URL)
|
||||
response = Net::HTTP.get_response(uri)
|
||||
case response.code.to_i
|
||||
when 200
|
||||
MethodExecutor.record("debug", "updates", "Version list fetched successfully.")
|
||||
MethodExecutor.record('debug', 'updates', 'Version list fetched successfully.')
|
||||
response.body
|
||||
else
|
||||
raise "Unexpected HTTP response code: #{response.code}"
|
||||
end
|
||||
rescue => e
|
||||
MethodExecutor.record("error", "updates", "Failed to fetch version list: #{e}")
|
||||
rescue StandardError => e
|
||||
MethodExecutor.record('error', 'updates', "Failed to fetch version list: #{e}")
|
||||
nil
|
||||
end
|
||||
# rubocop:enable Metrics/MethodLength
|
||||
|
||||
# rubocop:disable Metrics/MethodLength
|
||||
# @return [Hash{Symbol=>Symbol, Symbol=>String}]
|
||||
def self.check
|
||||
raw = fetch
|
||||
if raw.nil?
|
||||
MethodExecutor.record("error", "updates", "Version list is empty, cannot check updates.")
|
||||
raise "Unknown Error"
|
||||
MethodExecutor.record('error', 'updates', 'Version list is empty, cannot check updates.')
|
||||
raise 'Unknown Error'
|
||||
end
|
||||
|
||||
lines = raw.lines(chomp: true)
|
||||
lines.each_with_index do |line, index|
|
||||
line_num = index + 1
|
||||
if line == RELEASE_SERIAL_CODE && line_num == lines.size
|
||||
MethodExecutor.record("info", "updates", "Current version #{RELEASE_SERIAL_CODE} is up to date.")
|
||||
MethodExecutor.record('info', 'updates', "Current version #{RELEASE_SERIAL_CODE} is up to date.")
|
||||
return { type: :Newest, version: RELEASE_SERIAL_CODE }
|
||||
end
|
||||
end
|
||||
|
||||
latest = lines.last
|
||||
MethodExecutor.record("info", "updates", "Newer version #{latest} available (current: #{RELEASE_SERIAL_CODE}).")
|
||||
MethodExecutor.record('info', 'updates', "Newer version #{latest} available (current: #{RELEASE_SERIAL_CODE}).")
|
||||
{ type: :NewerAvailable, version: latest }
|
||||
end
|
||||
# rubocop:enable Metrics/MethodLength
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user