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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9601c51e9fb7c39a2290715c05e752aeb5898c58
4
- data.tar.gz: f0947bba05dcedbae40a94a770075b837f0b8fb3
3
+ metadata.gz: 742702af29fe7faca6d421caa1baef609eb0cac4
4
+ data.tar.gz: d37fab96da9f0477fa23d101c54518c76a6a63ea
5
5
  SHA512:
6
- metadata.gz: 8fb42815aa779d1b86f52d5c3c07f34fe1d06a8b97992a950d2e5cb7b1a9ab02d35d8131756cf780193039b5cfaf96bee9256204355878a6a8677a1ec6c07034
7
- data.tar.gz: 5efd37b850dd801e9dd91537c70dc7e0616f1a4c601407789cf71594e9decbf5d5db221f8b90a4b0cd2b3b46dddc34066c7db7c4bd958c44e31093479fb2dc6f
6
+ metadata.gz: c907b35e58cc397cc791fcf0e65a7a45e685ec72475f857f7f82dd41d1fe1edade4e21b96de2f761c9365d6cc2d30f2509abb90f1ebedcca540091c54b540fd6
7
+ data.tar.gz: 4d56ae5a5484a841170660df9820a6d7117d1ed74bd953fea1200c293de61b4f7e55c469e5941a6b0067ff8a05fab157d70623b33536942d12ee193cd8bf7397
@@ -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
- token = authorization_token
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
- branch = current_branch
49
- repo = current_remote_repo
50
- url = create_pull_request token, branch, repo, description
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 ~/.socialcast/credentials.yml for future reuse
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(token, branch, repo, body)
54
- payload = {:title => branch, :base => Thegarage::Gitx::BASE_BRANCH, :head => branch, :body => body}.to_json
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
- response = RestClient::Request.new(:url => "https://api.github.com/repos/#{repo}/pulls", :method => "POST", :payload => payload, :headers => {:accept => :json, :content_type => :json, 'Authorization' => "token #{token}"}).execute
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 "Failed to create pull request: #{data['message']}", :red
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
@@ -1,5 +1,5 @@
1
1
  module Thegarage
2
2
  module Gitx
3
- VERSION = '1.3.0'
3
+ VERSION = '1.4.0.pre1'
4
4
  end
5
5
  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
- expect(cli).to receive(:github_auth_token=).with(authorization_token)
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:'%ci - %s%n%b'", capture: true).and_return("2013-01-01 did some stuff").ordered
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
- expect(cli).to receive(:authorization_token).and_return(authorization_token)
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:'%ci - %s%n%b'", capture: true).and_return("2013-01-01 did some stuff").ordered
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.3.0
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-02-06 00:00:00.000000000 Z
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: '0'
204
+ version: 1.3.1
205
205
  requirements: []
206
206
  rubyforge_project:
207
207
  rubygems_version: 2.0.3