thegarage-gitx 1.4.0 → 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/thegarage/gitx/cli.rb +7 -20
- data/lib/thegarage/gitx/git.rb +21 -67
- data/lib/thegarage/gitx/github.rb +106 -37
- data/lib/thegarage/gitx/version.rb +1 -1
- data/spec/thegarage/gitx/cli_spec.rb +4 -60
- data/spec/thegarage/gitx/github_spec.rb +84 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e53179bded6c6d5e54e69a8bacb3116ffcd411e
|
4
|
+
data.tar.gz: 770a7742c1daec8aafb3b8dee9291f3455498161
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80522f4bbe1c40bb3078b74f945f5921c10797bec6f2ea5f7cf659e2af9e0cceb6fde07c0f71919e4377914afe3f402cc2e00d9f5612a816d0d793136ea23fc1
|
7
|
+
data.tar.gz: 49e817eb55e0efb84e8feaa93c0c2eced2c3f791472510f88ed92dd04a316b00ae82ae3fa6f20aebcfe659bd588501463c75c530d74ac4c913769bc7daff4aff
|
data/lib/thegarage/gitx/cli.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require "thor"
|
2
2
|
require 'rest_client'
|
3
3
|
require 'thegarage/gitx'
|
4
|
+
require 'thegarage/gitx/github'
|
4
5
|
|
5
6
|
module Thegarage
|
6
7
|
module Gitx
|
@@ -8,18 +9,9 @@ module Thegarage
|
|
8
9
|
include Thor::Actions
|
9
10
|
add_runtime_options!
|
10
11
|
|
11
|
-
include Thegarage::Gitx
|
12
12
|
include Thegarage::Gitx::Git
|
13
|
-
include Thegarage::Gitx::Github
|
14
13
|
|
15
14
|
TAGGABLE_BRANCHES = %w(master staging)
|
16
|
-
PULL_REQUEST_FOOTER = <<-EOS.dedent
|
17
|
-
# Pull Request Protips
|
18
|
-
# Include description of how this change accomplishes the task at hand.
|
19
|
-
# Use GitHub flavored Markdown http://github.github.com/github-flavored-markdown/
|
20
|
-
# Review CONTRIBUTING.md for recommendations of artifacts, links, images, screencasts, etc.
|
21
|
-
# NOTE: this footer will automatically be stripped from the pull request.
|
22
|
-
EOS
|
23
15
|
|
24
16
|
method_option :trace, :type => :boolean, :aliases => '-v'
|
25
17
|
def initialize(*args)
|
@@ -33,19 +25,10 @@ module Thegarage
|
|
33
25
|
method_option :assignee, :type => :string, :aliases => '-a', :desc => 'pull request assignee'
|
34
26
|
# @see http://developer.github.com/v3/pulls/
|
35
27
|
def reviewrequest
|
36
|
-
fail 'Github authorization token not found' unless authorization_token
|
37
28
|
update
|
38
29
|
|
39
|
-
changelog = run_cmd "git log #{BASE_BRANCH}...#{current_branch} --no-merges --pretty=format:'* %s%n%b'"
|
40
|
-
|
41
|
-
description_template << options[:description]
|
42
|
-
description_template << "\n"
|
43
|
-
description_template << '### Changelog'
|
44
|
-
description_template << changelog
|
45
|
-
description_template << PULL_REQUEST_FOOTER
|
46
|
-
|
47
|
-
description = editor_input(description_template.join("\n"))
|
48
|
-
url = create_pull_request description, options[:assignee]
|
30
|
+
changelog = run_cmd "git log #{Thegarage::Gitx::BASE_BRANCH}...#{current_branch} --no-merges --pretty=format:'* %s%n%b'"
|
31
|
+
url = github.create_pull_request(current_branch, changelog, options)
|
49
32
|
say 'Pull request created: '
|
50
33
|
say url, :green
|
51
34
|
end
|
@@ -180,6 +163,10 @@ module Thegarage
|
|
180
163
|
def pretend?
|
181
164
|
options[:pretend]
|
182
165
|
end
|
166
|
+
|
167
|
+
def github
|
168
|
+
@github ||= Thegarage::Gitx::Github.new(current_repo, self)
|
169
|
+
end
|
183
170
|
end
|
184
171
|
end
|
185
172
|
end
|
data/lib/thegarage/gitx/git.rb
CHANGED
@@ -21,29 +21,6 @@ module Thegarage
|
|
21
21
|
@repo ||= Grit::Repo.new(Dir.pwd)
|
22
22
|
end
|
23
23
|
|
24
|
-
# lookup the current repository of the PWD
|
25
|
-
# ex: git@github.com:socialcast/thegarage/gitx.git OR https://github.com/socialcast/thegarage/gitx.git
|
26
|
-
def current_remote_repo
|
27
|
-
repo = current_repo.config['remote.origin.url']
|
28
|
-
repo.to_s.gsub(/\.git$/,'').split(/[:\/]/).last(2).join('/')
|
29
|
-
end
|
30
|
-
|
31
|
-
# @returns [String] github username (ex: 'wireframe') of the current github.user
|
32
|
-
# @returns empty [String] when no github.user is set on the system
|
33
|
-
def current_user
|
34
|
-
current_repo.config['github.user']
|
35
|
-
end
|
36
|
-
|
37
|
-
# @returns [String] auth token stored in git (current repo, user config or installed global settings)
|
38
|
-
def github_auth_token
|
39
|
-
current_repo.config['thegarage.gitx.githubauthtoken']
|
40
|
-
end
|
41
|
-
|
42
|
-
# store new auth token in the local project git config
|
43
|
-
def github_auth_token=(new_token)
|
44
|
-
current_repo.config['thegarage.gitx.githubauthtoken'] = new_token
|
45
|
-
end
|
46
|
-
|
47
24
|
# retrieve a list of branches
|
48
25
|
def branches(options = {})
|
49
26
|
branches = []
|
@@ -115,55 +92,32 @@ module Thegarage
|
|
115
92
|
AGGREGATE_BRANCHES.include?(branch)
|
116
93
|
end
|
117
94
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
f.flush
|
124
|
-
|
125
|
-
editor = ENV['EDITOR'] || 'vi'
|
126
|
-
flags = case editor
|
127
|
-
when 'mate', 'emacs', 'subl'
|
128
|
-
'-w'
|
129
|
-
when 'mvim'
|
130
|
-
'-f'
|
131
|
-
else
|
132
|
-
''
|
133
|
-
end
|
134
|
-
pid = fork { exec "#{editor} #{flags} #{f.path}" }
|
135
|
-
Process.waitpid(pid)
|
136
|
-
description = File.read(f.path)
|
137
|
-
description.gsub(CLI::PULL_REQUEST_FOOTER, '').chomp.strip
|
138
|
-
end
|
95
|
+
def create_build_tag(branch, label)
|
96
|
+
timestamp = Time.now.utc.strftime '%Y-%m-%d-%H-%M-%S'
|
97
|
+
git_tag = "build-#{branch}-#{timestamp}"
|
98
|
+
run_cmd "git tag #{git_tag} -a -m '#{label}'"
|
99
|
+
run_cmd "git push origin #{git_tag}"
|
139
100
|
end
|
140
|
-
end
|
141
|
-
|
142
|
-
def create_build_tag(branch, label)
|
143
|
-
timestamp = Time.now.utc.strftime '%Y-%m-%d-%H-%M-%S'
|
144
|
-
git_tag = "build-#{branch}-#{timestamp}"
|
145
|
-
run_cmd "git tag #{git_tag} -a -m '#{label}'"
|
146
|
-
run_cmd "git push origin #{git_tag}"
|
147
|
-
end
|
148
101
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
102
|
+
def build_tags_for_branch(branch)
|
103
|
+
run_cmd "git fetch --tags"
|
104
|
+
build_tags = run_cmd("git tag -l 'build-#{branch}-*'").split
|
105
|
+
build_tags.sort
|
106
|
+
end
|
154
107
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
108
|
+
def migrations_need_to_be_reverted?
|
109
|
+
return false unless File.exists?('db/migrate')
|
110
|
+
outdated_migrations = run_cmd("git diff #{head_branch}...#{outdated_branch} --name-only db/migrate").split
|
111
|
+
return false if outdated_migrations.empty?
|
159
112
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
113
|
+
say "#{outdated_branch} contains migrations that may need to be reverted. Ensure any reversable migrations are reverted on affected databases before nuking.", :red
|
114
|
+
say 'Example commands to revert outdated migrations:'
|
115
|
+
outdated_migrations.reverse.each do |migration|
|
116
|
+
version = File.basename(migration).split('_').first
|
117
|
+
say "rake db:migrate:down VERSION=#{version}"
|
118
|
+
end
|
119
|
+
!yes?("Are you sure you want to nuke #{outdated_branch}? (y/n) ", :green)
|
165
120
|
end
|
166
|
-
!yes?("Are you sure you want to nuke #{outdated_branch}? (y/n) ", :green)
|
167
121
|
end
|
168
122
|
end
|
169
123
|
end
|
@@ -1,26 +1,74 @@
|
|
1
|
-
require 'thegarage/gitx/git'
|
2
1
|
require 'rest_client'
|
3
2
|
require 'json'
|
3
|
+
require 'tempfile'
|
4
4
|
|
5
5
|
module Thegarage
|
6
6
|
module Gitx
|
7
|
-
|
8
|
-
include Thegarage::Gitx::Git
|
7
|
+
class Github
|
9
8
|
CLIENT_NAME = 'The Garage Git eXtensions'
|
10
9
|
CLIENT_URL = 'https://github.com/thegarage/thegarage-gitx'
|
10
|
+
PULL_REQUEST_FOOTER = <<-EOS.dedent
|
11
|
+
# Pull Request Protips(tm):
|
12
|
+
# * Include description of how this change accomplishes the task at hand.
|
13
|
+
# * Use GitHub flavored Markdown http://github.github.com/github-flavored-markdown/
|
14
|
+
# * Review CONTRIBUTING.md for recommendations of artifacts, links, images, screencasts, etc.
|
15
|
+
#
|
16
|
+
# This footer will automatically be stripped from the pull request description
|
17
|
+
EOS
|
18
|
+
|
19
|
+
attr_reader :repo, :shell
|
20
|
+
|
21
|
+
def initialize(repo, shell)
|
22
|
+
@repo = repo
|
23
|
+
@shell = shell
|
24
|
+
end
|
25
|
+
|
26
|
+
# returns the url of the created pull request
|
27
|
+
# @see http://developer.github.com/v3/pulls/
|
28
|
+
def create_pull_request(branch, changelog, options = {})
|
29
|
+
fail 'Github authorization token not found' unless authorization_token
|
30
|
+
remote = remote_origin_name
|
31
|
+
body = pull_request_body(changelog, options[:description])
|
32
|
+
|
33
|
+
shell.say "Creating pull request for "
|
34
|
+
shell.say "#{branch} ", :green
|
35
|
+
shell.say "against "
|
36
|
+
shell.say "#{Thegarage::Gitx::BASE_BRANCH} ", :green
|
37
|
+
shell.say "in "
|
38
|
+
shell.say remote, :green
|
39
|
+
|
40
|
+
payload = {
|
41
|
+
:title => branch,
|
42
|
+
:base => Thegarage::Gitx::BASE_BRANCH,
|
43
|
+
:head => branch,
|
44
|
+
:body => body
|
45
|
+
}.to_json
|
46
|
+
response = RestClient::Request.new(:url => "https://api.github.com/repos/#{remote}/pulls", :method => "POST", :payload => payload, :headers => request_headers).execute
|
47
|
+
data = JSON.parse response.body
|
48
|
+
|
49
|
+
assign_pull_request(branch, options[:assignee], data) if options[:assignee]
|
50
|
+
|
51
|
+
url = data['html_url']
|
52
|
+
url
|
53
|
+
rescue RestClient::Exception => e
|
54
|
+
process_error e
|
55
|
+
throw e
|
56
|
+
end
|
11
57
|
|
12
58
|
private
|
59
|
+
|
13
60
|
# request github authorization token
|
14
61
|
# User-Agent is required
|
15
62
|
# store the token in local git config
|
63
|
+
# @returns [String] auth token stored in git (current repo, user config or installed global settings)
|
16
64
|
# @see http://developer.github.com/v3/oauth/#scopes
|
17
65
|
# @see http://developer.github.com/v3/#user-agent-required
|
18
66
|
def authorization_token
|
19
|
-
auth_token =
|
67
|
+
auth_token = repo.config['thegarage.gitx.githubauthtoken']
|
20
68
|
return auth_token unless auth_token.to_s.blank?
|
21
69
|
|
22
|
-
|
23
|
-
password = ask("Github password for #{
|
70
|
+
fail "Github user not configured. Run: `git config --global github.user 'me@email.com'`" unless username
|
71
|
+
password = shell.ask("Github password for #{username}: ", :echo => false)
|
24
72
|
|
25
73
|
payload = {
|
26
74
|
:scopes => ['repo'],
|
@@ -30,7 +78,7 @@ module Thegarage
|
|
30
78
|
response = RestClient::Request.new({
|
31
79
|
:url => "https://api.github.com/authorizations",
|
32
80
|
:method => "POST",
|
33
|
-
:user =>
|
81
|
+
:user => username,
|
34
82
|
:password => password,
|
35
83
|
:payload => payload,
|
36
84
|
:headers => {
|
@@ -41,58 +89,79 @@ module Thegarage
|
|
41
89
|
}).execute
|
42
90
|
data = JSON.parse response.body
|
43
91
|
token = data['token']
|
44
|
-
|
92
|
+
repo.config['thegarage.gitx.githubauthtoken'] = token
|
45
93
|
token
|
46
94
|
rescue RestClient::Exception => e
|
47
95
|
process_error e
|
48
96
|
throw e
|
49
97
|
end
|
50
98
|
|
51
|
-
# returns the url of the created pull request
|
52
|
-
# @see http://developer.github.com/v3/pulls/
|
53
|
-
def create_pull_request(body, assignee = nil)
|
54
|
-
branch = current_branch
|
55
|
-
repo = current_remote_repo
|
56
|
-
|
57
|
-
say "Creating pull request for "
|
58
|
-
say "#{branch} ", :green
|
59
|
-
say "against "
|
60
|
-
say "#{Thegarage::Gitx::BASE_BRANCH} ", :green
|
61
|
-
say "in "
|
62
|
-
say repo, :green
|
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
|
66
|
-
data = JSON.parse response.body
|
67
|
-
|
68
|
-
assign_pull_request(branch, assignee, data) if assignee
|
69
|
-
|
70
|
-
url = data['html_url']
|
71
|
-
url
|
72
|
-
rescue RestClient::Exception => e
|
73
|
-
process_error e
|
74
|
-
throw e
|
75
|
-
end
|
76
|
-
|
77
99
|
def assign_pull_request(branch, assignee, data)
|
78
100
|
issue_payload = { :title => branch, :assignee => assignee }.to_json
|
79
|
-
RestClient::Request.new(:url => data['issue_url'], :method => "PATCH", :payload => issue_payload, :headers =>
|
101
|
+
RestClient::Request.new(:url => data['issue_url'], :method => "PATCH", :payload => issue_payload, :headers => request_headers).execute
|
80
102
|
rescue RestClient::Exception => e
|
81
103
|
process_error e
|
82
104
|
end
|
83
105
|
|
84
106
|
def process_error(e)
|
85
107
|
data = JSON.parse e.http_body
|
86
|
-
say "Github request failed: #{data['message']}", :red
|
108
|
+
shell.say "Github request failed: #{data['message']}", :red
|
87
109
|
end
|
88
110
|
|
89
|
-
def
|
111
|
+
def request_headers
|
90
112
|
{
|
91
113
|
:accept => :json,
|
92
114
|
:content_type => :json,
|
93
115
|
'Authorization' => "token #{authorization_token}"
|
94
116
|
}
|
95
117
|
end
|
118
|
+
|
119
|
+
# @returns [String] github username (ex: 'wireframe') of the current github.user
|
120
|
+
# @returns empty [String] when no github.user is set on the system
|
121
|
+
def username
|
122
|
+
repo.config['github.user']
|
123
|
+
end
|
124
|
+
|
125
|
+
# lookup the current repository of the PWD
|
126
|
+
# ex: git@github.com:socialcast/thegarage/gitx.git OR https://github.com/socialcast/thegarage/gitx.git
|
127
|
+
def remote_origin_name
|
128
|
+
remote = repo.config['remote.origin.url']
|
129
|
+
remote.to_s.gsub(/\.git$/,'').split(/[:\/]/).last(2).join('/')
|
130
|
+
end
|
131
|
+
|
132
|
+
def pull_request_body(changelog, description = nil)
|
133
|
+
description_template = []
|
134
|
+
description_template << description if description
|
135
|
+
description_template << "\n"
|
136
|
+
description_template << '### Changelog'
|
137
|
+
description_template << changelog
|
138
|
+
description_template << PULL_REQUEST_FOOTER
|
139
|
+
|
140
|
+
body = input_from_editor(description_template.join("\n"))
|
141
|
+
body.gsub(PULL_REQUEST_FOOTER, '').chomp.strip
|
142
|
+
end
|
143
|
+
|
144
|
+
# launch configured editor to retreive message/string
|
145
|
+
def input_from_editor(initial_text = '')
|
146
|
+
Tempfile.open('reviewrequest.md') do |f|
|
147
|
+
f << initial_text
|
148
|
+
f.flush
|
149
|
+
|
150
|
+
editor = repo.config['core.editor'] || ENV['EDITOR'] || 'vi'
|
151
|
+
flags = case editor
|
152
|
+
when 'mate', 'emacs', 'subl'
|
153
|
+
'-w'
|
154
|
+
when 'mvim'
|
155
|
+
'-f'
|
156
|
+
else
|
157
|
+
''
|
158
|
+
end
|
159
|
+
pid = fork { exec([editor, flags, f.path].join(' ')) }
|
160
|
+
Process.waitpid(pid)
|
161
|
+
contents = File.read(f.path)
|
162
|
+
contents.chomp.strip
|
163
|
+
end
|
164
|
+
end
|
96
165
|
end
|
97
166
|
end
|
98
167
|
end
|
@@ -275,68 +275,12 @@ describe Thegarage::Gitx::CLI do
|
|
275
275
|
end
|
276
276
|
|
277
277
|
describe '#reviewrequest' do
|
278
|
-
context 'when github
|
279
|
-
let(:
|
280
|
-
it 'raises error' do
|
281
|
-
allow(cli).to receive(:current_user).and_return(current_user)
|
282
|
-
|
283
|
-
expect do
|
284
|
-
cli.reviewrequest
|
285
|
-
end.to raise_error /Github user not configured/
|
286
|
-
end
|
287
|
-
end
|
288
|
-
context 'when authorization_token is nil' do
|
289
|
-
let(:options) { {description: 'testing'} }
|
290
|
-
let(:current_user) { 'ryan@codecrate.com' }
|
291
|
-
let(:github_password) { 'secretz' }
|
292
|
-
let(:authorization_token) { 'auth_token' }
|
293
|
-
let(:expected_auth_body) do
|
294
|
-
JSON.dump({
|
295
|
-
scopes: ["repo"],
|
296
|
-
note: "The Garage Git eXtensions",
|
297
|
-
note_url: "https://github.com/thegarage/thegarage-gitx"
|
298
|
-
})
|
299
|
-
end
|
300
|
-
before do
|
301
|
-
stub_request(:post, "https://#{current_user}:#{github_password}@api.github.com/authorizations").
|
302
|
-
with(:body => expected_auth_body).
|
303
|
-
to_return(:status => 200, :body => JSON.dump(token: authorization_token), :headers => {})
|
304
|
-
|
305
|
-
stub_request(:post, "https://api.github.com/repos/thegarage/thegarage-gitx/pulls").
|
306
|
-
to_return(:status => 200, :body => %q({"html_url": "http://github.com/repo/project/pulls/1"}), :headers => {})
|
307
|
-
|
308
|
-
allow(cli).to receive(:current_user).and_return(current_user)
|
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)
|
311
|
-
|
312
|
-
expect(cli).to receive(:editor_input).and_return('scrubbed text')
|
313
|
-
expect(cli).to receive(:run).with("git pull origin feature-branch", capture: true).ordered
|
314
|
-
expect(cli).to receive(:run).with("git pull origin master", capture: true).ordered
|
315
|
-
expect(cli).to receive(:run).with("git push origin HEAD", capture: true).ordered
|
316
|
-
expect(cli).to receive(:run).with("git log master...feature-branch --no-merges --pretty=format:'* %s%n%b'", capture: true).and_return("2013-01-01 did some stuff").ordered
|
317
|
-
|
318
|
-
cli.reviewrequest
|
319
|
-
end
|
320
|
-
it 'creates authorization_token' do
|
321
|
-
should meet_expectations
|
322
|
-
end
|
323
|
-
it 'should create github pull request' do
|
324
|
-
should meet_expectations
|
325
|
-
end
|
326
|
-
it 'should run expected commands' do
|
327
|
-
should meet_expectations
|
328
|
-
end
|
329
|
-
end
|
330
|
-
context 'when description != null and there is an existing authorization_token' do
|
331
|
-
let(:options) { {description: 'testing'} }
|
332
|
-
let(:authorization_token) { '123981239123' }
|
278
|
+
context 'when github configured correctly' do
|
279
|
+
let(:github) { double('fake github') }
|
333
280
|
before do
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
allow(cli).to receive(:authorization_token).and_return(authorization_token)
|
281
|
+
expect(cli).to receive(:github).and_return(github)
|
282
|
+
expect(github).to receive(:create_pull_request).and_return('https://path/to/new/pull/request')
|
338
283
|
|
339
|
-
expect(cli).to receive(:editor_input).and_return('scrubbed text')
|
340
284
|
expect(cli).to receive(:run).with("git pull origin feature-branch", capture: true).ordered
|
341
285
|
expect(cli).to receive(:run).with("git pull origin master", capture: true).ordered
|
342
286
|
expect(cli).to receive(:run).with("git push origin HEAD", capture: true).ordered
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Thegarage::Gitx::Github do
|
4
|
+
let(:repo) { double('fake shell', config: repo_config) }
|
5
|
+
let(:repo_config) do
|
6
|
+
{
|
7
|
+
'remote.origin.url' => 'https://github.com/thegarage/thegarage-gitx'
|
8
|
+
}
|
9
|
+
end
|
10
|
+
let(:shell) { double('fake shell', say: nil, ask: nil) }
|
11
|
+
subject { Thegarage::Gitx::Github.new(repo, shell) }
|
12
|
+
|
13
|
+
describe '#create_pull_request' do
|
14
|
+
context 'when github.user is not configured' do
|
15
|
+
it 'raises error' do
|
16
|
+
expect do
|
17
|
+
subject.create_pull_request 'example-branch', 'changelog'
|
18
|
+
end.to raise_error /Github user not configured/
|
19
|
+
end
|
20
|
+
end
|
21
|
+
context 'when config.authorization_token is nil' do
|
22
|
+
let(:repo_config) do
|
23
|
+
{
|
24
|
+
'remote.origin.url' => 'https://github.com/thegarage/thegarage-gitx',
|
25
|
+
'github.user' => 'ryan@codecrate.com'
|
26
|
+
}
|
27
|
+
end
|
28
|
+
let(:github_password) { 'secretz' }
|
29
|
+
let(:authorization_token) { '123981239123' }
|
30
|
+
let(:expected_auth_body) do
|
31
|
+
JSON.dump({
|
32
|
+
scopes: ["repo"],
|
33
|
+
note: "The Garage Git eXtensions",
|
34
|
+
note_url: "https://github.com/thegarage/thegarage-gitx"
|
35
|
+
})
|
36
|
+
end
|
37
|
+
before do
|
38
|
+
stub_request(:post, "https://ryan@codecrate.com:secretz@api.github.com/authorizations").
|
39
|
+
with(:body => expected_auth_body).
|
40
|
+
to_return(:status => 200, :body => JSON.dump(token: authorization_token), :headers => {})
|
41
|
+
|
42
|
+
stub_request(:post, "https://api.github.com/repos/thegarage/thegarage-gitx/pulls").
|
43
|
+
to_return(:status => 200, :body => %q({"html_url": "http://github.com/repo/project/pulls/1"}), :headers => {})
|
44
|
+
|
45
|
+
expect(shell).to receive(:ask).with('Github password for ryan@codecrate.com: ', {:echo => false}).and_return(github_password).any_number_of_times
|
46
|
+
|
47
|
+
expect(subject).to receive(:input_from_editor).and_return('scrubbed text')
|
48
|
+
subject.create_pull_request 'example-branch', 'changelog'
|
49
|
+
end
|
50
|
+
it 'creates authorization_token' do
|
51
|
+
expect(repo_config).to include('thegarage.gitx.githubauthtoken' => authorization_token)
|
52
|
+
end
|
53
|
+
it 'should create github pull request' do
|
54
|
+
should meet_expectations
|
55
|
+
end
|
56
|
+
it 'should run expected commands' do
|
57
|
+
should meet_expectations
|
58
|
+
end
|
59
|
+
end
|
60
|
+
context 'when there is an existing authorization_token' do
|
61
|
+
let(:authorization_token) { '123981239123' }
|
62
|
+
let(:repo_config) do
|
63
|
+
{
|
64
|
+
'remote.origin.url' => 'https://github.com/thegarage/thegarage-gitx',
|
65
|
+
'github.user' => 'ryan@codecrate.com',
|
66
|
+
'thegarage.gitx.githubauthtoken' => authorization_token
|
67
|
+
}
|
68
|
+
end
|
69
|
+
before do
|
70
|
+
stub_request(:post, "https://api.github.com/repos/thegarage/thegarage-gitx/pulls").
|
71
|
+
to_return(:status => 200, :body => %q({"html_url": "http://github.com/repo/project/pulls/1"}), :headers => {})
|
72
|
+
|
73
|
+
expect(subject).to receive(:input_from_editor).and_return('scrubbed text')
|
74
|
+
subject.create_pull_request 'example-branch', 'changelog'
|
75
|
+
end
|
76
|
+
it 'should create github pull request' do
|
77
|
+
should meet_expectations
|
78
|
+
end
|
79
|
+
it 'should run expected commands' do
|
80
|
+
should meet_expectations
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
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.
|
4
|
+
version: 1.4.1
|
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-03-
|
11
|
+
date: 2014-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grit
|
@@ -183,6 +183,7 @@ files:
|
|
183
183
|
- spec/spec_helper.rb
|
184
184
|
- spec/support/meet_expectations_matcher.rb
|
185
185
|
- spec/thegarage/gitx/cli_spec.rb
|
186
|
+
- spec/thegarage/gitx/github_spec.rb
|
186
187
|
- thegarage-gitx.gemspec
|
187
188
|
homepage: ''
|
188
189
|
licenses:
|
@@ -212,3 +213,4 @@ test_files:
|
|
212
213
|
- spec/spec_helper.rb
|
213
214
|
- spec/support/meet_expectations_matcher.rb
|
214
215
|
- spec/thegarage/gitx/cli_spec.rb
|
216
|
+
- spec/thegarage/gitx/github_spec.rb
|