redmine_plugins_helper 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/init.rb +1 -1
- data/lib/redmine_plugins_helper.rb +2 -0
- data/lib/redmine_plugins_helper/fix_migrations.rb +10 -5
- data/lib/redmine_plugins_helper/migrate.rb +7 -6
- data/lib/redmine_plugins_helper/migrations.rb +7 -3
- data/lib/redmine_plugins_helper/patches/redmine/plugin_migration_context.rb +1 -1
- data/lib/redmine_plugins_helper/patches/redmine/plugin_patch.rb +21 -1
- data/lib/redmine_plugins_helper/patches/test_case_patch.rb +3 -1
- data/lib/redmine_plugins_helper/plugin_rake_task.rb +35 -0
- data/lib/redmine_plugins_helper/settings.rb +3 -0
- data/lib/redmine_plugins_helper/status_migrations.rb +3 -1
- data/lib/redmine_plugins_helper/test_config.rb +2 -0
- data/lib/redmine_plugins_helper/version.rb +1 -1
- data/lib/tasks/redmine.rake +54 -0
- data/lib/tasks/redmine_plugins_helper.rake +3 -51
- metadata +39 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42a61e097f13a79e25e3342f2d1a22f973fd19503642b652987d881d17257b6d
|
4
|
+
data.tar.gz: 42ba8680e2290f75e6eb0199664c2fe379a08ef57089b276cd0e20fafd65a434
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 390655cc975957070353753c0f04bbc24e26ccb96b45ed2a63f15d8b0a9b797085762188906fc8ab406741caf48dfbbab175c123dce4ef06c6547f64770d6d82
|
7
|
+
data.tar.gz: 3e5b2506f6f4e39a58f483bf31d81d1f4a101cbc17f7b8bb15a043a6fffa116ebd411c86c187c7a158c52cd29fb5a5c8a837572ad8e459698635342fcc987482
|
data/init.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RedminePluginsHelper
|
2
4
|
class FixMigrations
|
3
5
|
def initialize
|
@@ -17,6 +19,7 @@ module RedminePluginsHelper
|
|
17
19
|
def check_database_version(dbv)
|
18
20
|
lv = local_version(dbv[:timestamp])
|
19
21
|
return unless lv && lv.count == 1 && dbv[:plugin] != lv.first[:plugin]
|
22
|
+
|
20
23
|
fix_plugin_version(dbv, lv.first[:plugin])
|
21
24
|
end
|
22
25
|
|
@@ -41,18 +44,19 @@ module RedminePluginsHelper
|
|
41
44
|
def move_plugin_version(source_version, target_version)
|
42
45
|
Rails.logger.info("Moving #{source_version} to plugin \"#{target_version}\"")
|
43
46
|
::ActiveRecord::SchemaMigration.find_by(version: source_version)
|
44
|
-
|
47
|
+
.update!(version: target_version)
|
45
48
|
end
|
46
49
|
|
47
50
|
def local_version(timestamp)
|
48
51
|
return [] unless local_versions.key?(timestamp)
|
52
|
+
|
49
53
|
local_versions[timestamp]
|
50
54
|
end
|
51
55
|
|
52
56
|
def local_versions
|
53
57
|
@local_versions = begin
|
54
58
|
r = {}
|
55
|
-
Redmine::Plugin.registered_plugins.
|
59
|
+
Redmine::Plugin.registered_plugins.each_value do |p|
|
56
60
|
p.migrations.each do |m|
|
57
61
|
r[m] ||= []
|
58
62
|
r[m] << { plugin: p.id, timestamp: m, version: plugin_version(p.id, m) }
|
@@ -68,15 +72,16 @@ module RedminePluginsHelper
|
|
68
72
|
::RedminePluginsHelper::Migrations.db_all_versions.each do |v|
|
69
73
|
pv = parse_plugin_version(v)
|
70
74
|
next unless pv
|
75
|
+
|
71
76
|
r << pv
|
72
77
|
end
|
73
78
|
r
|
74
79
|
end
|
75
80
|
end
|
76
81
|
|
77
|
-
def parse_plugin_version(
|
78
|
-
h = ::RedminePluginsHelper::Migrations.parse_plugin_version(
|
79
|
-
h[:version] =
|
82
|
+
def parse_plugin_version(version)
|
83
|
+
h = ::RedminePluginsHelper::Migrations.parse_plugin_version(version)
|
84
|
+
h[:version] = version if h.is_a?(Hash)
|
80
85
|
h
|
81
86
|
end
|
82
87
|
|
@@ -30,10 +30,10 @@ module RedminePluginsHelper
|
|
30
30
|
::Redmine::Plugin.migrate(plugin_name, migration_version)
|
31
31
|
end
|
32
32
|
|
33
|
-
def migrate_plugin_version(
|
34
|
-
return if migrated?(
|
33
|
+
def migrate_plugin_version(version)
|
34
|
+
return if migrated?(version)
|
35
35
|
|
36
|
-
::Redmine::Plugin.registered_plugins[
|
36
|
+
::Redmine::Plugin.registered_plugins[version[:plugin]].migrate(version[:timestamp])
|
37
37
|
end
|
38
38
|
|
39
39
|
def versions_sorted
|
@@ -48,9 +48,10 @@ module RedminePluginsHelper
|
|
48
48
|
r
|
49
49
|
end
|
50
50
|
|
51
|
-
def migrated?(
|
52
|
-
return false unless db_versions.key?(
|
53
|
-
|
51
|
+
def migrated?(version)
|
52
|
+
return false unless db_versions.key?(version[:plugin])
|
53
|
+
|
54
|
+
db_versions[version[:plugin]].include?(version[:timestamp])
|
54
55
|
end
|
55
56
|
|
56
57
|
def db_versions
|
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RedminePluginsHelper
|
2
4
|
class Migrations
|
3
5
|
class << self
|
4
6
|
def local_versions
|
5
7
|
r = {}
|
6
|
-
Redmine::Plugin.registered_plugins.
|
8
|
+
Redmine::Plugin.registered_plugins.each_value do |p|
|
7
9
|
p.migrations.each do |ts|
|
8
10
|
r[p.id] ||= []
|
9
11
|
r[p.id] << ts
|
@@ -17,6 +19,7 @@ module RedminePluginsHelper
|
|
17
19
|
db_all_versions.each do |v|
|
18
20
|
pv = parse_plugin_version(v)
|
19
21
|
next unless pv
|
22
|
+
|
20
23
|
r[pv[:plugin]] ||= []
|
21
24
|
r[pv[:plugin]] << pv[:timestamp]
|
22
25
|
end
|
@@ -28,9 +31,10 @@ module RedminePluginsHelper
|
|
28
31
|
::ActiveRecord::SchemaMigration.all.pluck(:version)
|
29
32
|
end
|
30
33
|
|
31
|
-
def parse_plugin_version(
|
32
|
-
m =
|
34
|
+
def parse_plugin_version(version)
|
35
|
+
m = version.match(/^(\d+)\-(\S+)$/)
|
33
36
|
return nil unless m
|
37
|
+
|
34
38
|
{ plugin: m[2].to_sym, timestamp: m[1].to_i }
|
35
39
|
end
|
36
40
|
end
|
@@ -1,3 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
1
5
|
module RedminePluginsHelper
|
2
6
|
module Patches
|
3
7
|
module Redmine
|
@@ -12,6 +16,22 @@ module RedminePluginsHelper
|
|
12
16
|
ASSETS_SUBDIRS = %w[stylesheets javascripts images].freeze
|
13
17
|
|
14
18
|
module ClassMethods
|
19
|
+
def by_path(path)
|
20
|
+
plugin_id_from_path(path).if_present do |v|
|
21
|
+
registered_plugins[v]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def plugin_id_from_path(path)
|
26
|
+
path = path.to_pathname.expand_path
|
27
|
+
return nil unless path.to_path.start_with?(::Rails.root.to_path)
|
28
|
+
|
29
|
+
parts = path.relative_path_from(::Rails.root).each_filename.to_a
|
30
|
+
return nil unless parts.first == 'plugins' && parts.count >= 2
|
31
|
+
|
32
|
+
parts[1].to_sym
|
33
|
+
end
|
34
|
+
|
15
35
|
def post_register(plugin_name, &block)
|
16
36
|
plugin = registered_plugins[plugin_name]
|
17
37
|
raise "Plugin not registered: #{plugin_name}" unless plugin
|
@@ -22,7 +42,7 @@ module RedminePluginsHelper
|
|
22
42
|
|
23
43
|
module InstanceMethods
|
24
44
|
def load_initializers
|
25
|
-
Dir["#{initializers_directory}/*.rb"].each { |f| require f }
|
45
|
+
Dir["#{initializers_directory}/*.rb"].sort.each { |f| require f }
|
26
46
|
end
|
27
47
|
|
28
48
|
ASSETS_SUBDIRS.each do |assert_subdir|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'active_support'
|
2
4
|
|
3
5
|
module RedminePluginsHelper
|
@@ -35,5 +37,5 @@ end
|
|
35
37
|
unless ActiveSupport::TestCase.included_modules.include?(
|
36
38
|
RedminePluginsHelper::Patches::TestCasePatch
|
37
39
|
)
|
38
|
-
ActiveSupport::TestCase.
|
40
|
+
ActiveSupport::TestCase.include RedminePluginsHelper::Patches::TestCasePatch
|
39
41
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'shellwords'
|
5
|
+
|
6
|
+
module RedminePluginsHelper
|
7
|
+
class PluginRakeTask
|
8
|
+
DEFAULT_TASK_NAME_LAST_PART = 'rspec'
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def register(plugin_id, task_name_last_part = DEFAULT_TASK_NAME_LAST_PART)
|
12
|
+
new(plugin_id, task_name_last_part).register
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
common_constructor :plugin_id, :task_name_last_part
|
17
|
+
|
18
|
+
def register
|
19
|
+
::RSpec::Core::RakeTask.new(task_full_name) do |t|
|
20
|
+
t.rspec_opts = ::Shellwords.join(rspec_opts)
|
21
|
+
end
|
22
|
+
Rake::Task[task_full_name].enhance ['db:test:prepare']
|
23
|
+
end
|
24
|
+
|
25
|
+
def task_full_name
|
26
|
+
"#{plugin_id}:#{task_name_last_part}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def rspec_opts
|
30
|
+
['--pattern', "plugins/#{plugin_id}/spec/**/*_spec.rb",
|
31
|
+
'--default-path', 'plugins/redmine_plugins_helper/spec',
|
32
|
+
'--require', 'spec_helper']
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_dependency 'redmine_plugins_helper'
|
2
4
|
|
3
5
|
module RedminePluginsHelper
|
@@ -5,6 +7,7 @@ module RedminePluginsHelper
|
|
5
7
|
class << self
|
6
8
|
def default(plugin, default)
|
7
9
|
return unless ::RedminePluginsHelper.settings_table_exist?
|
10
|
+
|
8
11
|
p = plugin_current_setting_value(plugin)
|
9
12
|
default.each do |k, v|
|
10
13
|
p[k.to_s] = v unless p.key?(k)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module RedminePluginsHelper
|
2
4
|
class StatusMigrations
|
3
5
|
def initialize
|
@@ -10,7 +12,7 @@ module RedminePluginsHelper
|
|
10
12
|
local_versions.each do |plugin, timestamps|
|
11
13
|
timestamps.each do |timestamp|
|
12
14
|
m = migrated_version?(plugin, timestamp) ? 'up' : 'down'
|
13
|
-
|
15
|
+
::Rails.logger.info "#{m}\t#{plugin}\t#{timestamp}"
|
14
16
|
end
|
15
17
|
end
|
16
18
|
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Rake::Task['redmine:plugins:migrate'].clear
|
4
|
+
|
5
|
+
namespace :redmine do
|
6
|
+
desc 'Run migrations of core Redmine and installed plugins.'
|
7
|
+
task migrate: ['db:migrate', 'redmine:plugins:migrate:fix', 'redmine:plugins:migrate'] do
|
8
|
+
end
|
9
|
+
|
10
|
+
namespace :version do
|
11
|
+
desc 'Shows Redmine\'s version.'
|
12
|
+
task show: :environment do
|
13
|
+
puts ::Redmine::VERSION::STRING
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
task version: 'version:show'
|
18
|
+
|
19
|
+
namespace :plugins do
|
20
|
+
desc 'Migrates installed plugins.'
|
21
|
+
task migrate: :environment do
|
22
|
+
name = ENV['NAME']
|
23
|
+
version = nil
|
24
|
+
version_string = ENV['VERSION']
|
25
|
+
if version_string
|
26
|
+
if version_string =~ /^\d+$/
|
27
|
+
version = version_string.to_i
|
28
|
+
abort 'The VERSION argument requires a plugin NAME.' if name.nil?
|
29
|
+
else
|
30
|
+
abort "Invalid VERSION #{version_string} given."
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
begin
|
35
|
+
RedminePluginsHelper::Migrate.new(name, version)
|
36
|
+
Rake::Task['db:schema:dump'].invoke
|
37
|
+
rescue Redmine::PluginNotFound
|
38
|
+
abort "Plugin #{name} was not found."
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
namespace :migrate do
|
43
|
+
desc 'Fix migrations moved from a plugin to another'
|
44
|
+
task fix: :environment do
|
45
|
+
RedminePluginsHelper::FixMigrations.new
|
46
|
+
end
|
47
|
+
|
48
|
+
desc 'Show migrations status of all plugins'
|
49
|
+
task status: :environment do
|
50
|
+
RedminePluginsHelper::StatusMigrations.new
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -1,52 +1,4 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
task migrate: ['db:migrate', 'redmine:plugins:migrate:fix', 'redmine:plugins:migrate'] do
|
6
|
-
end
|
7
|
-
|
8
|
-
namespace :version do
|
9
|
-
desc 'Shows Redmine\'s version.'
|
10
|
-
task show: :environment do
|
11
|
-
puts ::Redmine::VERSION::STRING
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
task version: 'version:show'
|
16
|
-
|
17
|
-
namespace :plugins do
|
18
|
-
desc 'Migrates installed plugins.'
|
19
|
-
task migrate: :environment do
|
20
|
-
name = ENV['NAME']
|
21
|
-
version = nil
|
22
|
-
version_string = ENV['VERSION']
|
23
|
-
if version_string
|
24
|
-
if version_string =~ /^\d+$/
|
25
|
-
version = version_string.to_i
|
26
|
-
abort 'The VERSION argument requires a plugin NAME.' if name.nil?
|
27
|
-
else
|
28
|
-
abort "Invalid VERSION #{version_string} given."
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
begin
|
33
|
-
RedminePluginsHelper::Migrate.new(name, version)
|
34
|
-
Rake::Task['db:schema:dump'].invoke
|
35
|
-
rescue Redmine::PluginNotFound
|
36
|
-
abort "Plugin #{name} was not found."
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
namespace :migrate do
|
41
|
-
desc 'Fix migrations moved from a plugin to another'
|
42
|
-
task fix: :environment do
|
43
|
-
RedminePluginsHelper::FixMigrations.new
|
44
|
-
end
|
45
|
-
|
46
|
-
desc 'Show migrations status of all plugins'
|
47
|
-
task status: :environment do
|
48
|
-
RedminePluginsHelper::StatusMigrations.new
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
3
|
+
require 'redmine_plugins_helper/plugin_rake_task'
|
4
|
+
::RedminePluginsHelper::PluginRakeTask.register(:redmine_plugins_helper, :test)
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redmine_plugins_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- 0.
|
7
|
+
- 0.8.0
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-08-
|
11
|
+
date: 2020-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: eac_ruby_utils
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.43'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.43'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: sass-rails
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -24,6 +38,26 @@ dependencies:
|
|
24
38
|
- - "~>"
|
25
39
|
- !ruby/object:Gem::Version
|
26
40
|
version: '5.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: eac_ruby_gem_support
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.1'
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 0.1.2
|
51
|
+
type: :development
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - "~>"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0.1'
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 0.1.2
|
27
61
|
description:
|
28
62
|
email:
|
29
63
|
executables: []
|
@@ -43,10 +77,12 @@ files:
|
|
43
77
|
- lib/redmine_plugins_helper/patches/redmine/plugin_migration_context.rb
|
44
78
|
- lib/redmine_plugins_helper/patches/redmine/plugin_patch.rb
|
45
79
|
- lib/redmine_plugins_helper/patches/test_case_patch.rb
|
80
|
+
- lib/redmine_plugins_helper/plugin_rake_task.rb
|
46
81
|
- lib/redmine_plugins_helper/settings.rb
|
47
82
|
- lib/redmine_plugins_helper/status_migrations.rb
|
48
83
|
- lib/redmine_plugins_helper/test_config.rb
|
49
84
|
- lib/redmine_plugins_helper/version.rb
|
85
|
+
- lib/tasks/redmine.rake
|
50
86
|
- lib/tasks/redmine_plugins_helper.rake
|
51
87
|
homepage:
|
52
88
|
licenses: []
|