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 +4 -4
- data/CHANGELOG.md +10 -3
- data/README.md +142 -20
- data/lib/papa.rb +2 -0
- data/lib/papa/cli/hotfix.rb +2 -2
- data/lib/papa/cli/release.rb +2 -2
- data/lib/papa/cli/sandbox.rb +8 -3
- data/lib/papa/command.rb +13 -16
- data/lib/papa/command_queue.rb +6 -13
- data/lib/papa/common/add.rb +56 -18
- data/lib/papa/common/start.rb +10 -9
- data/lib/papa/git/checkout.rb +3 -1
- data/lib/papa/git/fetch.rb +4 -1
- data/lib/papa/git/merge.rb +3 -1
- data/lib/papa/git/rebase.rb +3 -1
- data/lib/papa/helpers.rb +4 -0
- data/lib/papa/helpers/path.rb +27 -0
- data/lib/papa/helpers/vi.rb +60 -0
- data/lib/papa/output.rb +32 -2
- data/lib/papa/sandbox/clean.rb +17 -0
- data/lib/papa/sandbox/generate.rb +28 -29
- data/lib/papa/string.rb +27 -0
- data/lib/papa/version.rb +1 -1
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e79d7aa5abd7759a7acee2ac1538c6f4b3bc69e
|
4
|
+
data.tar.gz: 7eb13ccb695d9c423d1b3f60dd552184ef86c705
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 807475a93bd68e8e520a7f069d38e1dee3c8e6491f81c21835140fa50af63e7f174994b69b5b2b2e82d6aeb7a5aa226063508ebbfe3f09fcc2911c0868879520
|
7
|
+
data.tar.gz: fd5289d8f9149e28666954a68def6ac64c9f1af26f5dfcdb3d1719a81244be2c2007e6720a5e046f18d3437e867ead2c6be84cea66d4079f570b1da898d474fc
|
data/CHANGELOG.md
CHANGED
@@ -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
|
-
|
3
|
+
Helper tool for inDinero's git workflow. Ako ang papa mo.
|
4
4
|
|
5
|
-
|
5
|
+
## Contents
|
6
6
|
|
7
|
-
|
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
|
-
|
15
|
+
## Getting Started
|
10
16
|
|
11
|
-
|
12
|
-
|
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
|
-
|
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
|
-
|
53
|
+
##### Sample Usage:
|
18
54
|
|
19
|
-
|
55
|
+
If you want to specify the feature branches using `--feature-branches`:
|
20
56
|
|
21
|
-
|
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
|
-
|
67
|
+
#### Finishing a release branch
|
24
68
|
|
25
|
-
|
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
|
-
|
71
|
+
```
|
72
|
+
$ papa release finish -v, --version=VERSION
|
73
|
+
```
|
28
74
|
|
29
|
-
|
75
|
+
##### Sample Usage:
|
30
76
|
|
31
|
-
|
77
|
+
```
|
78
|
+
$ papa release finish -v 17.12.0
|
79
|
+
```
|
32
80
|
|
33
|
-
|
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
|
-
|
97
|
+
#### Adding bugfix branches to a hotfix branch
|
36
98
|
|
37
|
-
|
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
|
-
|
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
|
+
```
|
data/lib/papa.rb
CHANGED
@@ -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
|
data/lib/papa/cli/hotfix.rb
CHANGED
@@ -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
|
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'
|
data/lib/papa/cli/release.rb
CHANGED
@@ -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
|
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'
|
data/lib/papa/cli/sandbox.rb
CHANGED
@@ -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(
|
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
|
data/lib/papa/command.rb
CHANGED
@@ -1,30 +1,27 @@
|
|
1
|
+
require 'open3'
|
2
|
+
|
1
3
|
module Papa
|
2
4
|
class Command
|
3
|
-
attr_accessor :command, :
|
5
|
+
attr_accessor :command, :stdout, :stderr, :exit_status, :silent
|
4
6
|
|
5
7
|
def initialize(command, options = {})
|
6
8
|
@command = command
|
7
|
-
@
|
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
|
19
|
-
|
20
|
-
|
21
|
-
@
|
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
|
-
|
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
|
-
|
36
|
+
exit_status != 0
|
40
37
|
end
|
41
38
|
|
42
39
|
private
|
data/lib/papa/command_queue.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/papa/common/add.rb
CHANGED
@@ -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.
|
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
|
-
|
39
|
+
success_message
|
40
|
+
failure_message
|
28
41
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
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
|
-
|
79
|
+
return if @failed_branches.empty?
|
80
|
+
|
81
|
+
output = ''
|
54
82
|
|
55
|
-
|
56
|
-
failed_branches.
|
57
|
-
|
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
|
-
|
60
|
-
|
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
|
data/lib/papa/common/start.rb
CHANGED
@@ -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
|
-
|
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.
|
24
|
+
Output.success "Successfully started new #{@build_type} branch #{@build_branch}"
|
24
25
|
end
|
25
26
|
|
26
27
|
def failure_message
|
27
|
-
Output.
|
28
|
+
Output.failure "There was a problem starting #{@build_type} branch: #{@build_branch}"
|
28
29
|
end
|
29
30
|
end
|
30
31
|
end
|
data/lib/papa/git/checkout.rb
CHANGED
data/lib/papa/git/fetch.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/papa/git/merge.rb
CHANGED
@@ -21,7 +21,9 @@ module Papa
|
|
21
21
|
|
22
22
|
def failure_message
|
23
23
|
super
|
24
|
-
|
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
|
data/lib/papa/git/rebase.rb
CHANGED
@@ -21,7 +21,9 @@ module Papa
|
|
21
21
|
|
22
22
|
def failure_message
|
23
23
|
super
|
24
|
-
|
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
|
data/lib/papa/helpers.rb
ADDED
@@ -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
|
data/lib/papa/output.rb
CHANGED
@@ -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 :
|
5
|
+
attr_accessor :remote_path, :local_path, :git_details, :options
|
4
6
|
|
5
7
|
def initialize(options = {})
|
6
8
|
@options = options
|
7
|
-
@
|
8
|
-
@
|
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
|
49
|
-
Output.stdout('
|
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 @
|
66
|
+
File.join @local_path, 'Gemfile'
|
65
67
|
end
|
66
68
|
|
67
69
|
def setup_remote_repository
|
68
|
-
if
|
69
|
-
|
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
|
-
|
75
|
+
create_remote_path
|
74
76
|
initialize_remote_repository
|
75
|
-
|
77
|
+
create_local_path
|
76
78
|
clone_remote_repository
|
77
79
|
end
|
78
80
|
end
|
79
81
|
|
80
|
-
def
|
81
|
-
Command.new("rm -rf #{@
|
82
|
-
Dir.mkdir @
|
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 @
|
87
|
-
Command.new('git init').run
|
88
|
-
Command.new("git remote add origin #{
|
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
|
92
|
-
Command.new("rm -rf #{@
|
93
|
-
Dir.mkdir @
|
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 @
|
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 #{@
|
103
|
-
Dir.chdir @
|
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')} #{@
|
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)} #{@
|
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.
|
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)
|
data/lib/papa/string.rb
ADDED
@@ -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
|
data/lib/papa/version.rb
CHANGED
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.
|
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-
|
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
|