0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-04 10:39:43 +08:00
discourse/spec/support/mock_git_importer.rb
David Taylor 45d9ae88e7
FEATURE: Show theme d-compat/* refs in admin UI (#40649)
When a remote theme is installed or updated from a git repository,
Discourse may check out a compatibility-pinned ref (a `d-compat/YYYY.MM`
branch or a `.discourse-compatibility` entry) rather than the requested
branch.

Previously this wasn't obvious in the UI. This commit surfaces the
currently-running compatibility reference, and the compatibility
reference of any pending update.

<img width="650" height="293" alt="image"
src="https://github.com/user-attachments/assets/11137fbd-e6e3-4786-8234-5799965d05c6"
/>
2026-06-17 22:13:45 +01:00

57 lines
1.1 KiB
Ruby
Vendored

# frozen_string_literal: true
class MockGitImporter < ThemeStore::GitImporter
attr_reader :s3_client
class << self
def with_mock
git_importer = ThemeStore::GitImporter
ThemeStore.send(:remove_const, :GitImporter)
ThemeStore.const_set(:GitImporter, MockGitImporter)
begin
yield
ensure
ThemeStore.send(:remove_const, :GitImporter)
ThemeStore.const_set(:GitImporter, git_importer)
end
end
def register(url, path)
repos[url] = path
url
end
def [](url)
repos.fetch(url)
end
def reset!
@repos = nil
end
private
def repos
@repos ||= {}
end
end
def initialize(url, private_key: nil, branch: nil)
@url = url
@private_key = private_key
@branch = branch
@temp_folder = "#{Pathname.new(Dir.tmpdir).realpath}/discourse_theme_#{SecureRandom.hex}"
end
def import!
begin
path = MockGitImporter[@url]
rescue KeyError
raise_import_error!
end
Discourse::Utils.execute_command("git", "clone", path, @temp_folder)
checkout_compatible_version!
end
end