Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display real branch name in rex state output #39

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions lib/rexer.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
module Rexer
def self.definition_file
".extensions.rb"
end

def self.definition_lock_file
".extensions.lock"
end

Config = Data.define(
# The prefix of the command such as bundle install and bin/rails redmine:plugins:migrate.
#
Expand All @@ -21,6 +13,14 @@ def self.definition_lock_file
class << self
attr_accessor :verbosity

def definition_file
".extensions.rb"
end

def definition_lock_file
".extensions.lock"
end

def config
@config ||= Config.new(command_prefix: ENV["REXER_COMMAND_PREFIX"])
end
Expand Down
27 changes: 20 additions & 7 deletions lib/rexer/commands/envs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ def call
defined_envs.each.with_index do |env, i|
puts env

definition_with(env).then { _1.themes + _1.plugins }.each do
puts " #{_1.name} (#{Source.from_definition(_1.source).info})"
themes_in(env) do
print_extension_definition(_1)
end

plugins_in(env) do
print_extension_definition(_1)
end

puts if i < defined_envs.size - 1
Expand All @@ -22,11 +26,20 @@ def call

attr_reader :definition

def definition_with(env)
definition.with(
plugins: definition.plugins.select { _1.env == env },
themes: definition.themes.select { _1.env == env }
)
def print_extension_definition(extension_def)
puts " #{extension_def.name} (#{Source.from_definition(extension_def.source).info})"
end

def themes_in(env)
definition.themes.each do
yield _1 if _1.env == env
end
end

def plugins_in(env)
definition.plugins.each do
yield _1 if _1.env == env
end
end
end
end
Expand Down
22 changes: 10 additions & 12 deletions lib/rexer/commands/state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,27 @@ def call
attr_reader :lock_definition

def print_plugins
plugins = lock_definition.plugins
return if plugins.empty?
plugin_defs = lock_definition.plugins
return if plugin_defs.empty?

puts "\nPlugins:"
plugins.each do
puts " * #{_1.name} (#{source_info(_1.source)})"
plugin_defs.each do
plugin = Extension::Entity::Plugin.new(_1)
puts " * #{plugin.name} (#{plugin.source_info})"
end
end

def print_themes
themes = lock_definition.themes
return if themes.empty?
theme_defs = lock_definition.themes
return if theme_defs.empty?

puts "\nThemes:"
themes.each do
puts " * #{_1.name} (#{source_info(_1.source)})"
theme_defs.each do
theme = Extension::Entity::Theme.new(_1)
puts " * #{theme.name} (#{theme.source_info})"
end
end

def source_info(definition_source)
Source.from_definition(definition_source).info
end

def no_lock_file_found
lock_definition.nil?.tap { |result|
puts "No lock file found" if result
Expand Down
55 changes: 55 additions & 0 deletions lib/rexer/extension/entity.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
require "active_support/core_ext/class/attribute"

module Rexer
module Extension
module Entity
class Base
class_attribute :root_dir

def initialize(definition)
@definition = definition
@hooks = definition.hooks || {}
@name = definition.name
end

attr_reader :hooks, :name

def exist?
path.exist? && !path.empty?
end

def path
@path ||= root_dir.join(name.to_s)
end

def source_info
@source_info ||= source.info(path)
end

def source
@source ||= Source.from_definition(definition.source)
end

private

attr_reader :definition
end

class Plugin < Base
self.root_dir = Pathname.new("plugins")

def contains_db_migrations?
path.join("db", "migrate").then { _1.exist? && !_1.empty? }
end

def contains_gemfile?
path.join("Gemfile").exist?
end
end

class Theme < Base
self.root_dir = Pathname.new("themes")
end
end
end
end
27 changes: 4 additions & 23 deletions lib/rexer/extension/plugin/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,21 @@ class Action

def initialize(definition)
@definition = definition
@name = definition.name
@hooks = definition.hooks || {}
@plugin = Entity::Plugin.new(definition)
end

private

attr_reader :name, :hooks, :definition

def plugin_root_dir
Pathname.new("plugins")
end

def plugin_dir
@plugin_dir ||= plugin_root_dir.join(name.to_s)
end

def plugin_exists?
plugin_dir.exist? && !plugin_dir.empty?
end
attr_reader :plugin

def needs_db_migration?
plugin_dir.join("db", "migrate").then {
_1.exist? && !_1.empty?
}
plugin.contains_db_migrations?
end

def run_db_migrate(extra_envs = {})
return unless needs_db_migration?

envs = {"NAME" => name.to_s}.merge(extra_envs)
envs = {"NAME" => plugin.name.to_s}.merge(extra_envs)
cmds = build_cmd("bundle", "exec", "rake", Rexer.verbosity.debug? ? nil : "-q", "redmine:plugins:migrate", envs:)

broadcast(:processing, "Execute #{cmds}")
Expand All @@ -51,10 +36,6 @@ def run_db_migrate(extra_envs = {})
end
end

def source
@source ||= Source.from_definition(definition.source)
end

def build_cmd(*command, envs: {})
envs_str = envs.map { [_1, _2].join("=") }
[Rexer.config.command_prefix, *command, *envs_str].compact.join(" ")
Expand Down
14 changes: 9 additions & 5 deletions lib/rexer/extension/plugin/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,40 @@ module Extension
module Plugin
class Install < Action
def call
broadcast(:started, "Install #{name}")
broadcast(:started, "Install #{plugin.name}")

if plugin_exists?
if plugin.exist?
broadcast(:skipped, "Already exists")
return
end

load_from_source
run_bundle_install
run_db_migrate
hooks[:installed]&.call
call_installed_hook

broadcast(:completed)
end

private

def load_from_source
source.load(plugin_dir.to_s)
plugin.source.load(plugin.path.to_s)
end

def run_bundle_install
return unless plugin_dir.join("Gemfile").exist?
return unless plugin.contains_gemfile?

cmds = build_cmd("bundle", "install", Rexer.verbosity.debug? ? nil : "--quiet")

broadcast(:processing, "Execute #{cmds}")

system(cmds, exception: true)
end

def call_installed_hook
plugin.hooks[:installed]&.call
end
end
end
end
Expand Down
10 changes: 4 additions & 6 deletions lib/rexer/extension/plugin/reload_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module Extension
module Plugin
class ReloadSource < Action
def call
return unless plugin_exists?
return unless plugin.exist?

broadcast(:started, "Reload #{name} source")
broadcast(:started, "Reload #{plugin.name} source")

reload_source
run_db_migrate
Expand All @@ -16,10 +16,8 @@ def call
private

def reload_source
plugin_dir.to_s.then { |dir|
FileUtils.rm_rf(dir)
source.load(dir)
}
plugin.path.rmtree
plugin.source.load(plugin.path.to_s)
end
end
end
Expand Down
12 changes: 8 additions & 4 deletions lib/rexer/extension/plugin/uninstall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ module Extension
module Plugin
class Uninstall < Action
def call
broadcast(:started, "Uninstall #{name}")
broadcast(:started, "Uninstall #{plugin.name}")

unless plugin_exists?
unless plugin.exist?
broadcast(:skipped, "Not exists")
return
end

reset_db_migration
remove_plugin
hooks[:uninstalled]&.call
call_uninstalled_hook

broadcast(:completed)
end
Expand All @@ -24,7 +24,11 @@ def reset_db_migration
end

def remove_plugin
plugin_dir.rmtree
plugin.path.rmtree
end

def call_uninstalled_hook
plugin.hooks[:uninstalled]&.call
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/rexer/extension/plugin/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ module Extension
module Plugin
class Update < Action
def call
return unless plugin_exists?
return unless plugin.exist?

broadcast(:started, "Update #{name}")
broadcast(:started, "Update #{plugin.name}")

unless source.updatable?
unless plugin.source.updatable?
broadcast(:skipped, "Not updatable")
return
end
Expand All @@ -21,7 +21,7 @@ def call
private

def update_source
source.update(plugin_dir.to_s)
plugin.source.update(plugin.path)
end
end
end
Expand Down
28 changes: 2 additions & 26 deletions lib/rexer/extension/theme/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,12 @@ class Action

def initialize(definition)
@definition = definition
@name = definition.name
@hooks = definition.hooks || {}
@theme = Entity::Theme.new(definition)
end

private

attr_reader :name, :hooks, :definition

def theme_root_dir
public_themes = Pathname.pwd.join("public", "themes")

if public_themes.exist?
# When Redmine version is v5.1 or older, public/themes is used.
public_themes
else
Pathname.new("themes")
end
end

def theme_dir
@theme_dir ||= theme_root_dir.join(name.to_s)
end

def theme_exists?
theme_dir.exist? && !theme_dir.empty?
end

def source
@source ||= Source.from_definition(definition.source)
end
attr_reader :theme
end
end
end
Expand Down
Loading