Skip to content

Commit 97ebf58

Browse files
committed
Version 1.1 of the hackorum-patch with update checks
This commit adds the necessary infrastructure for the feature both in the web frontend and in the script. In the future, the script will notify users if there is an update.
1 parent 5546abc commit 97ebf58

4 files changed

Lines changed: 88 additions & 1 deletion

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# frozen_string_literal: true
2+
3+
class ScriptsController < ApplicationController
4+
def version
5+
script_name = params[:name]
6+
changelog_path = Rails.root.join("public", "scripts", "#{script_name}.changelog.json")
7+
8+
unless File.exist?(changelog_path)
9+
render json: { error: "Script not found" }, status: :not_found
10+
return
11+
end
12+
13+
cache_key = "scripts/#{script_name}/version/#{File.mtime(changelog_path).to_i}"
14+
15+
changelog_data = Rails.cache.fetch(cache_key, expires_in: 1.day) do
16+
JSON.parse(File.read(changelog_path))
17+
end
18+
19+
render json: changelog_data
20+
end
21+
end

config/routes.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@
7777

7878
# Help pages
7979
resources :help, only: [:index, :show], param: :slug
80+
81+
# Script version endpoint
82+
get "scripts/:name/version", to: "scripts#version", as: :script_version
8083
get "person/*email/contributions/:year", to: "people#contributions", as: :person_contributions, format: false
8184
get "person/*email/activity/:date", to: "people#daily_activity", as: :person_activity, format: false
8285
get "person/*email/activity/month/:year/:month", to: "people#monthly_activity", as: :person_monthly_activity, format: false

public/scripts/hackorum-patch

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ require 'rubygems/package'
1010
require 'zlib'
1111
require 'stringio'
1212
require 'shellwords'
13+
require 'json'
1314

1415
class HackorumPatch
15-
VERSION = '1.0.0'
16+
VERSION = '1.1.0'
1617

1718
def initialize(argv)
1819
@options = {}
@@ -51,6 +52,7 @@ class HackorumPatch
5152

5253
def run
5354
print_banner
55+
check_version
5456
validate_arguments!
5557
validate_git_repository!
5658

@@ -150,6 +152,52 @@ class HackorumPatch
150152
puts ""
151153
end
152154

155+
def check_version
156+
server_url = @server_url || @options[:server] || 'https://hackorum.dev'
157+
version_url = "#{server_url}/scripts/hackorum-patch/version"
158+
159+
begin
160+
uri = URI(version_url)
161+
http = Net::HTTP.new(uri.host, uri.port)
162+
http.use_ssl = uri.scheme == 'https'
163+
http.open_timeout = 2
164+
http.read_timeout = 2
165+
166+
request = Net::HTTP::Get.new(uri)
167+
response = http.request(request)
168+
169+
return unless response.is_a?(Net::HTTPSuccess)
170+
171+
data = JSON.parse(response.body)
172+
remote_version = data['current_version']
173+
174+
return unless remote_version
175+
176+
local_ver = Gem::Version.new(VERSION)
177+
remote_ver = Gem::Version.new(remote_version)
178+
179+
if remote_ver > local_ver
180+
puts "[UPDATE] A newer version (#{remote_version}) is available!"
181+
182+
newer_versions = (data['versions'] || []).select do |v|
183+
Gem::Version.new(v['version']) > local_ver
184+
end
185+
186+
newer_versions.each do |v|
187+
puts " Changes in #{v['version']}:"
188+
(v['changes'] || []).each do |change|
189+
puts " - #{change}"
190+
end
191+
end
192+
193+
puts " Download: #{server_url}/help/hackorum-patch"
194+
puts ""
195+
end
196+
rescue Errno::ECONNREFUSED, Errno::ETIMEDOUT, Net::OpenTimeout, Net::ReadTimeout, JSON::ParserError, SocketError
197+
# Silently ignore version check failures - don't block the script
198+
end
199+
end
200+
153201
def validate_arguments!
154202
if @using_local_file
155203
unless File.exist?(@local_archive)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"current_version": "1.1.0",
3+
"versions": [
4+
{
5+
"version": "1.1.0",
6+
"date": "2026-01-21",
7+
"changes": ["Added version check to notify users of updates"]
8+
},
9+
{
10+
"version": "1.0.0",
11+
"date": "2026-01-17",
12+
"changes": ["Initial release"]
13+
}
14+
]
15+
}

0 commit comments

Comments
 (0)