octopolo 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CHANGELOG.markdown +1 -0
- data/lib/octopolo.rb +4 -0
- data/lib/octopolo/commands/pull_request.rb +5 -1
- data/lib/octopolo/github/pull_request_creator.rb +23 -1
- data/lib/octopolo/scripts/pull_request.rb +6 -3
- data/lib/octopolo/user_config.rb +8 -0
- data/lib/octopolo/version.rb +1 -1
- data/spec/octopolo/github/pull_request_creator_spec.rb +71 -0
- data/spec/octopolo/scripts/pull_request_spec.rb +1 -0
- data/spec/octopolo/user_config_spec.rb +13 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YWJiMDZmMWJkMWE1YjhkOWY2YzY3MDY4YWI3M2E0MDRmZDUxNDg3Mg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YjFhNGU3NzdkODFiYmM4YjBlYjIzNjc2ZWI5Y2E2YzVmOWM0OGViMQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Njk1YjE0Mjk0ZjRhZThhZGE4OGU2YTE0ZmI3MjM3ZjEzYTEzOGI0NmZiN2E5
|
10
|
+
NjcxZWMxYzQ5ZTg3Y2VlMDMzMzA2NDFjZTQ5NDUzMTdkNGNmNjcyZmEwZTBj
|
11
|
+
YTY3YzNiNTE2OTEyOGFlZTQ4OTIwYjgzNDdkMmZiN2VlNDQxODY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NDA2OTA3ODIyNTk5NWQxOTU1ZTdkZDBhNWE0ODkxNGUzNjgwMDJhYWQwNDkw
|
14
|
+
MGJmYzgxZjFhZDgxZDYxMDQwMzQ3NmNlOTliNTM1ZGQzODg2OGJmNDI4NzFl
|
15
|
+
OTk5ODQyZjliMTNjYjE3YmIzYjQ4ZWYyNjZlZDM3YjBkZTA1NmY=
|
data/CHANGELOG.markdown
CHANGED
data/lib/octopolo.rb
CHANGED
@@ -1,13 +1,17 @@
|
|
1
1
|
desc "Create a pull request from the current branch to the application's designated deploy branch."
|
2
2
|
command 'pull-request' do |c|
|
3
3
|
config = Octopolo::Config.parse
|
4
|
+
user_config = Octopolo::UserConfig.parse
|
4
5
|
|
5
6
|
c.desc "Branch to create the pull request against"
|
6
7
|
c.flag [:d, :dest, :destination], :arg_name => "destination_branch", :default_value => config.deploy_branch
|
7
8
|
|
9
|
+
c.desc "Use $EDITOR to update PR description before creating"
|
10
|
+
c.switch [:e, :editor], :default_value => user_config.editor
|
11
|
+
|
8
12
|
c.action do |global_options, options, args|
|
9
13
|
require_relative '../scripts/pull_request'
|
10
14
|
options = global_options.merge(options)
|
11
|
-
Octopolo::Scripts::PullRequest.execute options[:destination]
|
15
|
+
Octopolo::Scripts::PullRequest.execute options[:destination], options
|
12
16
|
end
|
13
17
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative "../renderer"
|
2
|
+
require 'tempfile'
|
2
3
|
|
3
4
|
module Octopolo
|
4
5
|
module GitHub
|
@@ -107,7 +108,28 @@ module Octopolo
|
|
107
108
|
#
|
108
109
|
# Returns a String
|
109
110
|
def body
|
110
|
-
Renderer.render Renderer::PULL_REQUEST_BODY, body_locals
|
111
|
+
output = Renderer.render Renderer::PULL_REQUEST_BODY, body_locals
|
112
|
+
output = edit_body(output) if options[:editor]
|
113
|
+
output
|
114
|
+
end
|
115
|
+
|
116
|
+
def edit_body(body)
|
117
|
+
return body unless ENV['EDITOR']
|
118
|
+
|
119
|
+
# Open the file, write the contents, and close it
|
120
|
+
tempfile = Tempfile.new(['octopolo_pull_request', '.md'])
|
121
|
+
tempfile.write(body)
|
122
|
+
tempfile.close
|
123
|
+
|
124
|
+
# Allow the user to edit the file
|
125
|
+
system "#{ENV['EDITOR']} #{tempfile.path}"
|
126
|
+
|
127
|
+
# Reopen the file, read the contents, and delete it
|
128
|
+
tempfile.open
|
129
|
+
output = tempfile.read
|
130
|
+
tempfile.unlink
|
131
|
+
|
132
|
+
output
|
111
133
|
end
|
112
134
|
|
113
135
|
# Public: The local variables to pass into the template
|
@@ -16,13 +16,15 @@ module Octopolo
|
|
16
16
|
attr_accessor :jira_ids
|
17
17
|
attr_accessor :destination_branch
|
18
18
|
attr_accessor :label
|
19
|
+
attr_accessor :options
|
19
20
|
|
20
|
-
def self.execute(destination_branch=nil)
|
21
|
-
new(destination_branch).execute
|
21
|
+
def self.execute(destination_branch=nil, options={})
|
22
|
+
new(destination_branch, options).execute
|
22
23
|
end
|
23
24
|
|
24
|
-
def initialize(destination_branch=nil)
|
25
|
+
def initialize(destination_branch=nil, options={})
|
25
26
|
@destination_branch = destination_branch || default_destination_branch
|
27
|
+
@options = options
|
26
28
|
end
|
27
29
|
|
28
30
|
def default_destination_branch
|
@@ -108,6 +110,7 @@ module Octopolo
|
|
108
110
|
source_branch: git.current_branch,
|
109
111
|
pivotal_ids: pivotal_ids,
|
110
112
|
jira_ids: jira_ids,
|
113
|
+
editor: options[:editor]
|
111
114
|
}
|
112
115
|
end
|
113
116
|
private :pull_request_attributes
|
data/lib/octopolo/user_config.rb
CHANGED
@@ -4,6 +4,7 @@ module Octopolo
|
|
4
4
|
attr_accessor :github_user
|
5
5
|
attr_accessor :github_token
|
6
6
|
attr_accessor :full_name
|
7
|
+
attr_accessor :editor
|
7
8
|
attr_accessor :pivotal_token
|
8
9
|
attr_accessor :attributes # keep the whole hash
|
9
10
|
|
@@ -79,6 +80,13 @@ module Octopolo
|
|
79
80
|
@full_name || ENV["USER"]
|
80
81
|
end
|
81
82
|
|
83
|
+
# Public: Always use the $EDITOR when available
|
84
|
+
#
|
85
|
+
# Returns a value or false
|
86
|
+
def editor
|
87
|
+
@editor || false
|
88
|
+
end
|
89
|
+
|
82
90
|
# Public: The GitHub username
|
83
91
|
#
|
84
92
|
# If none is stored, generate it for the user.
|
data/lib/octopolo/version.rb
CHANGED
@@ -154,6 +154,60 @@ module Octopolo
|
|
154
154
|
end
|
155
155
|
end
|
156
156
|
|
157
|
+
context "#edit_body" do
|
158
|
+
let(:path) { stub(:path) }
|
159
|
+
let(:body) { stub(:string) }
|
160
|
+
let(:tempfile) { stub(:tempfile) }
|
161
|
+
let(:edited_body) { stub(:edited_body) }
|
162
|
+
|
163
|
+
before do
|
164
|
+
Tempfile.stub(:new) { tempfile }
|
165
|
+
tempfile.stub(path: path, write: nil, read: edited_body, unlink: nil, close: nil, open: nil)
|
166
|
+
creator.stub(:system)
|
167
|
+
end
|
168
|
+
|
169
|
+
context "without the $EDITOR env var set" do
|
170
|
+
before do
|
171
|
+
stub_const('ENV', {'EDITOR' => nil})
|
172
|
+
end
|
173
|
+
|
174
|
+
it "returns the un-edited output" do
|
175
|
+
creator.edit_body(body).should == body
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
context "with the $EDITOR env set" do
|
180
|
+
|
181
|
+
before do
|
182
|
+
stub_const('ENV', {'EDITOR' => 'vim'})
|
183
|
+
end
|
184
|
+
|
185
|
+
it "creates a tempfile, write default contents, and close it" do
|
186
|
+
Tempfile.should_receive(:new).with(['octopolo_pull_request', '.md']) { tempfile }
|
187
|
+
tempfile.should_receive(:write).with(body)
|
188
|
+
tempfile.should_receive(:close)
|
189
|
+
creator.edit_body body
|
190
|
+
end
|
191
|
+
|
192
|
+
it "edits the tempfile with the $EDITOR" do
|
193
|
+
tempfile.should_receive(:path) { path }
|
194
|
+
creator.should_receive(:system).with("vim #{path}")
|
195
|
+
creator.edit_body body
|
196
|
+
end
|
197
|
+
|
198
|
+
it "reopens the file, gets the contents, and deletes the temp file" do
|
199
|
+
tempfile.should_receive(:open)
|
200
|
+
tempfile.should_receive(:read) { edited_body }
|
201
|
+
tempfile.should_receive(:unlink)
|
202
|
+
creator.edit_body body
|
203
|
+
end
|
204
|
+
|
205
|
+
it "returns the user edited output" do
|
206
|
+
creator.edit_body(body).should == edited_body
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
157
211
|
context "#body" do
|
158
212
|
let(:locals) { stub(:hash) }
|
159
213
|
let(:output) { stub(:string) }
|
@@ -168,6 +222,23 @@ module Octopolo
|
|
168
222
|
Renderer.should_receive(:render).with(Renderer::PULL_REQUEST_BODY, locals) { output }
|
169
223
|
creator.body.should == output
|
170
224
|
end
|
225
|
+
|
226
|
+
context "when the editor option is set" do
|
227
|
+
let(:edited_output) { stub(:output) }
|
228
|
+
|
229
|
+
before do
|
230
|
+
creator.stub({
|
231
|
+
body_locals: locals,
|
232
|
+
options: { editor: true }
|
233
|
+
})
|
234
|
+
end
|
235
|
+
|
236
|
+
it "calls the edit_body method" do
|
237
|
+
Renderer.should_receive(:render).with(Renderer::PULL_REQUEST_BODY, locals) { output }
|
238
|
+
creator.should_receive(:edit_body).with(output) { edited_output }
|
239
|
+
creator.body.should == edited_output
|
240
|
+
end
|
241
|
+
end
|
171
242
|
end
|
172
243
|
end
|
173
244
|
end
|
@@ -119,6 +119,19 @@ module Octopolo
|
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
122
|
+
context "#editor" do
|
123
|
+
let(:config) { UserConfig.new }
|
124
|
+
|
125
|
+
it "returns the configured value" do
|
126
|
+
config.editor = true
|
127
|
+
config.editor.should == true
|
128
|
+
end
|
129
|
+
|
130
|
+
it "returns false otherwise" do
|
131
|
+
config.editor.should == false
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
122
135
|
context "#github_user" do
|
123
136
|
let(:config) { UserConfig.new }
|
124
137
|
let(:username) { "joeperson" }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: octopolo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrick Byrne
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-02-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|