papa 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,29 +0,0 @@
1
- module Papa
2
- class Git::Merge < Command
3
- def initialize(branch_name)
4
- @branch_name = branch_name
5
- command = "git merge #{@branch_name} --no-ff"
6
- super(command)
7
- end
8
-
9
- def run
10
- current_branch # Store current branch before executing command
11
- super
12
- end
13
-
14
- def cleanup
15
- super
16
- queue = CommandQueue.new
17
- queue.add Git.merge_abort
18
- queue.add Git.checkout(branch_name: current_branch)
19
- queue.run
20
- end
21
-
22
- def failure_message
23
- super
24
- message = "Failed to merge #{@branch_name} into #{current_branch}. Merge conflict?"
25
- Output.error message
26
- message
27
- end
28
- end
29
- end
@@ -1,29 +0,0 @@
1
- module Papa
2
- class Git::Rebase < Command
3
- def initialize(base_branch_name)
4
- @base_branch_name = base_branch_name
5
- command = "git rebase #{@base_branch_name}"
6
- super(command)
7
- end
8
-
9
- def run
10
- current_branch # Store current branch before executing command
11
- super
12
- end
13
-
14
- def cleanup
15
- super
16
- queue = CommandQueue.new
17
- queue.add Git.rebase_abort
18
- queue.add Git.checkout(branch_name: current_branch)
19
- queue.run
20
- end
21
-
22
- def failure_message
23
- super
24
- message = "Failed to rebase #{current_branch} from #{@base_branch_name}. Merge conflict?"
25
- Output.error message
26
- message
27
- end
28
- end
29
- end
data/lib/papa/git.rb DELETED
@@ -1,71 +0,0 @@
1
- module Papa
2
- class Git
3
- def self.status
4
- Command.new 'git status'
5
- end
6
-
7
- def self.fetch(remote:)
8
- require 'papa/git/fetch'
9
-
10
- Git::Fetch.new(remote)
11
- end
12
-
13
- def self.checkout(branch_name:)
14
- require 'papa/git/checkout'
15
-
16
- Git::Checkout.new(branch_name)
17
- end
18
-
19
- def self.branch(branch_name:)
20
- Command.new "git branch #{branch_name}"
21
- end
22
-
23
- def self.delete_branch(branch_name:)
24
- Command.new "git branch -D #{branch_name}"
25
- end
26
-
27
- def self.merge(branch_name:)
28
- require 'papa/git/merge'
29
-
30
- Git::Merge.new(branch_name)
31
- end
32
-
33
- def self.merge_abort
34
- Command.new 'git merge --abort'
35
- end
36
-
37
- def self.pull(remote:, branch_name:)
38
- Command.new "git pull #{remote} #{branch_name}"
39
- end
40
-
41
- def self.push(remote:, branch_name:)
42
- Command.new "git push #{remote} #{branch_name}"
43
- end
44
-
45
- def self.force_push(remote:, branch_name:)
46
- Command.new "git push #{remote} #{branch_name} --force-with-lease"
47
- end
48
-
49
- def self.rebase(base_branch_name:)
50
- require 'papa/git/rebase'
51
-
52
- Git::Rebase.new(base_branch_name)
53
- end
54
-
55
- def self.rebase_abort
56
- Command.new 'git rebase --abort'
57
- end
58
-
59
- def self.tag(tag_name:)
60
- Command.new "git tag #{tag_name}"
61
- end
62
-
63
- def self.push_tag(remote:, tag_name:)
64
- push(remote: remote, branch_name: tag_name)
65
- end
66
-
67
- def self.hard_reset(remote:, branch_name:)
68
- Command.new "git reset --hard #{remote}/#{branch_name}"
69
- end
70
- end
71
- end
@@ -1,27 +0,0 @@
1
- require 'securerandom'
2
-
3
- module Papa
4
- class Helpers::Path
5
- TMP_PATH = '/tmp/'
6
- VI_PREFIX = 'papa-vi-'
7
- SANDBOX_PREFIX = 'papa-sandbox-'
8
-
9
- def self.generate_vi_file_path
10
- File.join(TMP_PATH, VI_PREFIX + uuid_gen + '.txt')
11
- end
12
-
13
- def self.generate_sandbox_path(type, options = {})
14
- path =
15
- if options.has_key?('override_path_prefix')
16
- options[:override_path_prefix] + '-' + type
17
- else
18
- SANDBOX_PREFIX + type + '-' + uuid_gen
19
- end
20
- File.join(TMP_PATH, path)
21
- end
22
-
23
- def self.uuid_gen
24
- SecureRandom.uuid
25
- end
26
- end
27
- end
@@ -1,60 +0,0 @@
1
- require 'papa/helpers/path'
2
-
3
- module Papa
4
- class Helpers::Vi
5
- attr_accessor :path, :branches
6
-
7
- def initialize
8
- @path = Helpers::Path.generate_vi_file_path
9
- @branches = []
10
- end
11
-
12
- def run
13
- initialize_file
14
- prompt_vi
15
- read_from_file
16
- delete_file
17
- validate_branches
18
- branches
19
- end
20
-
21
- private
22
-
23
- def initialize_file
24
- content = <<-CONTENT
25
- # Add your branches here. One branch name per line.
26
- # Lines starting in pound (#) will be ignored
27
- # Sample:
28
- # feature/1-add-butterfree-gem
29
- # feature/2-add-beedrill-gem
30
- CONTENT
31
- File.open(path, 'w') { |file| file.write(content) }
32
- end
33
-
34
- def prompt_vi
35
- system('vi', path)
36
- end
37
-
38
- def read_from_file
39
- @branches = File.read(path).chomp.split("\n").map do |branch|
40
- branch.strip!
41
- if branch.empty? || branch[0] == '#'
42
- nil
43
- else
44
- branch
45
- end
46
- end.compact
47
- end
48
-
49
- def delete_file
50
- Command.new("rm #{path}", silent: true).run
51
- end
52
-
53
- def validate_branches
54
- if @branches.empty?
55
- Output.failure 'No branches specified.'
56
- exit 1
57
- end
58
- end
59
- end
60
- end
data/lib/papa/helpers.rb DELETED
@@ -1,4 +0,0 @@
1
- module Papa
2
- class Helpers
3
- end
4
- end
@@ -1,9 +0,0 @@
1
- module Papa
2
- class Hotfix::Add < Common::Add
3
- def initialize(version:, bugfix_branches:)
4
- @build_type = 'hotfix'
5
- @version = version
6
- @branches = bugfix_branches
7
- end
8
- end
9
- end
@@ -1,11 +0,0 @@
1
- module Papa
2
- class Hotfix::Finish < Common::Finish
3
- def initialize(version:, additional_branches:)
4
- @build_type = 'hotfix'
5
- @version = version
6
- additional_branches ||= []
7
- @tag_name = version
8
- @base_branches = ['develop', 'master'] + additional_branches
9
- end
10
- end
11
- end
@@ -1,9 +0,0 @@
1
- module Papa
2
- class Hotfix::Start < Common::Start
3
- def initialize(version:)
4
- @build_type = 'hotfix'
5
- @base_branch = 'master'
6
- @version = version
7
- end
8
- end
9
- end
@@ -1,17 +0,0 @@
1
- require 'date'
2
-
3
- module Papa
4
- class Integration::Start < Common::Start
5
- def initialize(base_branch:)
6
- @build_type = 'integration'
7
- @base_branch = base_branch
8
- @build_branch = generate_integration_branch_name
9
- end
10
-
11
- private
12
-
13
- def generate_integration_branch_name
14
- "integration/#{DateTime.now.strftime('%y.%m.%d.%H.%M').gsub('.0', '.')}"
15
- end
16
- end
17
- end
@@ -1,36 +0,0 @@
1
- module Papa
2
- class Larga::Deploy < Command
3
- def initialize(branch, lifespan, protection, hostname)
4
- @branch = branch
5
- @lifespan = lifespan
6
- @protection = protection
7
- @hostname = hostname
8
-
9
- command = "larga #{build_options.join(' ')}"
10
- super(command, silent: false)
11
- end
12
-
13
- def failed?
14
- @output.include? 'Cowardly refusing'
15
- end
16
-
17
- def failure_message
18
- super
19
- Output.stderr 'ERROR: Ensure that the branch exists before trying again'
20
- end
21
-
22
- private
23
-
24
- def build_options()
25
- options = []
26
- options << '-action deploy'
27
- options << "-branch #{@branch}"
28
- options << "-lifespan #{@lifespan}"
29
- options << "-protection #{@protection}"
30
- if @hostname
31
- options << "-hostname #{@hostname}"
32
- end
33
- options
34
- end
35
- end
36
- end
@@ -1,12 +0,0 @@
1
- module Papa
2
- class Larga::Type < Command
3
- def initialize
4
- super('type larga')
5
- end
6
-
7
- def failure_message
8
- super
9
- Output.stderr 'Larga is not installed in this system'
10
- end
11
- end
12
- end
data/lib/papa/larga.rb DELETED
@@ -1,18 +0,0 @@
1
- module Papa
2
- class Larga
3
- RELEASE_OR_HOTFIX_LIFESPAN = '3d'
4
- DEFAULT_LIFESPAN = '4h'
5
- RELEASE_OR_HOTFIX_PROTECTION = 'off'
6
- DEFAULT_PROTECTION = 'on'
7
-
8
- def self.type
9
- Larga::Type.new
10
- end
11
-
12
- def self.deploy(branch:, lifespan: DEFAULT_LIFESPAN, protection: DEFAULT_PROTECTION, hostname: nil)
13
- require 'papa/larga/deploy'
14
-
15
- Larga::Deploy.new(branch, lifespan, protection, hostname)
16
- end
17
- end
18
- end
data/lib/papa/output.rb DELETED
@@ -1,43 +0,0 @@
1
- require 'date'
2
-
3
- module Papa
4
- class Output
5
- REDIRECT_TO_NULL = '> /dev/null 2>&1'
6
-
7
- def self.stdout(message, options = {})
8
- puts build_output(message)
9
- end
10
-
11
- def self.stderr(message, options = {})
12
- STDERR.puts build_output(message)
13
- end
14
-
15
- def self.error(message)
16
- stderr("ERROR: #{message}")
17
- end
18
-
19
- def self.success(message)
20
- puts
21
- puts message.strip.green
22
- end
23
-
24
- def self.failure(message)
25
- STDERR.puts
26
- STDERR.puts message.strip.red
27
- end
28
-
29
- def self.failure_reason(messages)
30
- messages.each do |message|
31
- STDERR.puts " #{message}"
32
- end
33
- end
34
-
35
- def self.build_output(message)
36
- "[#{timestamp}] - #{message}"
37
- end
38
-
39
- def self.timestamp
40
- DateTime.now.strftime('%H:%M:%S')
41
- end
42
- end
43
- end
@@ -1,9 +0,0 @@
1
- module Papa
2
- class Release::Add < Common::Add
3
- def initialize(version:, feature_branches:)
4
- @build_type = "release"
5
- @version = version
6
- @branches = feature_branches
7
- end
8
- end
9
- end
@@ -1,10 +0,0 @@
1
- module Papa
2
- class Release::Finish < Common::Finish
3
- def initialize(version:)
4
- @build_type = 'release'
5
- @version = version
6
- @tag_name = version
7
- @base_branches = ['develop', 'master']
8
- end
9
- end
10
- end
@@ -1,30 +0,0 @@
1
- module Papa
2
- class Release::Patch < Common::Add
3
- def initialize(version:, patch_branch:)
4
- @build_type = 'release'
5
- @version = version
6
- @branches = [patch_branch]
7
- end
8
-
9
- # def run
10
- # @build_branch = "#{@build_type}/#{@version}"
11
- #
12
- # queue = CommandQueue.new
13
- # queue.add Git.fetch(remote: 'origin')
14
- # queue.add Git.checkout(branch_name: @build_branch)
15
- # queue.add Git.checkout(branch_name: @patch_branch)
16
- # queue.add Git.rebase(base_branch_name: @build_branch)
17
- # queue.add Git.checkout(branch_name: @build_branch)
18
- # queue.add Git.merge(branch_name: @patch_branch)
19
- # queue.run
20
- #
21
- # cleanup
22
- # end
23
-
24
- # def cleanup
25
- # queue = CommandQueue.new
26
- # @branches.each { |branch| queue.add Git.delete_branch(branch_name: branch) }
27
- # queue.run
28
- # end
29
- end
30
- end
@@ -1,9 +0,0 @@
1
- module Papa
2
- class Release::Start < Common::Start
3
- def initialize(version:)
4
- @build_type = 'release'
5
- @base_branch = 'develop'
6
- @version = version
7
- end
8
- end
9
- end
@@ -1,17 +0,0 @@
1
- require 'papa/helpers/path'
2
-
3
- module Papa
4
- class Sandbox::Clean
5
- attr_accessor :options
6
-
7
- def initialize(options = {})
8
- @options = options
9
- end
10
-
11
- def run
12
- Output.stdout('Started cleaning sandbox directories...') unless options[:silent]
13
- Command.new("rm -rf #{Helpers::Path::SANDBOX_PREFIX}*").run
14
- Output.success('Successfully removed sandbox directories.')
15
- end
16
- end
17
- end
@@ -1,176 +0,0 @@
1
- require 'papa/helpers/path'
2
-
3
- module Papa
4
- class Sandbox::Generate
5
- attr_accessor :remote_path, :local_path, :git_details, :options
6
-
7
- def initialize(options = {})
8
- @options = options
9
- @remote_path = Helpers::Path.generate_sandbox_path('remote', options)
10
- @local_path = Helpers::Path.generate_sandbox_path('local', options)
11
- @git_details = [
12
- {
13
- commit: 'APP-1 - Add butterfree gem',
14
- branch: 'feature/1-add-butterfree-gem',
15
- base_branch: 'develop'
16
- },
17
- {
18
- commit: 'APP-2 - Add beedrill gem',
19
- branch: 'feature/2-add-beedrill-gem',
20
- base_branch: 'develop'
21
- },
22
- {
23
- commit: 'APP-3 - Add pidgey gem',
24
- branch: 'patch/17.8.0/3-add-pidgey-gem',
25
- base_branch: 'develop'
26
- },
27
- {
28
- commit: 'APP-4 - Fix charmeleon spelling',
29
- branch: 'bugfix/4-fix-charmeleon-spelling',
30
- base_branch: 'master'
31
- },
32
- {
33
- commit: 'APP-5 - Fix gem source',
34
- branch: 'bugfix/5-fix-gem-source',
35
- base_branch: 'master'
36
- },
37
- {
38
- commit: 'APP-6 - Add pidgeotto gem',
39
- branch: 'feature/6-add-pidgeotto-gem',
40
- base_branch: 'develop'
41
- },
42
- {
43
- commit: 'APP-7 - Add pidgeot gem',
44
- branch: 'feature/7-add-pidgeot-gem',
45
- base_branch: 'develop'
46
- }
47
- ]
48
- end
49
-
50
- def run
51
- Output.stdout('Started generation of sandbox...') unless options[:silent]
52
- @project_directory = File.expand_path(File.dirname(__dir__))
53
- @branches_directory = File.join @project_directory, 'sandbox', 'branches'
54
- setup_remote_repository
55
- setup_local_repository
56
- success_message unless options[:silent]
57
- end
58
-
59
- private
60
-
61
- def gemfile_path(branch)
62
- File.join @branches_directory, branch, 'Gemfile'
63
- end
64
-
65
- def temp_gemfile_path
66
- File.join @local_path, 'Gemfile'
67
- end
68
-
69
- def setup_remote_repository
70
- if options[:override_origin]
71
- create_local_path
72
- initialize_local_repository
73
- remove_old_branches_from_origin
74
- else
75
- create_remote_path
76
- initialize_remote_repository
77
- create_local_path
78
- clone_remote_repository
79
- end
80
- end
81
-
82
- def create_local_path
83
- Command.new("rm -rf #{@local_path}", options).run
84
- Dir.mkdir @local_path
85
- end
86
-
87
- def initialize_local_repository
88
- Dir.chdir @local_path
89
- Command.new('git init', options).run
90
- Command.new("git remote add origin #{options[:override_origin]}", options).run
91
- end
92
-
93
- def create_remote_path
94
- Command.new("rm -rf #{@remote_path}", options).run
95
- Dir.mkdir @remote_path
96
- end
97
-
98
- def initialize_remote_repository
99
- Dir.chdir @remote_path
100
- Command.new('git init --bare', options).run
101
- end
102
-
103
- def clone_remote_repository
104
- Command.new("git clone #{@remote_path} #{@local_path}", options).run
105
- Dir.chdir @local_path
106
- end
107
-
108
- def setup_local_repository
109
- initialize_master_and_develop
110
- initialize_branches
111
- cleanup
112
- end
113
-
114
- def remove_old_branches_from_origin
115
- `git fetch #{Output::REDIRECT_TO_NULL}`
116
- ['hotfix', 'release'].each do |branch|
117
- `git branch -r | grep #{branch}`.split("\n").each do |branch|
118
- branch = branch.strip.split('origin/').last
119
- `git push -d origin #{branch}`
120
- end
121
- end
122
- end
123
-
124
- def initialize_master_and_develop
125
- [
126
- "cp #{gemfile_path('master')} #{@local_path}",
127
- 'git add .',
128
- 'git commit -m "Initial commit"',
129
- 'git push origin master --force',
130
- 'git checkout -b develop',
131
- 'git push origin develop --force'
132
- ].each do |command|
133
- `#{command} #{Output::REDIRECT_TO_NULL}`
134
- end
135
- end
136
-
137
- def initialize_branches
138
- @git_details.each do |detail|
139
- commit = detail[:commit]
140
- branch = detail[:branch]
141
- base_branch = detail[:base_branch]
142
- [
143
- "git checkout #{base_branch}",
144
- "git checkout -b #{branch}",
145
- "rm #{temp_gemfile_path}",
146
- "cp #{gemfile_path(branch)} #{@local_path}",
147
- "git add .",
148
- "git commit -m \"#{commit}\"",
149
- "git push origin #{branch} --force"
150
- ].each do |command|
151
- `#{command} #{Output::REDIRECT_TO_NULL}`
152
- end
153
- end
154
- end
155
-
156
- def cleanup
157
- `git checkout develop #{Output::REDIRECT_TO_NULL}`
158
- @git_details.each do |detail|
159
- `git branch -D #{detail[:branch]} #{Output::REDIRECT_TO_NULL}`
160
- end
161
- end
162
-
163
- def success_message
164
- Output.success "Your sandbox is now available at:\n #{@local_path}"
165
- end
166
-
167
- def override_origin(origin)
168
- [
169
- 'git remote remove origin',
170
- 'git remote add origin #{origin}'
171
- ].each do |command|
172
- `#{command} #{Output::REDIRECT_TO_NULL}`
173
- end
174
- end
175
- end
176
- end