papa 0.3.0 → 0.4.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.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/CHANGELOG.md +5 -0
  4. data/README.md +22 -2
  5. data/exe/papa +1 -1
  6. data/lib/papa/cli/hotfix.rb +27 -28
  7. data/lib/papa/cli/integration.rb +10 -9
  8. data/lib/papa/cli/main.rb +34 -0
  9. data/lib/papa/cli/release.rb +25 -38
  10. data/lib/papa/cli/sandbox.rb +14 -12
  11. data/lib/papa/command/base.rb +48 -0
  12. data/lib/papa/command/git/branch.rb +15 -0
  13. data/lib/papa/command/git/branch_delete.rb +14 -0
  14. data/lib/papa/command/git/checkout.rb +22 -0
  15. data/lib/papa/command/git/fetch.rb +22 -0
  16. data/lib/papa/command/git/merge.rb +33 -0
  17. data/lib/papa/command/git/merge_abort.rb +14 -0
  18. data/lib/papa/command/git/pull.rb +14 -0
  19. data/lib/papa/command/git/push.rb +14 -0
  20. data/lib/papa/command/git/push_force.rb +14 -0
  21. data/lib/papa/command/git/rebase.rb +39 -0
  22. data/lib/papa/command/git/rebase_abort.rb +14 -0
  23. data/lib/papa/command/git/reset_hard.rb +14 -0
  24. data/lib/papa/command/git/tag.rb +14 -0
  25. data/lib/papa/command/git/tag_push.rb +14 -0
  26. data/lib/papa/command/larga/deploy.rb +63 -0
  27. data/lib/papa/command/larga/type.rb +19 -0
  28. data/lib/papa/helper/output.rb +45 -0
  29. data/lib/papa/helper/path.rb +29 -0
  30. data/lib/papa/helper/vi.rb +63 -0
  31. data/lib/papa/{command_queue.rb → runner.rb} +3 -7
  32. data/lib/papa/task/common/add.rb +117 -0
  33. data/lib/papa/task/common/finish.rb +72 -0
  34. data/lib/papa/task/common/start.rb +44 -0
  35. data/lib/papa/task/deploy.rb +38 -0
  36. data/lib/papa/task/hotfix/add.rb +15 -0
  37. data/lib/papa/task/hotfix/finish.rb +17 -0
  38. data/lib/papa/task/hotfix/start.rb +15 -0
  39. data/lib/papa/task/integration/start.rb +22 -0
  40. data/lib/papa/task/release/add.rb +15 -0
  41. data/lib/papa/task/release/finish.rb +16 -0
  42. data/lib/papa/task/release/start.rb +15 -0
  43. data/lib/papa/{sandbox → task/sandbox}/branches/bugfix/4-fix-charmeleon-spelling/Gemfile +0 -0
  44. data/lib/papa/{sandbox → task/sandbox}/branches/bugfix/5-fix-gem-source/Gemfile +0 -0
  45. data/lib/papa/{sandbox → task/sandbox}/branches/feature/1-add-butterfree-gem/Gemfile +0 -0
  46. data/lib/papa/{sandbox → task/sandbox}/branches/feature/2-add-beedrill-gem/Gemfile +0 -0
  47. data/lib/papa/{sandbox → task/sandbox}/branches/feature/6-add-pidgeotto-gem/Gemfile +0 -0
  48. data/lib/papa/{sandbox → task/sandbox}/branches/feature/7-add-pidgeot-gem/Gemfile +0 -0
  49. data/lib/papa/{sandbox → task/sandbox}/branches/master/Gemfile +0 -0
  50. data/lib/papa/{sandbox → task/sandbox}/branches/patch/17.8.0/3-add-pidgey-gem/Gemfile +0 -0
  51. data/lib/papa/task/sandbox/clean.rb +23 -0
  52. data/lib/papa/task/sandbox/generate.rb +182 -0
  53. data/lib/papa/version.rb +1 -1
  54. data/lib/papa.rb +1 -9
  55. metadata +45 -40
  56. data/lib/papa/cli.rb +0 -34
  57. data/lib/papa/command.rb +0 -45
  58. data/lib/papa/common/add.rb +0 -101
  59. data/lib/papa/common/finish.rb +0 -56
  60. data/lib/papa/common/start.rb +0 -31
  61. data/lib/papa/common.rb +0 -4
  62. data/lib/papa/deploy.rb +0 -48
  63. data/lib/papa/git/checkout.rb +0 -16
  64. data/lib/papa/git/fetch.rb +0 -16
  65. data/lib/papa/git/merge.rb +0 -29
  66. data/lib/papa/git/rebase.rb +0 -29
  67. data/lib/papa/git.rb +0 -71
  68. data/lib/papa/helpers/path.rb +0 -27
  69. data/lib/papa/helpers/vi.rb +0 -60
  70. data/lib/papa/helpers.rb +0 -4
  71. data/lib/papa/hotfix/add.rb +0 -9
  72. data/lib/papa/hotfix/finish.rb +0 -11
  73. data/lib/papa/hotfix/start.rb +0 -9
  74. data/lib/papa/integration/start.rb +0 -17
  75. data/lib/papa/larga/deploy.rb +0 -36
  76. data/lib/papa/larga/type.rb +0 -12
  77. data/lib/papa/larga.rb +0 -18
  78. data/lib/papa/output.rb +0 -43
  79. data/lib/papa/release/add.rb +0 -9
  80. data/lib/papa/release/finish.rb +0 -10
  81. data/lib/papa/release/patch.rb +0 -30
  82. data/lib/papa/release/start.rb +0 -9
  83. data/lib/papa/sandbox/clean.rb +0 -17
  84. data/lib/papa/sandbox/generate.rb +0 -176
@@ -0,0 +1,63 @@
1
+ require 'papa/command/base'
2
+
3
+ module Papa
4
+ module Command
5
+ module Larga
6
+ class Deploy < Command::Base
7
+ RELEASE_OR_HOTFIX_LIFESPAN = '3d'
8
+ DEFAULT_LIFESPAN = '4h'
9
+ RELEASE_OR_HOTFIX_PROTECTION = 'off'
10
+ DEFAULT_PROTECTION = 'on'
11
+
12
+ def initialize(options)
13
+ @options = options
14
+
15
+ command = "larga #{larga_options.join(' ')}"
16
+ super(command, silent: false)
17
+ end
18
+
19
+ def failed?
20
+ stdout.include? 'Cowardly refusing'
21
+ end
22
+
23
+ def failure_message
24
+ message = "Error while running #{command.bold}"
25
+ Helper::Output.error message
26
+ message = 'Larga output:' + @stdout
27
+ Helper::Output.stderr message
28
+ end
29
+
30
+ private
31
+
32
+ def larga_options
33
+ branch = @options[:branch]
34
+ lifespan =
35
+ if branch_is_release_or_hotfix?
36
+ RELEASE_OR_HOTFIX_LIFESPAN
37
+ else
38
+ DEFAULT_LIFESPAN
39
+ end
40
+ protection =
41
+ if branch_is_release_or_hotfix?
42
+ RELEASE_OR_HOTFIX_PROTECTION
43
+ else
44
+ DEFAULT_PROTECTION
45
+ end
46
+ hostname = @options[:hostname]
47
+
48
+ options = []
49
+ options << '-action deploy'
50
+ options << "-branch #{branch}"
51
+ options << "-lifespan #{lifespan}"
52
+ options << "-protection #{protection}"
53
+ options << "-hostname #{hostname}" if hostname
54
+ options
55
+ end
56
+
57
+ def branch_is_release_or_hotfix?
58
+ ['release', 'hotfix'].any? { |s| @options[:branch].include?(s) }
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,19 @@
1
+ require 'papa/command/base'
2
+
3
+ module Papa
4
+ module Command
5
+ module Larga
6
+ class Type < Command::Base
7
+ def initialize
8
+ command = 'type larga'
9
+ super(command)
10
+ end
11
+
12
+ def failure_message
13
+ super
14
+ Helper::Output.stderr 'Larga is not installed in this system'
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,45 @@
1
+ require 'date'
2
+
3
+ module Papa
4
+ module Helper
5
+ class Helper::Output
6
+ REDIRECT_TO_NULL = '> /dev/null 2>&1'
7
+
8
+ def self.stdout(message, options = {})
9
+ puts build_output(message)
10
+ end
11
+
12
+ def self.stderr(message, options = {})
13
+ STDERR.puts build_output(message)
14
+ end
15
+
16
+ def self.error(message)
17
+ stderr("ERROR: #{message}")
18
+ end
19
+
20
+ def self.success(message)
21
+ puts
22
+ puts message.strip.green
23
+ end
24
+
25
+ def self.failure(message)
26
+ STDERR.puts
27
+ STDERR.puts message.strip.red
28
+ end
29
+
30
+ def self.failure_reason(messages)
31
+ messages.each do |message|
32
+ STDERR.puts " #{message}"
33
+ end
34
+ end
35
+
36
+ def self.build_output(message)
37
+ "[#{timestamp}] - #{message}"
38
+ end
39
+
40
+ def self.timestamp
41
+ DateTime.now.strftime('%H:%M:%S')
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,29 @@
1
+ require 'securerandom'
2
+
3
+ module Papa
4
+ module Helper
5
+ class Path
6
+ TMP_PATH = '/tmp/'
7
+ VI_PREFIX = 'papa-vi-'
8
+ SANDBOX_PREFIX = 'papa-sandbox-'
9
+
10
+ def self.generate_vi_file_path
11
+ File.join(TMP_PATH, VI_PREFIX + uuid_gen + '.txt')
12
+ end
13
+
14
+ def self.generate_sandbox_path(type, options = {})
15
+ path =
16
+ if options.has_key?('override_path_prefix')
17
+ options[:override_path_prefix] + '-' + type
18
+ else
19
+ SANDBOX_PREFIX + type + '-' + uuid_gen
20
+ end
21
+ File.join(TMP_PATH, path)
22
+ end
23
+
24
+ def self.uuid_gen
25
+ SecureRandom.uuid
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,63 @@
1
+ require 'papa/helper/path'
2
+ require 'papa/command/base'
3
+
4
+ module Papa
5
+ module Helper
6
+ class Vi
7
+ attr_accessor :path, :branches
8
+
9
+ def initialize
10
+ @path = Helper::Path.generate_vi_file_path
11
+ @branches = []
12
+ end
13
+
14
+ def run
15
+ initialize_file
16
+ prompt_vi
17
+ read_from_file
18
+ delete_file
19
+ validate_branches
20
+ branches
21
+ end
22
+
23
+ private
24
+
25
+ def initialize_file
26
+ content = <<-CONTENT
27
+ # Add your branches here. One branch name per line.
28
+ # Lines starting in pound (#) will be ignored
29
+ # Sample:
30
+ # feature/1-add-butterfree-gem
31
+ # feature/2-add-beedrill-gem
32
+ CONTENT
33
+ File.open(path, 'w') { |file| file.write(content) }
34
+ end
35
+
36
+ def prompt_vi
37
+ system('vi', path)
38
+ end
39
+
40
+ def read_from_file
41
+ @branches = File.read(path).chomp.split("\n").map do |branch|
42
+ branch.strip!
43
+ if branch.empty? || branch[0] == '#'
44
+ nil
45
+ else
46
+ branch
47
+ end
48
+ end.compact
49
+ end
50
+
51
+ def delete_file
52
+ Command::Base.new("rm #{path}", silent: true).run
53
+ end
54
+
55
+ def validate_branches
56
+ if @branches.empty?
57
+ Helper::Output.failure 'No branches specified.'
58
+ exit 1
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -1,13 +1,9 @@
1
1
  module Papa
2
- class CommandQueue
2
+ class Runner
3
3
  attr_accessor :queue, :last_command, :success, :last_error
4
4
 
5
- def initialize
6
- @queue = []
7
- end
8
-
9
- def add(command)
10
- @queue.push command
5
+ def initialize(queue)
6
+ @queue = queue || []
11
7
  end
12
8
 
13
9
  def run
@@ -0,0 +1,117 @@
1
+ require 'papa/helper/output'
2
+ require 'papa/command/git/fetch'
3
+ require 'papa/command/git/checkout'
4
+ require 'papa/command/git/reset_hard'
5
+ require 'papa/command/git/rebase'
6
+ require 'papa/command/git/push_force'
7
+ require 'papa/command/git/merge'
8
+ require 'papa/command/git/push'
9
+ require 'papa/command/git/branch_delete'
10
+ require 'papa/runner'
11
+
12
+ module Papa
13
+ module Task
14
+ module Common
15
+ class Add
16
+ def run
17
+ check_branches
18
+
19
+ @build_branch ||= "#{@build_type}/#{@version}"
20
+
21
+ success = true
22
+ @success_branches = []
23
+ @failed_branches = []
24
+
25
+ Helper::Output.stdout "Started adding branches to #{@build_branch.bold}."
26
+
27
+ @branches.each_with_index do |branch, index|
28
+ Helper::Output.stdout "Adding branch #{branch.bold} (#{index + 1} of #{@branches.count})..."
29
+ queue = [
30
+ Command::Git::Fetch.new('origin'),
31
+ Command::Git::Checkout.new(@build_branch),
32
+ Command::Git::Checkout.new(branch),
33
+ Command::Git::ResetHard.new('origin', branch),
34
+ Command::Git::Rebase.new(@build_branch),
35
+ Command::Git::PushForce.new('origin', branch),
36
+ Command::Git::Checkout.new(@build_branch),
37
+ Command::Git::Merge.new(branch),
38
+ Command::Git::Push.new('origin', @build_branch)
39
+ ]
40
+ runner = Runner.new(queue)
41
+
42
+ if runner.run
43
+ @success_branches << branch
44
+ else
45
+ failed_branch = {
46
+ branch: branch,
47
+ message: runner.last_error
48
+ }
49
+ @failed_branches << failed_branch
50
+ success = false
51
+ end
52
+ end
53
+
54
+ success_message
55
+ failure_message
56
+
57
+ if success
58
+ success_cleanup
59
+ else
60
+ failure_cleanup
61
+ exit 1
62
+ end
63
+ end
64
+
65
+ private
66
+
67
+ def check_branches
68
+ return unless @branches.empty?
69
+ require 'papa/helper/vi'
70
+ vi_file_helper = Helper::Vi.new
71
+ @branches = vi_file_helper.run
72
+ end
73
+
74
+ def success_cleanup
75
+ queue = @branches.map { |branch| Command::Git::BranchDelete.new(branch) }
76
+ Runner.new(queue).run
77
+ end
78
+
79
+ def success_message
80
+ return if @success_branches.empty?
81
+ output = ''
82
+ output << "Successfully added these branches to #{@build_branch}:\n"
83
+ @success_branches.each_with_index do |branch, index|
84
+ output << " #{index + 1}.) #{branch}\n"
85
+ end
86
+ Helper::Output.success output
87
+ end
88
+
89
+ def failure_cleanup
90
+ end
91
+
92
+ def failure_message
93
+ return if @failed_branches.empty?
94
+
95
+ output = ''
96
+
97
+ output << "Failed to add these branches to #{@build_branch}:\n"
98
+ @failed_branches.each_with_index do |failed_branch, index|
99
+ branch = failed_branch[:branch]
100
+ message = failed_branch[:message]
101
+ output << " #{index + 1}.) #{branch}\n"
102
+ output << " - #{message}\n"
103
+ end
104
+
105
+ output << "\n"
106
+
107
+ branch_names = @failed_branches.map { |f| f[:branch] }
108
+
109
+ output << "When the above problems are resolved, you can re-run this with:\n"
110
+ output << " papa #{@build_type} add -v #{@version} -b #{branch_names.join(' ')}"
111
+
112
+ Helper::Output.failure output
113
+ end
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,72 @@
1
+ require 'papa/command/git/fetch'
2
+ require 'papa/command/git/checkout'
3
+ require 'papa/command/git/merge'
4
+ require 'papa/command/git/push'
5
+ require 'papa/command/git/tag'
6
+ require 'papa/command/git/tag_push'
7
+ require 'papa/runner'
8
+ require 'papa/helper/output'
9
+
10
+ module Papa
11
+ module Task
12
+ module Common
13
+ class Finish
14
+ def run
15
+ @build_branch ||= "#{@build_type}/#{@version}"
16
+
17
+ success = true
18
+ @success_branches = []
19
+
20
+ @base_branches.each do |branch|
21
+ queue = [
22
+ Command::Git::Fetch.new('origin'),
23
+ Command::Git::Checkout.new(@build_branch),
24
+ Command::Git::Checkout.new(branch),
25
+ Command::Git::Merge.new(@build_branch),
26
+ Command::Git::Push.new('origin', branch)
27
+ ]
28
+ if @tag_name && branch == 'master'
29
+ queue << Command::Git::Tag.new(@tag_name)
30
+ queue << Command::Git::TagPush.new('origin', @tag_name)
31
+ end
32
+ runner = Runner.new(queue)
33
+
34
+ if runner.run
35
+ @success_branches << branch
36
+ else
37
+ success = false
38
+ end
39
+ end
40
+
41
+ success_message if !@success_branches.empty?
42
+
43
+ if !success
44
+ failure_message
45
+ exit 1
46
+ end
47
+ end
48
+
49
+ private
50
+
51
+ def success_message
52
+ output = ''
53
+ output << "Successfully merged #{@build_branch} to these branches:\n"
54
+ @success_branches.each_with_index do |branch, index|
55
+ output << " #{index + 1}.) #{branch}\n"
56
+ end
57
+ Helper::Output.success output
58
+ end
59
+
60
+ def failure_message
61
+ failed_branches = @base_branches - @success_branches
62
+ output = ''
63
+ output << "Failed to merge #{@build_branch} to these branches:\n"
64
+ failed_branches.each_with_index do |branch, index|
65
+ output << " #{index + 1}.) #{branch}\n"
66
+ end
67
+ Helper::Output.failure output
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,44 @@
1
+ require 'papa/command/git/fetch'
2
+ require 'papa/command/git/checkout'
3
+ require 'papa/command/git/branch'
4
+ require 'papa/command/git/push'
5
+ require 'papa/runner'
6
+ require 'papa/helper/output'
7
+
8
+ module Papa
9
+ module Task
10
+ module Common
11
+ class Start
12
+ def run
13
+ @build_branch ||= "#{@build_type}/#{@version}"
14
+
15
+ queue = [
16
+ Command::Git::Fetch.new('origin'),
17
+ Command::Git::Checkout.new(@base_branch),
18
+ Command::Git::Branch.new(@build_branch),
19
+ Command::Git::Checkout.new(@build_branch),
20
+ Command::Git::Push.new('origin', @build_branch)
21
+ ]
22
+ runner = Runner.new(queue)
23
+
24
+ if runner.run
25
+ success_message
26
+ else
27
+ failure_message
28
+ exit 1
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def success_message
35
+ Helper::Output.success "Successfully started new #{@build_type} branch #{@build_branch}"
36
+ end
37
+
38
+ def failure_message
39
+ Helper::Output.failure "There was a problem starting #{@build_type} branch: #{@build_branch}"
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,38 @@
1
+ require 'papa/command/larga/type'
2
+ require 'papa/command/larga/deploy'
3
+ require 'papa/runner'
4
+
5
+ module Papa
6
+ module Task
7
+ class Deploy
8
+ def initialize(options = {})
9
+ @options = options
10
+ end
11
+
12
+ def run
13
+ queue = [
14
+ Command::Larga::Type.new,
15
+ Command::Larga::Deploy.new(@options)
16
+ ]
17
+ runner = Runner.new(queue)
18
+
19
+ if runner.run
20
+ success_message
21
+ else
22
+ failure_message
23
+ exit 1
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def success_message
30
+ Helper::Output.success 'Successfully deployed larga instance.'
31
+ end
32
+
33
+ def failure_message
34
+ Helper::Output.failure 'There was a problem deploying larga instance.'
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,15 @@
1
+ require 'papa/task/common/add'
2
+
3
+ module Papa
4
+ module Task
5
+ module Hotfix
6
+ class Add < Common::Add
7
+ def initialize(version:, bugfix_branches:)
8
+ @build_type = 'hotfix'
9
+ @version = version
10
+ @branches = bugfix_branches
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ require 'papa/task/common/finish'
2
+
3
+ module Papa
4
+ module Task
5
+ module Hotfix
6
+ class Finish < Common::Finish
7
+ def initialize(version:, additional_branches:)
8
+ @build_type = 'hotfix'
9
+ @version = version
10
+ additional_branches ||= []
11
+ @tag_name = version
12
+ @base_branches = ['develop', 'master'] + additional_branches
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ require 'papa/task/common/start'
2
+
3
+ module Papa
4
+ module Task
5
+ module Hotfix
6
+ class Start < Common::Start
7
+ def initialize(version:)
8
+ @build_type = 'hotfix'
9
+ @base_branch = 'master'
10
+ @version = version
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,22 @@
1
+ require 'papa/task/common/start'
2
+ require 'date'
3
+
4
+ module Papa
5
+ module Task
6
+ module Integration
7
+ class Start < Common::Start
8
+ def initialize(base_branch:)
9
+ @build_type = 'integration'
10
+ @base_branch = base_branch
11
+ @build_branch = generate_integration_branch_name
12
+ end
13
+
14
+ private
15
+
16
+ def generate_integration_branch_name
17
+ "integration/#{DateTime.now.strftime('%y.%m.%d.%H.%M').gsub('.0', '.')}"
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,15 @@
1
+ require 'papa/task/common/add'
2
+
3
+ module Papa
4
+ module Task
5
+ module Release
6
+ class Add < Common::Add
7
+ def initialize(version:, feature_branches:)
8
+ @build_type = "release"
9
+ @version = version
10
+ @branches = feature_branches
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ require 'papa/task/common/finish'
2
+
3
+ module Papa
4
+ module Task
5
+ module Release
6
+ class Finish < Common::Finish
7
+ def initialize(version:)
8
+ @build_type = 'release'
9
+ @version = version
10
+ @tag_name = version
11
+ @base_branches = ['develop', 'master']
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ require 'papa/task/common/start'
2
+
3
+ module Papa
4
+ module Task
5
+ module Release
6
+ class Start < Common::Start
7
+ def initialize(version:)
8
+ @build_type = 'release'
9
+ @base_branch = 'develop'
10
+ @version = version
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,23 @@
1
+ require 'papa/helper/path'
2
+ require 'papa/command/base'
3
+
4
+ module Papa
5
+ module Task
6
+ module Sandbox
7
+ class Clean
8
+ attr_accessor :options
9
+
10
+ def initialize(options = {})
11
+ @options = options
12
+ end
13
+
14
+ def run
15
+ Helper::Output.stdout('Started cleaning sandbox directories...') unless options[:silent]
16
+ path = File.join(Helper::Path::TMP_PATH, Helper::Path::SANDBOX_PREFIX)
17
+ Command::Base.new("rm -rf #{path}*").run
18
+ Helper::Output.success('Successfully removed sandbox directories.')
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end