papa 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 71de33eed576744cad1400a5d795616b436d8146
4
- data.tar.gz: e2a1e530d112d5c819d487c1804e31d119d76cdb
3
+ metadata.gz: 4e79d7aa5abd7759a7acee2ac1538c6f4b3bc69e
4
+ data.tar.gz: 7eb13ccb695d9c423d1b3f60dd552184ef86c705
5
5
  SHA512:
6
- metadata.gz: 1e686d587e3b4d15b6a72da07663e270b97eef6f7bfa5e1c190a4ad234af3a558605005ad9805cb4ad849647f45070de2792fa692ac5cbb35950f56b804e9a76
7
- data.tar.gz: f9f40abba6bddd80576d0d8a76b704262415430b712c42a34c207a45fe826d46f8337f7758d3698bec5bcc194eb441fa192047d29fbc1b4e91a7f1a5fb8436c7
6
+ metadata.gz: 807475a93bd68e8e520a7f069d38e1dee3c8e6491f81c21835140fa50af63e7f174994b69b5b2b2e82d6aeb7a5aa226063508ebbfe3f09fcc2911c0868879520
7
+ data.tar.gz: fd5289d8f9149e28666954a68def6ac64c9f1af26f5dfcdb3d1719a81244be2c2007e6720a5e046f18d3437e867ead2c6be84cea66d4079f570b1da898d474fc
@@ -1,11 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.0
4
+ * Used open3 for easier output and exit status handling
5
+ * Added more descriptive output messages
6
+ * Prompt vi when no branches are specified in add
7
+ * Improved sandbox path generation
8
+ * Added `papa sandbox clean` to remove old generated sandbox directories
9
+
3
10
  ## 0.2.0
4
- * Added `integration [start]`
5
- * Added `deploy` via larga
11
+ * Added `papa integration [start]`
12
+ * Added `papa deploy` via larga
6
13
  * Hard reset local feature and bugfix branches to remote versions before adding
7
14
 
8
15
  ## 0.1.0
9
16
  * Initial release
10
- * Added `release [start, add, finish]`, `hotfix [start, add, finish]` and `sandbox [generate]` commands
17
+ * Added `papa release [start, add, finish]`, `papa hotfix [start, add, finish]` and `papa sandbox [generate]` commands
11
18
  * Added simple error handling for some git commands for when they fail
data/README.md CHANGED
@@ -1,39 +1,161 @@
1
- # Papa
1
+ # Papa [![Gem Version](https://badge.fury.io/rb/papa.svg)](https://badge.fury.io/rb/papa) [![Build Status](https://travis-ci.org/b-ggs/papa.svg?branch=master)](https://travis-ci.org/b-ggs/papa) [![Maintainability](https://api.codeclimate.com/v1/badges/cec506e3421dc3e08eeb/maintainability)](https://codeclimate.com/github/b-ggs/papa/maintainability)
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/papa`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Helper tool for inDinero's git workflow. Ako ang papa mo.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ ## Contents
6
6
 
7
- ## Installation
7
+ * [Getting Started](#getting-started)
8
+ * [Commands](#commands)
9
+ * [papa release](#papa-release)
10
+ * [papa hotfix](#papa-hotfix)
11
+ * [papa integration](#papa-integration)
12
+ * [papa deploy](#papa-deploy)
13
+ * [papa sandbox](#papa-sandbox)
8
14
 
9
- Add this line to your application's Gemfile:
15
+ ## Getting Started
10
16
 
11
- ```ruby
12
- gem 'papa'
17
+ Install `papa` from Rubygems.
18
+
19
+ ```
20
+ $ gem install papa
21
+ ```
22
+
23
+ That's it, you're ready to go!
24
+
25
+ ## Commands
26
+
27
+ ### `papa release`
28
+
29
+ #### Starting a release branch
30
+
31
+ This will create a new release branch based on the current `develop` branch. The release branch will be pushed to origin.
32
+
33
+ ```
34
+ $ papa release start -v, --version=VERSION
35
+ ```
36
+
37
+ ###### Sample Usage:
38
+
39
+ ```
40
+ $ papa release start -v 17.12.0
41
+ ```
42
+
43
+ #### Adding feature branches to a release branch
44
+
45
+ This will rebase all new feature branches from the release branch and then subsequently merge the updated feature branch into the release branch. The updated release branch will be pushed to origin.
46
+
47
+ ```
48
+ $ papa release add -v, --version=VERSION [-b, --feature-branches=one two three]
13
49
  ```
14
50
 
15
- And then execute:
51
+ If `--feature-branches` is not specified, it will prompt a vi session where you can enter the branch names separated by line breaks.
16
52
 
17
- $ bundle
53
+ ##### Sample Usage:
18
54
 
19
- Or install it yourself as:
55
+ If you want to specify the feature branches using `--feature-branches`:
20
56
 
21
- $ gem install papa
57
+ ```
58
+ $ papa release add -v 17.12.0 -b feature/1 feature/2 feature/3
59
+ ```
60
+
61
+ If you want to use vi to specify the feature branches:
62
+
63
+ ```
64
+ $ papa release add -v 17.12.0
65
+ ```
22
66
 
23
- ## Usage
67
+ #### Finishing a release branch
24
68
 
25
- TODO: Write usage instructions here
69
+ The finished release branch will be merged to `master` and `develop`. The updated `master` and `develop` branches will be pushed to origin.
26
70
 
27
- ## Development
71
+ ```
72
+ $ papa release finish -v, --version=VERSION
73
+ ```
28
74
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
75
+ ##### Sample Usage:
30
76
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
77
+ ```
78
+ $ papa release finish -v 17.12.0
79
+ ```
32
80
 
33
- ## Contributing
81
+ ### `papa hotfix`
82
+
83
+ #### Starting a hotfix branch
84
+
85
+ This will create a new hotfix branch based on the current `master` branch. The hotfix branch will be pushed to origin.
86
+
87
+ ```
88
+ $ papa hotfix start -v, --version=VERSION
89
+ ```
90
+
91
+ ###### Sample Usage:
92
+
93
+ ```
94
+ $ papa hotfix start -v 17.12.0
95
+ ```
34
96
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/b-ggs/papa.
97
+ #### Adding bugfix branches to a hotfix branch
36
98
 
37
- ## License
99
+ This will rebase all new bugfix branches from the hotfix branch and then subsequently merge the updated bugfix branch into the release branch. The updated release branch will be pushed to origin.
38
100
 
39
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
101
+ ```
102
+ $ papa hotfix add -v, --version=VERSION [-b, --bugfix-branches=one two three]
103
+ ```
104
+
105
+ If `--bugfix-branches` is not specified, it will prompt a vi session where you can enter the branch names separated by line breaks.
106
+
107
+ ##### Sample Usage:
108
+
109
+ If you want to specify the bugfix branches using `--bugfix-branches`:
110
+
111
+ ```
112
+ $ papa hotfix add -v 17.12.0 -b bugfix/1 bugfix/2 bugfix/3
113
+ ```
114
+
115
+ If you want to use vi to specify the bugfix branches:
116
+
117
+ ```
118
+ $ papa hotfix add -v 17.12.0
119
+ ```
120
+
121
+ #### Finishing a hotfix branch
122
+
123
+ The finished hotfix branch will be merged to `master` and `develop`. The updated `master` and `develop` branches will be pushed to origin.
124
+
125
+ ```
126
+ $ papa release hotfix -v, --version=VERSION
127
+ ```
128
+
129
+ ##### Sample Usage:
130
+
131
+ ```
132
+ $ papa release hotfix -v 17.12.0
133
+ ```
134
+
135
+ ### `papa integration`
136
+
137
+ #### Starting an integration branch
138
+
139
+ This will create a new integration branch based on the specified base branch. The integration branch will be pushed to origin.
140
+
141
+ ```
142
+ $ papa integration start -b, --base-branch=BASE_BRANCH
143
+ ```
144
+
145
+ ##### Sample Usage:
146
+
147
+ ```
148
+ $ papa integration start -b develop
149
+ ```
150
+
151
+ ### `papa deploy`
152
+
153
+ ### `papa sandbox`
154
+
155
+ #### Generating a new sandbox
156
+
157
+ This will generate a git repository that you can use to test out `papa`.
158
+
159
+ ```
160
+ $ papa sandbox generate
161
+ ```
@@ -1,11 +1,13 @@
1
1
  require 'thor'
2
2
  require 'papa/thor'
3
+ require 'papa/string'
3
4
  require 'papa/version'
4
5
  require 'papa/cli'
5
6
  require 'papa/command'
6
7
  require 'papa/command_queue'
7
8
  require 'papa/git'
8
9
  require 'papa/output'
10
+ require 'papa/helpers'
9
11
 
10
12
  module Papa
11
13
  end
@@ -12,10 +12,10 @@ module Papa
12
12
 
13
13
  desc 'add', 'Add bugfix branches to a hotfix branch'
14
14
  option :version, aliases: '-v', required: true
15
- option :bugfix_branches, aliases: '-b', type: :array, required: true
15
+ option :bugfix_branches, aliases: '-b', type: :array
16
16
  def add
17
17
  version = options[:version]
18
- bugfix_branches = options[:bugfix_branches]
18
+ bugfix_branches = options[:bugfix_branches] || []
19
19
 
20
20
  require 'papa/common/add'
21
21
  require 'papa/hotfix/add'
@@ -12,10 +12,10 @@ module Papa
12
12
 
13
13
  desc 'add', 'Add feature branches to a release branch'
14
14
  option :version, aliases: '-v', required: true
15
- option :feature_branches, aliases: '-b', type: :array, required: true
15
+ option :feature_branches, aliases: '-b', type: :array
16
16
  def add
17
17
  version = options[:version]
18
- feature_branches = options[:feature_branches]
18
+ feature_branches = options[:feature_branches] || []
19
19
 
20
20
  require 'papa/common/add'
21
21
  require 'papa/release/add'
@@ -2,11 +2,16 @@ module Papa
2
2
  class Sandbox < Thor
3
3
  desc 'generate', 'Generate a sandbox environment'
4
4
  option :override_origin, aliases: '-o'
5
+ option :override_path_prefix, aliases: '-p'
5
6
  def generate
6
- override_origin = options[:override_origin]
7
-
8
7
  require 'papa/sandbox/generate'
9
- Sandbox::Generate.new(override_origin: override_origin).run
8
+ Sandbox::Generate.new(options).run
9
+ end
10
+
11
+ desc 'clean', 'Clean up sandbox directories in /tmp'
12
+ def clean
13
+ require 'papa/sandbox/clean'
14
+ Sandbox::Clean.new.run
10
15
  end
11
16
  end
12
17
  end
@@ -1,30 +1,27 @@
1
+ require 'open3'
2
+
1
3
  module Papa
2
4
  class Command
3
- attr_accessor :command, :output, :exit_status
5
+ attr_accessor :command, :stdout, :stderr, :exit_status, :silent
4
6
 
5
7
  def initialize(command, options = {})
6
8
  @command = command
7
- @output = nil
8
- @exit_status = nil
9
- @output_redirect =
10
- if options[:silent]
11
- Output::REDIRECT_TO_NULL
12
- else
13
- ''
14
- end
9
+ @silent = options.has_key?(:silent) ? options[:silent] : false
15
10
  end
16
11
 
17
12
  def run
18
- return if @command.nil?
19
- output = `#{@command} #{@output_redirect}`
20
- exit_status = $?.exitstatus
21
- @output = output
22
- @exit_status = exit_status
13
+ return if command.nil?
14
+ Output.stdout "Running #{command.bold}..." unless silent
15
+ @stdout, @stderr, status = Open3.capture3(command)
16
+ @exit_status = status.exitstatus
23
17
  self
24
18
  end
25
19
 
26
20
  def failure_message
27
- Output.stderr "ERROR: There was a problem running '#{command}'"
21
+ message = "Error while running #{command.bold}"
22
+ Output.error message
23
+ Output.error stderr
24
+ message
28
25
  end
29
26
 
30
27
  def cleanup
@@ -36,7 +33,7 @@ module Papa
36
33
  end
37
34
 
38
35
  def failed?
39
- @exit_status != 0
36
+ exit_status != 0
40
37
  end
41
38
 
42
39
  private
@@ -1,6 +1,6 @@
1
1
  module Papa
2
2
  class CommandQueue
3
- attr_accessor :queue
3
+ attr_accessor :queue, :last_command, :success, :last_error
4
4
 
5
5
  def initialize
6
6
  @queue = []
@@ -10,25 +10,18 @@ module Papa
10
10
  @queue.push command
11
11
  end
12
12
 
13
- def list_queue
14
- Output.stdout 'Running:'
15
- @queue.each do |command|
16
- Output.stdout " #{command.command}"
17
- end
18
- end
19
-
20
13
  def run
21
- success = true
22
- list_queue
14
+ @success = true
15
+ message = nil
23
16
  @queue.each do |command|
24
17
  if command.run.failed?
25
- success = false
18
+ @success = false
26
19
  command.cleanup
27
- command.failure_message
20
+ @last_error = command.failure_message
28
21
  break
29
22
  end
30
23
  end
31
- success
24
+ @success
32
25
  end
33
26
  end
34
27
  end
@@ -1,12 +1,18 @@
1
1
  module Papa
2
2
  class Common::Add
3
3
  def run
4
+ check_branches
5
+
4
6
  @build_branch ||= "#{@build_type}/#{@version}"
5
7
 
6
8
  success = true
7
9
  @success_branches = []
10
+ @failed_branches = []
11
+
12
+ Output.stdout "Started adding branches to #{@build_branch.bold}."
8
13
 
9
- @branches.each do |branch|
14
+ @branches.each_with_index do |branch, index|
15
+ Output.stdout "Adding branch #{branch.bold} (#{index + 1} of #{@branches.count})..."
10
16
  queue = CommandQueue.new
11
17
  queue.add Git.fetch(remote: 'origin')
12
18
  queue.add Git.checkout(branch_name: @build_branch)
@@ -17,47 +23,79 @@ module Papa
17
23
  queue.add Git.checkout(branch_name: @build_branch)
18
24
  queue.add Git.merge(branch_name: branch)
19
25
  queue.add Git.push(remote: 'origin', branch_name: @build_branch)
26
+
20
27
  if queue.run
21
28
  @success_branches << branch
22
29
  else
30
+ failed_branch = {
31
+ branch: branch,
32
+ message: queue.last_error
33
+ }
34
+ @failed_branches << failed_branch
23
35
  success = false
24
36
  end
25
37
  end
26
38
 
27
- cleanup
39
+ success_message
40
+ failure_message
28
41
 
29
- success_message if !@success_branches.empty?
30
-
31
- if !success
32
- failure_message
42
+ if success
43
+ success_cleanup
44
+ else
45
+ failure_cleanup
33
46
  exit 1
34
47
  end
35
48
  end
36
49
 
37
50
  private
38
51
 
39
- def success_message
40
- Output.stdout "Successfully added these branches to #{@build_branch}:"
41
- @success_branches.each do |branch|
42
- Output.stdout " #{branch}"
43
- end
52
+ def check_branches
53
+ return unless @branches.empty?
54
+ require 'papa/helpers/vi'
55
+ vi_file_helper = Helpers::Vi.new
56
+ @branches = vi_file_helper.run
44
57
  end
45
58
 
46
- def cleanup
59
+ def success_cleanup
47
60
  queue = CommandQueue.new
48
61
  @branches.each { |branch| queue.add Git.delete_branch(branch_name: branch) }
49
62
  queue.run
50
63
  end
51
64
 
65
+ def success_message
66
+ return if @success_branches.empty?
67
+ output = ''
68
+ output << "Successfully added these branches to #{@build_branch}:\n"
69
+ @success_branches.each_with_index do |branch, index|
70
+ output << " #{index + 1}.) #{branch}\n"
71
+ end
72
+ Output.success output
73
+ end
74
+
75
+ def failure_cleanup
76
+ end
77
+
52
78
  def failure_message
53
- failed_branches = @branches - @success_branches
79
+ return if @failed_branches.empty?
80
+
81
+ output = ''
54
82
 
55
- Output.stderr "Failed to add these branches to #{@build_branch}:"
56
- failed_branches.each do |branch|
57
- Output.stderr " #{branch}"
83
+ output << "Failed to add these branches to #{@build_branch}:\n"
84
+ @failed_branches.each_with_index do |failed_branch, index|
85
+ branch = failed_branch[:branch]
86
+ message = failed_branch[:message]
87
+ output << " #{index + 1}.) #{branch}\n"
88
+ output << " - #{message}\n"
58
89
  end
59
- Output.stderr 'When the above problems are resolved, you can re-run this with:'
60
- Output.stderr " papa #{@build_type} add -v #{@version} -b #{failed_branches.join(' ')}"
90
+
91
+ output << "\n"
92
+
93
+ branch_names = @failed_branches.map { |f| f[:branch] }
94
+
95
+ output << "When the above problems are resolved, you can re-run this with:\n"
96
+ output << " papa #{@build_type} add -v #{@version} -b #{branch_names.join(' ')}"
97
+
98
+ Output.failure output
61
99
  end
62
100
  end
63
101
  end
@@ -3,13 +3,14 @@ module Papa
3
3
  def run
4
4
  @build_branch ||= "#{@build_type}/#{@version}"
5
5
 
6
- queue = CommandQueue.new
7
- queue.add Git.fetch(remote: 'origin')
8
- queue.add Git.checkout(branch_name: @base_branch)
9
- queue.add Git.branch(branch_name: @build_branch)
10
- queue.add Git.checkout(branch_name: @build_branch)
11
- queue.add Git.push(remote: 'origin', branch_name: @build_branch)
12
- if queue.run
6
+ @queue = CommandQueue.new
7
+ @queue.add Git.fetch(remote: 'origin')
8
+ @queue.add Git.checkout(branch_name: @base_branch)
9
+ @queue.add Git.branch(branch_name: @build_branch)
10
+ @queue.add Git.checkout(branch_name: @build_branch)
11
+ @queue.add Git.push(remote: 'origin', branch_name: @build_branch)
12
+
13
+ if @queue.run
13
14
  success_message
14
15
  else
15
16
  failure_message
@@ -20,11 +21,11 @@ module Papa
20
21
  private
21
22
 
22
23
  def success_message
23
- Output.stdout "Successfully started new #{@build_type} branch #{@build_branch}"
24
+ Output.success "Successfully started new #{@build_type} branch #{@build_branch}"
24
25
  end
25
26
 
26
27
  def failure_message
27
- Output.stderr "There was a problem starting #{@build_type} branch: #{@build_branch}"
28
+ Output.failure "There was a problem starting #{@build_type} branch: #{@build_branch}"
28
29
  end
29
30
  end
30
31
  end
@@ -8,7 +8,9 @@ module Papa
8
8
 
9
9
  def failure_message
10
10
  super
11
- Output.stderr "ERROR: Branch #{@branch_name} doesn't exist."
11
+ message = "Failed to checkout #{@branch_name.bold}. Check whether this branch exists."
12
+ Output.error message
13
+ message
12
14
  end
13
15
  end
14
16
  end
@@ -1,13 +1,16 @@
1
1
  module Papa
2
2
  class Git::Fetch < Command
3
3
  def initialize(remote)
4
+ @remote = remote
4
5
  command = "git fetch #{remote}"
5
6
  super(command)
6
7
  end
7
8
 
8
9
  def failure_message
9
10
  super
10
- Output.stderr 'ERROR: Make sure origin exists and you have a working Internet connection'
11
+ message = "Failed to fetch from #{@remote}. Please check your internet connection and try again."
12
+ Output.stderr message
13
+ message
11
14
  end
12
15
  end
13
16
  end
@@ -21,7 +21,9 @@ module Papa
21
21
 
22
22
  def failure_message
23
23
  super
24
- Output.stderr "ERROR: A merge conflict occurred while merging #{@branch_name} into #{current_branch}"
24
+ message = "Failed to merge #{@branch_name} into #{current_branch}. Merge conflict?"
25
+ Output.error message
26
+ message
25
27
  end
26
28
  end
27
29
  end
@@ -21,7 +21,9 @@ module Papa
21
21
 
22
22
  def failure_message
23
23
  super
24
- Output.stderr "ERROR: There was a problem rebasing #{current_branch} from #{@base_branch_name}"
24
+ message = "Failed to rebase #{current_branch} from #{@base_branch_name}. Merge conflict?"
25
+ Output.error message
26
+ message
25
27
  end
26
28
  end
27
29
  end
@@ -0,0 +1,4 @@
1
+ module Papa
2
+ class Helpers
3
+ end
4
+ end
@@ -0,0 +1,27 @@
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
@@ -0,0 +1,60 @@
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
@@ -1,13 +1,43 @@
1
+ require 'date'
2
+
1
3
  module Papa
2
4
  class Output
3
5
  REDIRECT_TO_NULL = '> /dev/null 2>&1'
4
6
 
5
7
  def self.stdout(message, options = {})
6
- puts message
8
+ puts build_output(message)
7
9
  end
8
10
 
9
11
  def self.stderr(message, options = {})
10
- STDERR.puts message
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')
11
41
  end
12
42
  end
13
43
  end
@@ -0,0 +1,17 @@
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,11 +1,13 @@
1
+ require 'papa/helpers/path'
2
+
1
3
  module Papa
2
4
  class Sandbox::Generate
3
- attr_accessor :remote_repository_directory, :local_repository_directory, :git_details
5
+ attr_accessor :remote_path, :local_path, :git_details, :options
4
6
 
5
7
  def initialize(options = {})
6
8
  @options = options
7
- @remote_repository_directory = '/tmp/papa_sandbox_remote_repository'
8
- @local_repository_directory = '/tmp/papa_sandbox_local_repository'
9
+ @remote_path = Helpers::Path.generate_sandbox_path('remote', options)
10
+ @local_path = Helpers::Path.generate_sandbox_path('local', options)
9
11
  @git_details = [
10
12
  {
11
13
  commit: 'APP-1 - Add butterfree gem',
@@ -45,8 +47,8 @@ module Papa
45
47
  ]
46
48
  end
47
49
 
48
- def run(options = {})
49
- Output.stdout('Generating sandbox...') unless options[:silent]
50
+ def run
51
+ Output.stdout('Started generation of sandbox...') unless options[:silent]
50
52
  @project_directory = File.expand_path(File.dirname(__dir__))
51
53
  @branches_directory = File.join @project_directory, 'sandbox', 'branches'
52
54
  setup_remote_repository
@@ -61,46 +63,46 @@ module Papa
61
63
  end
62
64
 
63
65
  def temp_gemfile_path
64
- File.join @local_repository_directory, 'Gemfile'
66
+ File.join @local_path, 'Gemfile'
65
67
  end
66
68
 
67
69
  def setup_remote_repository
68
- if @options[:override_origin]
69
- create_local_repository_directory
70
+ if options[:override_origin]
71
+ create_local_path
70
72
  initialize_local_repository
71
73
  remove_old_branches_from_origin
72
74
  else
73
- create_remote_repository_directory
75
+ create_remote_path
74
76
  initialize_remote_repository
75
- create_local_repository_directory
77
+ create_local_path
76
78
  clone_remote_repository
77
79
  end
78
80
  end
79
81
 
80
- def create_local_repository_directory
81
- Command.new("rm -rf #{@local_repository_directory}").run
82
- Dir.mkdir @local_repository_directory
82
+ def create_local_path
83
+ Command.new("rm -rf #{@local_path}", options).run
84
+ Dir.mkdir @local_path
83
85
  end
84
86
 
85
87
  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
88
+ Dir.chdir @local_path
89
+ Command.new('git init', options).run
90
+ Command.new("git remote add origin #{options[:override_origin]}", options).run
89
91
  end
90
92
 
91
- def create_remote_repository_directory
92
- Command.new("rm -rf #{@remote_repository_directory}").run
93
- Dir.mkdir @remote_repository_directory
93
+ def create_remote_path
94
+ Command.new("rm -rf #{@remote_path}", options).run
95
+ Dir.mkdir @remote_path
94
96
  end
95
97
 
96
98
  def initialize_remote_repository
97
- Dir.chdir @remote_repository_directory
98
- Command.new('git init --bare').run
99
+ Dir.chdir @remote_path
100
+ Command.new('git init --bare', options).run
99
101
  end
100
102
 
101
103
  def clone_remote_repository
102
- Command.new("git clone #{@remote_repository_directory} #{@local_repository_directory}", silent: true).run
103
- Dir.chdir @local_repository_directory
104
+ Command.new("git clone #{@remote_path} #{@local_path}", options).run
105
+ Dir.chdir @local_path
104
106
  end
105
107
 
106
108
  def setup_local_repository
@@ -121,7 +123,7 @@ module Papa
121
123
 
122
124
  def initialize_master_and_develop
123
125
  [
124
- "cp #{gemfile_path('master')} #{@local_repository_directory}",
126
+ "cp #{gemfile_path('master')} #{@local_path}",
125
127
  'git add .',
126
128
  'git commit -m "Initial commit"',
127
129
  'git push origin master --force',
@@ -141,7 +143,7 @@ module Papa
141
143
  "git checkout #{base_branch}",
142
144
  "git checkout -b #{branch}",
143
145
  "rm #{temp_gemfile_path}",
144
- "cp #{gemfile_path(branch)} #{@local_repository_directory}",
146
+ "cp #{gemfile_path(branch)} #{@local_path}",
145
147
  "git add .",
146
148
  "git commit -m \"#{commit}\"",
147
149
  "git push origin #{branch} --force"
@@ -159,10 +161,7 @@ module Papa
159
161
  end
160
162
 
161
163
  def success_message
162
- Output.stdout <<-STDOUT
163
- Your sandbox is now available at:
164
- #{@local_repository_directory}
165
- STDOUT
164
+ Output.success "Your sandbox is now available at:\n #{@local_path}"
166
165
  end
167
166
 
168
167
  def override_origin(origin)
@@ -0,0 +1,27 @@
1
+ # Color overrides for terminal output (ref: https://stackoverflow.com/a/16363159)
2
+
3
+ class String
4
+ def black; "\e[30m#{self}\e[0m" end
5
+ def red; "\e[31m#{self}\e[0m" end
6
+ def green; "\e[32m#{self}\e[0m" end
7
+ def brown; "\e[33m#{self}\e[0m" end
8
+ def blue; "\e[34m#{self}\e[0m" end
9
+ def magenta; "\e[35m#{self}\e[0m" end
10
+ def cyan; "\e[36m#{self}\e[0m" end
11
+ def gray; "\e[37m#{self}\e[0m" end
12
+
13
+ def bg_black; "\e[40m#{self}\e[0m" end
14
+ def bg_red; "\e[41m#{self}\e[0m" end
15
+ def bg_green; "\e[42m#{self}\e[0m" end
16
+ def bg_brown; "\e[43m#{self}\e[0m" end
17
+ def bg_blue; "\e[44m#{self}\e[0m" end
18
+ def bg_magenta; "\e[45m#{self}\e[0m" end
19
+ def bg_cyan; "\e[46m#{self}\e[0m" end
20
+ def bg_gray; "\e[47m#{self}\e[0m" end
21
+
22
+ def bold; "\e[1m#{self}\e[22m" end
23
+ def italic; "\e[3m#{self}\e[23m" end
24
+ def underline; "\e[4m#{self}\e[24m" end
25
+ def blink; "\e[5m#{self}\e[25m" end
26
+ def reverse_color; "\e[7m#{self}\e[27m" end
27
+ end
@@ -1,3 +1,3 @@
1
1
  module Papa
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: papa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - boggs
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-11 00:00:00.000000000 Z
11
+ date: 2017-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -101,6 +101,9 @@ files:
101
101
  - lib/papa/git/fetch.rb
102
102
  - lib/papa/git/merge.rb
103
103
  - lib/papa/git/rebase.rb
104
+ - lib/papa/helpers.rb
105
+ - lib/papa/helpers/path.rb
106
+ - lib/papa/helpers/vi.rb
104
107
  - lib/papa/hotfix/add.rb
105
108
  - lib/papa/hotfix/finish.rb
106
109
  - lib/papa/hotfix/start.rb
@@ -121,7 +124,9 @@ files:
121
124
  - lib/papa/sandbox/branches/feature/7-add-pidgeot-gem/Gemfile
122
125
  - lib/papa/sandbox/branches/master/Gemfile
123
126
  - lib/papa/sandbox/branches/patch/17.8.0/3-add-pidgey-gem/Gemfile
127
+ - lib/papa/sandbox/clean.rb
124
128
  - lib/papa/sandbox/generate.rb
129
+ - lib/papa/string.rb
125
130
  - lib/papa/thor.rb
126
131
  - lib/papa/version.rb
127
132
  - papa.gemspec