Skip to content

Commit

Permalink
Merge branch 'master' of github.com:thegarage/thegarage-gitx into rug…
Browse files Browse the repository at this point in the history
…ged-upgrade

Conflicts:
	spec/spec_helper.rb
	thegarage-gitx.gemspec
  • Loading branch information
vandahm committed Jul 10, 2014
2 parents d31a277 + 8718071 commit 722a14a
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 45 deletions.
30 changes: 11 additions & 19 deletions lib/thegarage/gitx/cli/review_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require 'thegarage/gitx/cli/update_command'
require 'json'
require 'rest_client'
require 'octokit'

module Thegarage
module Gitx
Expand Down Expand Up @@ -56,31 +57,22 @@ def authorization_token

fail "Github user not configured. Run: `git config --global github.user 'me@email.com'`" unless username
password = ask("Github password for #{username}: ", :echo => false)
say ''
two_factor_auth_token = ask("Github two factor authorization token (if enabled): ", :echo => false)

client_name = "The Garage Git eXtensions - #{remote_origin_name}"
payload = {
timestamp = Time.now.utc.strftime('%Y-%m-%dT%H:%M:%S%z')
client_name = "The Garage Git eXtensions - #{remote_origin_name} #{timestamp}"
options = {
:scopes => ['repo'],
:note => client_name,
:note_url => CLIENT_URL
}.to_json
response = RestClient::Request.new({
:url => "https://api.github.com/authorizations",
:method => "POST",
:user => username,
:password => password,
:payload => payload,
:headers => {
:accept => :json,
:content_type => :json,
:user_agent => 'thegarage/gitx'
}
}).execute
data = JSON.parse response.body
token = data['token']
}
options[:headers] = {'X-GitHub-OTP' => two_factor_auth_token} if two_factor_auth_token
client = Octokit::Client.new(login: username, password: password)
response = client.create_authorization(options)
token = response.token
repo.config['thegarage.gitx.githubauthtoken'] = token
token
rescue RestClient::Exception => e
process_error e
end

# @see http://developer.github.com/v3/pulls/
Expand Down
2 changes: 1 addition & 1 deletion lib/thegarage/gitx/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Thegarage
module Gitx
VERSION = '2.2.0'
VERSION = '2.2.1'
end
end
15 changes: 0 additions & 15 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,6 @@
# in spec/support/ and its subdirectories.
Dir[File.join(__dir__, "support/**/*.rb")].each { |f| require f }

RSpec.configure do |config|
config.run_all_when_everything_filtered = true
config.filter_run :focus

# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = 'random'
end

# This file was generated by the `rspec --init` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# The generated `.rspec` file contains `--require spec_helper` which will cause this
Expand All @@ -35,9 +24,6 @@
#
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |config|
# The settings below are suggested to provide a good initial experience
# with RSpec, but feel free to customize to your heart's content.
=begin
# These two settings work together to allow you to limit a spec run
# to individual examples or groups you care about by tagging them with
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
Expand Down Expand Up @@ -94,5 +80,4 @@
# a real object. This is generally recommended.
mocks.verify_partial_doubles = true
end
=end
end
36 changes: 27 additions & 9 deletions spec/thegarage/gitx/cli/review_command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,12 @@
end
let(:github_password) { 'secretz' }
let(:authorization_token) { '123981239123' }
let(:expected_auth_body) do
JSON.dump({
scopes: ["repo"],
note: "The Garage Git eXtensions - thegarage/thegarage-gitx",
note_url: "https://github.com/thegarage/thegarage-gitx"
})
end
before do
stub_request(:post, "https://ryan@codecrate.com:secretz@api.github.com/authorizations").
with(:body => expected_auth_body).
to_return(:status => 200, :body => JSON.dump(token: authorization_token), :headers => {})
to_return(:status => 200, :body => JSON.dump(token: authorization_token), :headers => {'Content-Type' => 'application/json'})

expect(cli).to receive(:ask).with('Github password for ryan@codecrate.com: ', {:echo => false}).and_return(github_password)
expect(cli).to receive(:ask).with('Github two factor authorization token (if enabled): ', {:echo => false}).and_return(nil)

@auth_token = cli.send(:authorization_token)
end
Expand All @@ -165,6 +158,31 @@
end
it { expect(@auth_token).to eq authorization_token }
end
context 'when two factor authorization token given' do
let(:repo_config) do
{
'remote.origin.url' => 'https://github.com/thegarage/thegarage-gitx',
'github.user' => 'ryan@codecrate.com'
}
end
let(:github_password) { 'secretz' }
let(:authorization_token) { '123981239123' }
let(:two_factor_auth_token) { '456456' }
before do
stub_request(:post, "https://ryan@codecrate.com:secretz@api.github.com/authorizations").
with(headers: {'X-GitHub-OTP' => two_factor_auth_token}).
to_return(:status => 200, :body => JSON.dump(token: authorization_token), :headers => {'Content-Type' => 'application/json'})

expect(cli).to receive(:ask).with('Github password for ryan@codecrate.com: ', {:echo => false}).and_return(github_password)
expect(cli).to receive(:ask).with('Github two factor authorization token (if enabled): ', {:echo => false}).and_return(two_factor_auth_token)

@auth_token = cli.send(:authorization_token)
end
it 'stores authorization_token in git config' do
expect(repo_config).to include('thegarage.gitx.githubauthtoken' => authorization_token)
end
it { expect(@auth_token).to eq authorization_token }
end
end
describe '#create_pull_request' do
context 'when there is an existing authorization_token' do
Expand Down
3 changes: 2 additions & 1 deletion thegarage-gitx.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]

spec.add_runtime_dependency "rugged", '~> 0.21.0'
spec.add_runtime_dependency "rest-client", ">= 1.4.0"
spec.add_runtime_dependency "thor"
spec.add_runtime_dependency "rest-client", ">= 1.4.0"
spec.add_runtime_dependency "octokit"

spec.add_development_dependency "bundler", "~> 1.3"
spec.add_development_dependency "rake"
Expand Down

0 comments on commit 722a14a

Please sign in to comment.