redmine_with_git 0.1.6 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 58274eb6dc1553a0fc31d5b096d9a01793cb7c87d23936c3efc08d71362482ac
4
- data.tar.gz: 3b49e6376dc0235caa9e8f7a425058e78b7fe4e971c6db47250da4773d336b04
3
+ metadata.gz: a34a6641c46dca0c41d62bdc1e816c9f4570092c09115b2e51976e6a42f27faf
4
+ data.tar.gz: 4d4e3099dae281d66f3b8dd5fd6fa19dff1e9f460eae9edcd6778b0a9d851cd7
5
5
  SHA512:
6
- metadata.gz: 07cd5541197837d3f9fde3025e0f5f2d7d14e9f06360799b13870b3a2bcecd48217abc2aa4b2b33d2a8636091cd17f5bc98dc749218afeb76c8b58af0f8af47a
7
- data.tar.gz: 53ae4211b01ea05301056b3cb86c0b18428a07f46ae4075fbaf38d1eb1b3becf0f39a1f22e6924e1532d2694b37fd2e75090a933a134ac2ed444d4514f96e99e
6
+ metadata.gz: e96d18022267e48569eb1b41195bb68b8684d6a7ce935ba22af72c28d37fb1377a48e152e1a8a00fd48f434fa6f27d2936602731811540b0126adc5679dcf08d
7
+ data.tar.gz: 5d34f055c0a6ff833f242d63e520d0a9ec9bd2dff7cccf468a1acc8df7183017385b56cbc5b7beba449a4dff7d039ceaa8d65b5a446cc149de3c791feb4be772
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class RedmineWithGitController < ApplicationController
2
4
  before_filter :require_admin
3
5
 
@@ -42,7 +44,8 @@ class RedmineWithGitController < ApplicationController
42
44
 
43
45
  def import_params
44
46
  ps = params[::RedmineWithGit::Tableless::Load.model_name.param_key]
45
- return {} unless ps.present?
47
+ return {} if ps.blank?
48
+
46
49
  ps.permit(:path)
47
50
  end
48
51
  end
@@ -1,15 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RedmineWithGitHelper
2
4
  def export_api_curl_command
3
5
  curl_command("curl -JLO '#{export_redmine_with_git_url(key: User.current.api_key)}'")
4
6
  end
5
7
 
6
8
  def import_api_curl_command
7
- curl_command(<<IMPORT_CURL)
8
- curl -X POST \\
9
- -F '#{import_param_key}=@<PATH_TO_BACKUP_FILE>' \\
10
- -F 'key=#{User.current.api_key}' \\
11
- #{import_redmine_with_git_url(format: 'json')}
12
- IMPORT_CURL
9
+ curl_command(<<~IMPORT_CURL)
10
+ curl -X POST \\
11
+ -F '#{import_param_key}=@<PATH_TO_BACKUP_FILE>' \\
12
+ -F 'key=#{User.current.api_key}' \\
13
+ #{import_redmine_with_git_url(format: 'json')}
14
+ IMPORT_CURL
13
15
  end
14
16
 
15
17
  private
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RedmineWithGit
2
4
  module Tableless
3
5
  class Load < ::EacRailsUtils::TablelessModel
@@ -7,10 +9,11 @@ module RedmineWithGit
7
9
 
8
10
  def save
9
11
  return false unless valid?
12
+
10
13
  ::RedmineWithGit::Load::All.new(path.path)
11
14
  true
12
- rescue StandardError => ex
13
- errors.add(:path, ex.message)
15
+ rescue StandardError => e
16
+ errors.add(:path, e.message)
14
17
  false
15
18
  end
16
19
 
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Redmine::Plugin.post_register :redmine_with_git do
2
4
  # Source: https://github.com/esquilo-azul/redmine_plugins_helper
3
- requires_redmine_plugin(:redmine_plugins_helper, version_or_higher: '0.4.0')
5
+ requires_redmine_plugin(:redmine_plugins_helper, version_or_higher: '0.5.0')
4
6
  # Source: https://github.com/jbox-web/redmine_bootstrap_kit.git
5
7
  # Note: redmine_bootstrap_kit is a redmine_git_hosting's dependency.
6
8
  requires_redmine_plugin(:redmine_bootstrap_kit, version_or_higher: '0.2.5')
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  patches_root = ::File.dirname(::File.dirname(__dir__))
2
4
  Dir["#{patches_root}/lib/**/*.rb"].each do |f|
3
5
  load(f)
@@ -1,2 +1,10 @@
1
1
  en:
2
+ eac_ruby_utils:
3
+ listable:
4
+ redmine_with_git/dump/base:
5
+ overwrite:
6
+ allowed:
7
+ label: Allowed
8
+ denied:
9
+ label: Denied
2
10
  field_path: Path
@@ -1,2 +1,10 @@
1
1
  pt-BR:
2
+ eac_ruby_utils:
3
+ listable:
4
+ redmine_with_git/dump/base:
5
+ overwrite:
6
+ allowed:
7
+ label: Permitido
8
+ denied:
9
+ label: Negado
2
10
  field_path: Caminho
data/config/routes.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RedmineApp::Application.routes.draw do
2
4
  get '/redmine_with_git', to: 'redmine_with_git#index', as: 'redmine_with_git'
3
5
  get '/redmine_with_git/export', to: 'redmine_with_git#export', as: 'export_redmine_with_git'
data/init.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'redmine'
2
4
  require 'redmine_with_git/version'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RedmineWithGit
2
4
  module Dump
3
5
  class All < ::RedmineWithGit::Dump::Base
@@ -7,13 +9,13 @@ module RedmineWithGit
7
9
 
8
10
  def run_command
9
11
  on_temp_dir do
10
- RESOURCES.each { |a| build_sub(a) }
12
+ RESOURCES.each { |resource| build_sub(resource) }
11
13
  super
12
14
  end
13
15
  end
14
16
 
15
- def build_sub(a)
16
- resource_class(a).new(resource_file_path(a), overwrite)
17
+ def build_sub(resource)
18
+ resource_class(resource).new(resource_file_path(resource), overwrite)
17
19
  end
18
20
 
19
21
  def build_command
@@ -1,21 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/files/rotate'
4
+ require 'eac_ruby_utils/listable'
5
+
1
6
  module RedmineWithGit
2
7
  module Dump
3
8
  class Base < ::RedmineWithGit::DumpLoad::Base
4
- def initialize(path, overwrite)
5
- @overwrite = overwrite
9
+ include ::EacRubyUtils::Listable
10
+
11
+ lists.add_integer :overwrite, 1 => :denied, 2 => :allowed, 3 => :rotate
12
+
13
+ def initialize(path, options = {})
14
+ @options = options
15
+ validate_overwrite
6
16
  super(path)
7
17
  end
8
18
 
9
- private
19
+ def overwrite
20
+ v = @options[:overwrite]
21
+ v.present? ? v.to_i : OVERWRITE_DENIED
22
+ end
10
23
 
11
- attr_reader :overwrite
24
+ private
12
25
 
13
26
  def run
14
27
  start_banner
15
- if ::File.exist?(path) && !overwrite
16
- Rails.logger.warn "File \"#{path}\" already exists"
17
- return
18
- end
28
+ return unless run_if_overwrite_denied
29
+ return unless run_if_rotate
30
+
19
31
  run_command
20
32
  validate_exported
21
33
  end_banner
@@ -23,29 +35,56 @@ module RedmineWithGit
23
35
 
24
36
  def start_banner
25
37
  Rails.logger.info "Dumping resource \"#{resource_name}\" to \"#{path}\"..."
38
+ Rails.logger.info "Overwrite: #{overwrite}"
26
39
  end
27
40
 
28
41
  def end_banner
29
42
  Rails.logger.info("#{path}: #{number_to_human_size(::File.size(path))}, #{path_type}")
30
43
  end
31
44
 
45
+ def run_if_overwrite_denied
46
+ if ::File.exist?(path) && overwrite == OVERWRITE_DENIED
47
+ Rails.logger.warn "File \"#{path}\" already exists"
48
+ false
49
+ else
50
+ true
51
+ end
52
+ end
53
+
54
+ def run_if_rotate
55
+ if ::File.exist?(path) && overwrite == OVERWRITE_ROTATE
56
+ rotate = ::Avm::Files::Rotate.new(path)
57
+ ::Rails.logger.info "Rotating \"#{rotate.source_path}\"..."
58
+ rotate.run
59
+ ::Rails.logger.info "Rotated to \"#{rotate.target_path}\""
60
+ end
61
+ true
62
+ end
63
+
32
64
  def run_command
33
65
  build_command.execute!(output_file: path)
34
66
  end
35
67
 
36
68
  def create_tar_command(dir, compression = true)
37
69
  tar = "cd #{Shellwords.escape(dir)}; tar -c *"
38
- tar << " | #{compress_args.join(' ')}" if compression
70
+ tar += " | #{compress_args.join(' ')}" if compression
39
71
  env.command(['bash', '-c', tar])
40
72
  end
41
73
 
42
74
  def compress_args
43
- %w(gzip -9 -c -)
75
+ %w[gzip -9 -c -]
44
76
  end
45
77
 
46
78
  def validate_exported
47
79
  raise "File \"#{path}\" was not generated" unless ::File.exist?(path)
48
- raise "File \"#{path}\" has zero size" unless ::File.size(path) > 0
80
+ raise "File \"#{path}\" has zero size" unless ::File.size(path).positive?
81
+ end
82
+
83
+ def validate_overwrite
84
+ klass = ::RedmineWithGit::Dump::Base
85
+ return if klass.lists.overwrite.values.include?(overwrite)
86
+
87
+ raise "Invalid overwrite value: \"#{overwrite}\" (Valid: #{klass.lists.overwrite.values})"
49
88
  end
50
89
  end
51
90
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RedmineWithGit
2
4
  module Dump
3
5
  class Database < ::RedmineWithGit::Dump::Base
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RedmineWithGit
2
4
  module Dump
3
5
  class Files < ::RedmineWithGit::Dump::Base
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RedmineWithGit
2
4
  module Dump
3
5
  class Git < ::RedmineWithGit::Dump::Base
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RedmineWithGit
2
4
  module DumpLoad
3
5
  module All
4
- DATABASE = 'database.gz'.freeze
5
- FILES = 'files.tar.gz'.freeze
6
- GIT = 'git.tar.gz'.freeze
6
+ DATABASE = 'database.gz'
7
+ FILES = 'files.tar.gz'
8
+ GIT = 'git.tar.gz'
7
9
 
8
- RESOURCES = %w(database files git).freeze
10
+ RESOURCES = %w[database files git].freeze
9
11
 
10
12
  private
11
13
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RedmineWithGit
2
4
  module DumpLoad
3
5
  class Base
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RedmineWithGit
2
4
  module DumpLoad
3
5
  module Database
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RedmineWithGit
2
4
  module DumpLoad
3
5
  module Files
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RedmineWithGit
2
4
  module DumpLoad
3
5
  module Git
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RedmineWithGit
2
4
  module Load
3
5
  class All < ::RedmineWithGit::Load::Base
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RedmineWithGit
2
4
  module Load
3
5
  class Base < ::RedmineWithGit::DumpLoad::Base
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_dependency 'redmine_plugins_helper'
2
4
 
3
5
  module RedmineWithGit
@@ -8,9 +10,10 @@ module RedmineWithGit
8
10
  private
9
11
 
10
12
  def before_clear
11
- raise(<<EOS) unless ::RedminePluginsHelper.settings_table_exist?
12
- Settings table does not exist.
13
- EOS
13
+ raise(<<~MESSAGE) unless ::RedminePluginsHelper.settings_table_exist?
14
+ Settings table does not exist.
15
+ MESSAGE
16
+
14
17
  @redmine_git_hosting_setting = ::Setting.plugin_redmine_git_hosting
15
18
  end
16
19
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RedmineWithGit
2
4
  module Load
3
5
  class Files < ::RedmineWithGit::Load::Base
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RedmineWithGit
2
4
  module Load
3
5
  class Git < ::RedmineWithGit::Load::Base
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RedmineWithGit
2
4
  module Patches
3
5
  module RedmineGitHosting
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RedmineWithGit
4
- VERSION = '0.1.6'.freeze
4
+ VERSION = '0.2.0'
5
5
  end
@@ -1,11 +1,21 @@
1
+ # frozen_string_literal: true
2
+
1
3
  namespace :redmine_with_git do
2
- %w(database files git all).each do |a|
4
+ %w[database files git all].each do |a|
3
5
  namespace :dump do
4
- task a, [:path, :overwrite] => :environment do |_t, args|
5
- ::RedmineWithGit::Dump.const_get(a.camelize).new(args.path, args.overwrite.present?)
6
+ desc <<~DESCRIPTION
7
+ Dump backup file for \"#{a}\" resource(s).
8
+
9
+ Arguments:
10
+ * <path>: path to the dump.
11
+ * [overwrite]: 1: denied, 2: allowed, 3: rotate (Default: 1).
12
+ DESCRIPTION
13
+ task a, %i[path overwrite] => :environment do |_t, args|
14
+ ::RedmineWithGit::Dump.const_get(a.camelize).new(args.path, overwrite: args.overwrite)
6
15
  end
7
16
  end
8
17
  namespace :load do
18
+ desc "Load backup file for \"#{a}\" resource(s)"
9
19
  task a, [:path] => :environment do |_t, args|
10
20
  ::RedmineWithGit::Load.const_get(a.camelize).new(args.path)
11
21
  end
@@ -13,10 +23,10 @@ namespace :redmine_with_git do
13
23
  end
14
24
 
15
25
  desc 'Executa as operações de "Rescue" da configuração do plugin RedmineGitHosting'
16
- task rescue: [:'redmine_git_hosting:install_hook_parameters',
17
- :'redmine_git_hosting:migration_tools:update_repositories_type',
18
- :'redmine_git_hosting:install_hook_files',
19
- :'redmine_git_hosting:fetch_changesets'] do |_t, _args|
26
+ task rescue: %i[redmine_git_hosting:install_hook_parameters
27
+ redmine_git_hosting:migration_tools:update_repositories_type
28
+ redmine_git_hosting:install_hook_files
29
+ redmine_git_hosting:fetch_changesets] do |_t, _args|
20
30
  RedmineGitHosting::GitoliteAccessor.update_projects(
21
31
  'all',
22
32
  message: 'Forced resync of all projects (active, closed, archived)...',
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redmine_with_git
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esquilo Azul Company
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-27 00:00:00.000000000 Z
11
+ date: 2019-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: avm-tools
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.2'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: eac_rails_utils
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -30,20 +44,14 @@ dependencies:
30
44
  requirements:
31
45
  - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '0.1'
34
- - - ">="
35
- - !ruby/object:Gem::Version
36
- version: 0.1.2
47
+ version: '0.10'
37
48
  type: :runtime
38
49
  prerelease: false
39
50
  version_requirements: !ruby/object:Gem::Requirement
40
51
  requirements:
41
52
  - - "~>"
42
53
  - !ruby/object:Gem::Version
43
- version: '0.1'
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: 0.1.2
54
+ version: '0.10'
47
55
  description:
48
56
  email:
49
57
  executables: []