papa 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +5 -0
  5. data/CHANGELOG.md +0 -0
  6. data/Gemfile +6 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +39 -0
  9. data/Rakefile +6 -0
  10. data/exe/papa +6 -0
  11. data/lib/papa.rb +11 -0
  12. data/lib/papa/cli.rb +17 -0
  13. data/lib/papa/command.rb +42 -0
  14. data/lib/papa/command_queue.rb +34 -0
  15. data/lib/papa/common.rb +4 -0
  16. data/lib/papa/common/add.rb +62 -0
  17. data/lib/papa/common/finish.rb +56 -0
  18. data/lib/papa/common/start.rb +30 -0
  19. data/lib/papa/git.rb +62 -0
  20. data/lib/papa/git/checkout.rb +14 -0
  21. data/lib/papa/git/merge.rb +27 -0
  22. data/lib/papa/git/rebase.rb +27 -0
  23. data/lib/papa/hotfix.rb +37 -0
  24. data/lib/papa/hotfix/add.rb +9 -0
  25. data/lib/papa/hotfix/finish.rb +11 -0
  26. data/lib/papa/hotfix/start.rb +9 -0
  27. data/lib/papa/output.rb +13 -0
  28. data/lib/papa/release.rb +47 -0
  29. data/lib/papa/release/add.rb +9 -0
  30. data/lib/papa/release/finish.rb +10 -0
  31. data/lib/papa/release/patch.rb +30 -0
  32. data/lib/papa/release/start.rb +9 -0
  33. data/lib/papa/sandbox.rb +12 -0
  34. data/lib/papa/sandbox/branches/bugfix/4-fix-charmeleon-spelling/Gemfile +24 -0
  35. data/lib/papa/sandbox/branches/bugfix/5-fix-gem-source/Gemfile +24 -0
  36. data/lib/papa/sandbox/branches/feature/1-add-butterfree-gem/Gemfile +25 -0
  37. data/lib/papa/sandbox/branches/feature/2-add-beedrill-gem/Gemfile +25 -0
  38. data/lib/papa/sandbox/branches/feature/6-add-pidgeotto-gem/Gemfile +26 -0
  39. data/lib/papa/sandbox/branches/feature/7-add-pidgeot-gem/Gemfile +26 -0
  40. data/lib/papa/sandbox/branches/master/Gemfile +24 -0
  41. data/lib/papa/sandbox/branches/patch/17.8.0/3-add-pidgey-gem/Gemfile +26 -0
  42. data/lib/papa/sandbox/generate.rb +177 -0
  43. data/lib/papa/thor.rb +5 -0
  44. data/lib/papa/version.rb +3 -0
  45. data/papa.gemspec +31 -0
  46. metadata +145 -0
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+ source "https://pokemon.org"
3
+
4
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
5
+
6
+ gem "bulbasaur"
7
+ gem "ivysaur"
8
+ gem "venusaur"
9
+ gem "charmander"
10
+ gem "charmelon"
11
+ gem "charizard"
12
+ gem "squirtle"
13
+ gem "wartortle"
14
+ gem "blastoise"
15
+
16
+ group :development, :test do
17
+ gem "caterpie"
18
+ gem "metapod"
19
+ end
20
+
21
+ group :test do
22
+ gem "weedle"
23
+ gem "kakuna"
24
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+ source "https://pokemon.org"
3
+
4
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
5
+
6
+ gem "bulbasaur"
7
+ gem "ivysaur"
8
+ gem "venusaur"
9
+ gem "charmander"
10
+ gem "charmelon"
11
+ gem "charizard"
12
+ gem "squirtle"
13
+ gem "wartortle"
14
+ gem "blastoise"
15
+
16
+ group :development, :test do
17
+ gem "caterpie"
18
+ gem "metapod"
19
+ end
20
+
21
+ group :test do
22
+ gem "weedle"
23
+ gem "kakuna"
24
+ end
25
+
26
+ gem "pidgey"
@@ -0,0 +1,177 @@
1
+ module Papa
2
+ class Sandbox::Generate
3
+ attr_accessor :remote_repository_directory, :local_repository_directory, :git_details
4
+
5
+ def initialize(options = {})
6
+ @options = options
7
+ @remote_repository_directory = '/tmp/papa_sandbox_remote_repository'
8
+ @local_repository_directory = '/tmp/papa_sandbox_local_repository'
9
+ @git_details = [
10
+ {
11
+ commit: 'APP-1 - Add butterfree gem',
12
+ branch: 'feature/1-add-butterfree-gem',
13
+ base_branch: 'develop'
14
+ },
15
+ {
16
+ commit: 'APP-2 - Add beedrill gem',
17
+ branch: 'feature/2-add-beedrill-gem',
18
+ base_branch: 'develop'
19
+ },
20
+ {
21
+ commit: 'APP-3 - Add pidgey gem',
22
+ branch: 'patch/17.8.0/3-add-pidgey-gem',
23
+ base_branch: 'develop'
24
+ },
25
+ {
26
+ commit: 'APP-4 - Fix charmeleon spelling',
27
+ branch: 'bugfix/4-fix-charmeleon-spelling',
28
+ base_branch: 'master'
29
+ },
30
+ {
31
+ commit: 'APP-5 - Fix gem source',
32
+ branch: 'bugfix/5-fix-gem-source',
33
+ base_branch: 'master'
34
+ },
35
+ {
36
+ commit: 'APP-6 - Add pidgeotto gem',
37
+ branch: 'feature/6-add-pidgeotto-gem',
38
+ base_branch: 'develop'
39
+ },
40
+ {
41
+ commit: 'APP-7 - Add pidgeot gem',
42
+ branch: 'feature/7-add-pidgeot-gem',
43
+ base_branch: 'develop'
44
+ }
45
+ ]
46
+ end
47
+
48
+ def run(options = {})
49
+ Output.stdout('Generating sandbox...') unless options[:silent]
50
+ @project_directory = File.expand_path(File.dirname(__dir__))
51
+ @branches_directory = File.join @project_directory, 'sandbox', 'branches'
52
+ setup_remote_repository
53
+ setup_local_repository
54
+ success_message unless options[:silent]
55
+ end
56
+
57
+ private
58
+
59
+ def gemfile_path(branch)
60
+ File.join @branches_directory, branch, 'Gemfile'
61
+ end
62
+
63
+ def temp_gemfile_path
64
+ File.join @local_repository_directory, 'Gemfile'
65
+ end
66
+
67
+ def setup_remote_repository
68
+ if @options[:override_origin]
69
+ create_local_repository_directory
70
+ initialize_local_repository
71
+ remove_old_branches_from_origin
72
+ else
73
+ create_remote_repository_directory
74
+ initialize_remote_repository
75
+ create_local_repository_directory
76
+ clone_remote_repository
77
+ end
78
+ end
79
+
80
+ def create_local_repository_directory
81
+ Command.new("rm -rf #{@local_repository_directory}").run
82
+ Dir.mkdir @local_repository_directory
83
+ end
84
+
85
+ def initialize_local_repository
86
+ Dir.chdir @local_repository_directory
87
+ Command.new('git init').run
88
+ Command.new("git remote add origin #{@options[:override_origin]}").run
89
+ end
90
+
91
+ def create_remote_repository_directory
92
+ Command.new("rm -rf #{@remote_repository_directory}").run
93
+ Dir.mkdir @remote_repository_directory
94
+ end
95
+
96
+ def initialize_remote_repository
97
+ Dir.chdir @remote_repository_directory
98
+ Command.new('git init --bare').run
99
+ end
100
+
101
+ def clone_remote_repository
102
+ Command.new("git clone #{@remote_repository_directory} #{@local_repository_directory}").run
103
+ Dir.chdir @local_repository_directory
104
+ end
105
+
106
+ def setup_local_repository
107
+ initialize_master_and_develop
108
+ initialize_branches
109
+ cleanup
110
+ end
111
+
112
+ def remove_old_branches_from_origin
113
+ `git fetch #{Output::REDIRECT_TO_NULL}`
114
+ ['hotfix', 'release'].each do |branch|
115
+ `git branch -r | grep #{branch}`.split("\n").each do |branch|
116
+ branch = branch.strip.split('origin/').last
117
+ `git push -d origin #{branch}`
118
+ end
119
+ end
120
+ end
121
+
122
+ def initialize_master_and_develop
123
+ [
124
+ "cp #{gemfile_path('master')} #{@local_repository_directory}",
125
+ 'git add .',
126
+ 'git commit -m "Initial commit"',
127
+ 'git push origin master --force',
128
+ 'git checkout -b develop',
129
+ 'git push origin develop --force'
130
+ ].each do |command|
131
+ `#{command} #{Output::REDIRECT_TO_NULL}`
132
+ end
133
+ end
134
+
135
+ def initialize_branches
136
+ @git_details.each do |detail|
137
+ commit = detail[:commit]
138
+ branch = detail[:branch]
139
+ base_branch = detail[:base_branch]
140
+ [
141
+ "git checkout #{base_branch}",
142
+ "git checkout -b #{branch}",
143
+ "rm #{temp_gemfile_path}",
144
+ "cp #{gemfile_path(branch)} #{@local_repository_directory}",
145
+ "git add .",
146
+ "git commit -m \"#{commit}\"",
147
+ "git push origin #{branch} --force"
148
+ ].each do |command|
149
+ `#{command} #{Output::REDIRECT_TO_NULL}`
150
+ end
151
+ end
152
+ end
153
+
154
+ def cleanup
155
+ `git checkout develop #{Output::REDIRECT_TO_NULL}`
156
+ @git_details.each do |detail|
157
+ `git branch -D #{detail[:branch]} #{Output::REDIRECT_TO_NULL}`
158
+ end
159
+ end
160
+
161
+ def success_message
162
+ Output.stdout <<-STDOUT
163
+ Your sandbox is now available at:
164
+ #{@local_repository_directory}
165
+ STDOUT
166
+ end
167
+
168
+ def override_origin(origin)
169
+ [
170
+ 'git remote remove origin',
171
+ 'git remote add origin #{origin}'
172
+ ].each do |command|
173
+ `#{command} #{Output::REDIRECT_TO_NULL}`
174
+ end
175
+ end
176
+ end
177
+ end
data/lib/papa/thor.rb ADDED
@@ -0,0 +1,5 @@
1
+ class Thor
2
+ def self.exit_on_failure?
3
+ true
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module Papa
2
+ VERSION = "0.1.0"
3
+ end
data/papa.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "papa/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "papa"
8
+ spec.version = Papa::VERSION
9
+ spec.authors = ["boggs"]
10
+ spec.email = ["hello@boggs.xyz"]
11
+
12
+ spec.summary = "Helper gem for inDinero's git workflow"
13
+ spec.description = "Helper gem for inDinero's git workflow"
14
+ spec.homepage = "https://github.com/b-ggs/papa"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.required_ruby_version = ">= 2.1.5"
25
+
26
+ spec.add_dependency "thor", "~> 0.20.0"
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.15"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "rspec", "~> 3.0"
31
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: papa
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - boggs
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-09-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.20.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.20.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.15'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.15'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: Helper gem for inDinero's git workflow
70
+ email:
71
+ - hello@boggs.xyz
72
+ executables:
73
+ - papa
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - CHANGELOG.md
81
+ - Gemfile
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - exe/papa
86
+ - lib/papa.rb
87
+ - lib/papa/cli.rb
88
+ - lib/papa/command.rb
89
+ - lib/papa/command_queue.rb
90
+ - lib/papa/common.rb
91
+ - lib/papa/common/add.rb
92
+ - lib/papa/common/finish.rb
93
+ - lib/papa/common/start.rb
94
+ - lib/papa/git.rb
95
+ - lib/papa/git/checkout.rb
96
+ - lib/papa/git/merge.rb
97
+ - lib/papa/git/rebase.rb
98
+ - lib/papa/hotfix.rb
99
+ - lib/papa/hotfix/add.rb
100
+ - lib/papa/hotfix/finish.rb
101
+ - lib/papa/hotfix/start.rb
102
+ - lib/papa/output.rb
103
+ - lib/papa/release.rb
104
+ - lib/papa/release/add.rb
105
+ - lib/papa/release/finish.rb
106
+ - lib/papa/release/patch.rb
107
+ - lib/papa/release/start.rb
108
+ - lib/papa/sandbox.rb
109
+ - lib/papa/sandbox/branches/bugfix/4-fix-charmeleon-spelling/Gemfile
110
+ - lib/papa/sandbox/branches/bugfix/5-fix-gem-source/Gemfile
111
+ - lib/papa/sandbox/branches/feature/1-add-butterfree-gem/Gemfile
112
+ - lib/papa/sandbox/branches/feature/2-add-beedrill-gem/Gemfile
113
+ - lib/papa/sandbox/branches/feature/6-add-pidgeotto-gem/Gemfile
114
+ - lib/papa/sandbox/branches/feature/7-add-pidgeot-gem/Gemfile
115
+ - lib/papa/sandbox/branches/master/Gemfile
116
+ - lib/papa/sandbox/branches/patch/17.8.0/3-add-pidgey-gem/Gemfile
117
+ - lib/papa/sandbox/generate.rb
118
+ - lib/papa/thor.rb
119
+ - lib/papa/version.rb
120
+ - papa.gemspec
121
+ homepage: https://github.com/b-ggs/papa
122
+ licenses:
123
+ - MIT
124
+ metadata: {}
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: 2.1.5
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 2.6.10
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: Helper gem for inDinero's git workflow
145
+ test_files: []