thegarage-gitx 1.3.0 → 1.4.0.pre1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/thegarage/gitx/cli.rb +6 -6
- data/lib/thegarage/gitx/github.rb +27 -5
- data/lib/thegarage/gitx/version.rb +1 -1
- data/spec/thegarage/gitx/cli_spec.rb +5 -8
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 742702af29fe7faca6d421caa1baef609eb0cac4
|
4
|
+
data.tar.gz: d37fab96da9f0477fa23d101c54518c76a6a63ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c907b35e58cc397cc791fcf0e65a7a45e685ec72475f857f7f82dd41d1fe1edade4e21b96de2f761c9365d6cc2d30f2509abb90f1ebedcca540091c54b540fd6
|
7
|
+
data.tar.gz: 4d56ae5a5484a841170660df9820a6d7117d1ed74bd953fea1200c293de61b4f7e55c469e5941a6b0067ff8a05fab157d70623b33536942d12ee193cd8bf7397
|
data/lib/thegarage/gitx/cli.rb
CHANGED
@@ -30,12 +30,13 @@ module Thegarage
|
|
30
30
|
|
31
31
|
desc "reviewrequest", "Create a pull request on github"
|
32
32
|
method_option :description, :type => :string, :aliases => '-d', :desc => 'pull request description'
|
33
|
+
method_option :assignee, :type => :string, :aliases => '-a', :desc => 'pull request assignee'
|
33
34
|
# @see http://developer.github.com/v3/pulls/
|
34
35
|
def reviewrequest
|
36
|
+
fail 'Github authorization token not found' unless authorization_token
|
35
37
|
update
|
36
38
|
|
37
|
-
|
38
|
-
changelog = run_cmd "git log #{BASE_BRANCH}...#{current_branch} --no-merges --pretty=format:'%ci - %s%n%b'"
|
39
|
+
changelog = run_cmd "git log #{BASE_BRANCH}...#{current_branch} --no-merges --pretty=format:'%s%n%b%n'"
|
39
40
|
description_template = []
|
40
41
|
description_template << options[:description]
|
41
42
|
description_template << "\n"
|
@@ -45,10 +46,9 @@ module Thegarage
|
|
45
46
|
description_template << PULL_REQUEST_FOOTER
|
46
47
|
|
47
48
|
description = editor_input(description_template.join("\n"))
|
48
|
-
|
49
|
-
|
50
|
-
url
|
51
|
-
say "Pull request created: #{url}", :green
|
49
|
+
url = create_pull_request description, options[:assignee]
|
50
|
+
say 'Pull request created: '
|
51
|
+
say url, :green
|
52
52
|
end
|
53
53
|
|
54
54
|
# TODO: use --no-edit to skip merge messages
|
@@ -12,7 +12,7 @@ module Thegarage
|
|
12
12
|
private
|
13
13
|
# request github authorization token
|
14
14
|
# User-Agent is required
|
15
|
-
# store the token in
|
15
|
+
# store the token in local git config
|
16
16
|
# @see http://developer.github.com/v3/oauth/#scopes
|
17
17
|
# @see http://developer.github.com/v3/#user-agent-required
|
18
18
|
def authorization_token
|
@@ -50,16 +50,23 @@ module Thegarage
|
|
50
50
|
|
51
51
|
# returns the url of the created pull request
|
52
52
|
# @see http://developer.github.com/v3/pulls/
|
53
|
-
def create_pull_request(
|
54
|
-
|
53
|
+
def create_pull_request(body, assignee = nil)
|
54
|
+
branch = current_branch
|
55
|
+
repo = current_remote_repo
|
56
|
+
|
55
57
|
say "Creating pull request for "
|
56
58
|
say "#{branch} ", :green
|
57
59
|
say "against "
|
58
60
|
say "#{Thegarage::Gitx::BASE_BRANCH} ", :green
|
59
61
|
say "in "
|
60
62
|
say repo, :green
|
61
|
-
|
63
|
+
|
64
|
+
payload = {:title => branch, :base => Thegarage::Gitx::BASE_BRANCH, :head => branch, :body => body}.to_json
|
65
|
+
response = RestClient::Request.new(:url => "https://api.github.com/repos/#{repo}/pulls", :method => "POST", :payload => payload, :headers => github_request_headers).execute
|
62
66
|
data = JSON.parse response.body
|
67
|
+
|
68
|
+
assign_pull_request(branch, assignee, data) if assignee
|
69
|
+
|
63
70
|
url = data['html_url']
|
64
71
|
url
|
65
72
|
rescue RestClient::Exception => e
|
@@ -67,9 +74,24 @@ module Thegarage
|
|
67
74
|
throw e
|
68
75
|
end
|
69
76
|
|
77
|
+
def assign_pull_request(branch, assignee, data)
|
78
|
+
issue_payload = { :title => branch, :assignee => assignee }.to_json
|
79
|
+
RestClient::Request.new(:url => data['issue_url'], :method => "PATCH", :payload => issue_payload, :headers => github_request_headers).execute
|
80
|
+
rescue RestClient::Exception => e
|
81
|
+
process_error e
|
82
|
+
end
|
83
|
+
|
70
84
|
def process_error(e)
|
71
85
|
data = JSON.parse e.http_body
|
72
|
-
say "
|
86
|
+
say "Github request failed: #{data['message']}", :red
|
87
|
+
end
|
88
|
+
|
89
|
+
def github_request_headers
|
90
|
+
{
|
91
|
+
:accept => :json,
|
92
|
+
:content_type => :json,
|
93
|
+
'Authorization' => "token #{authorization_token}"
|
94
|
+
}
|
73
95
|
end
|
74
96
|
end
|
75
97
|
end
|
@@ -279,9 +279,6 @@ describe Thegarage::Gitx::CLI do
|
|
279
279
|
let(:current_user) { nil }
|
280
280
|
it 'raises error' do
|
281
281
|
allow(cli).to receive(:current_user).and_return(current_user)
|
282
|
-
expect(cli).to receive(:run).with("git pull origin feature-branch", capture: true).ordered
|
283
|
-
expect(cli).to receive(:run).with("git pull origin master", capture: true).ordered
|
284
|
-
expect(cli).to receive(:run).with("git push origin HEAD", capture: true).ordered
|
285
282
|
|
286
283
|
expect do
|
287
284
|
cli.reviewrequest
|
@@ -309,14 +306,14 @@ describe Thegarage::Gitx::CLI do
|
|
309
306
|
to_return(:status => 200, :body => %q({"html_url": "http://github.com/repo/project/pulls/1"}), :headers => {})
|
310
307
|
|
311
308
|
allow(cli).to receive(:current_user).and_return(current_user)
|
312
|
-
expect(cli).to receive(:ask).with('Github password for ryan@codecrate.com: ', {:echo => false}).and_return(github_password)
|
313
|
-
|
309
|
+
expect(cli).to receive(:ask).with('Github password for ryan@codecrate.com: ', {:echo => false}).and_return(github_password).any_number_of_times
|
310
|
+
allow(cli).to receive(:github_auth_token=).with(authorization_token)
|
314
311
|
|
315
312
|
expect(cli).to receive(:editor_input).and_return('scrubbed text')
|
316
313
|
expect(cli).to receive(:run).with("git pull origin feature-branch", capture: true).ordered
|
317
314
|
expect(cli).to receive(:run).with("git pull origin master", capture: true).ordered
|
318
315
|
expect(cli).to receive(:run).with("git push origin HEAD", capture: true).ordered
|
319
|
-
expect(cli).to receive(:run).with("git log master...feature-branch --no-merges --pretty=format:'%
|
316
|
+
expect(cli).to receive(:run).with("git log master...feature-branch --no-merges --pretty=format:'%s%n%b%n'", capture: true).and_return("2013-01-01 did some stuff").ordered
|
320
317
|
|
321
318
|
cli.reviewrequest
|
322
319
|
end
|
@@ -337,13 +334,13 @@ describe Thegarage::Gitx::CLI do
|
|
337
334
|
stub_request(:post, "https://api.github.com/repos/thegarage/thegarage-gitx/pulls").
|
338
335
|
to_return(:status => 200, :body => %q({"html_url": "http://github.com/repo/project/pulls/1"}), :headers => {})
|
339
336
|
|
340
|
-
|
337
|
+
allow(cli).to receive(:authorization_token).and_return(authorization_token)
|
341
338
|
|
342
339
|
expect(cli).to receive(:editor_input).and_return('scrubbed text')
|
343
340
|
expect(cli).to receive(:run).with("git pull origin feature-branch", capture: true).ordered
|
344
341
|
expect(cli).to receive(:run).with("git pull origin master", capture: true).ordered
|
345
342
|
expect(cli).to receive(:run).with("git push origin HEAD", capture: true).ordered
|
346
|
-
expect(cli).to receive(:run).with("git log master...feature-branch --no-merges --pretty=format:'%
|
343
|
+
expect(cli).to receive(:run).with("git log master...feature-branch --no-merges --pretty=format:'%s%n%b%n'", capture: true).and_return("2013-01-01 did some stuff").ordered
|
347
344
|
|
348
345
|
cli.reviewrequest
|
349
346
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thegarage-gitx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0.pre1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Sonnek
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grit
|
@@ -199,9 +199,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
199
199
|
version: '0'
|
200
200
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
201
201
|
requirements:
|
202
|
-
- - '
|
202
|
+
- - '>'
|
203
203
|
- !ruby/object:Gem::Version
|
204
|
-
version:
|
204
|
+
version: 1.3.1
|
205
205
|
requirements: []
|
206
206
|
rubyforge_project:
|
207
207
|
rubygems_version: 2.0.3
|