Skip to content

Commit

Permalink
Merge pull request travis-ci#420 from HPI-BP2015H/launchpad
Browse files Browse the repository at this point in the history
Launchpad support
  • Loading branch information
BanzaiMan committed Apr 11, 2016
2 parents 426032a + 2441a25 commit f5a99db
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Dpl supports the following providers:
* [Hackage](#hackage)
* [Heroku](#heroku)
* [Lambda](#lambda)
* [Launchpad](#launchpad)
* [Modulus](#modulus)
* [Nodejitsu](#nodejitsu)
* [NPM](#npm)
Expand Down Expand Up @@ -710,6 +711,24 @@ Deploy contents of a specific directory using specific module name:
--handler_name="handler";
```

### Launchpad:

#### Options:

* **slug**: Required. `~user-name/project-name/branch-name`
* **oauth_token**: Required. Your OAUTH token for Launchpad
* **oauth_token_secret**: Required. Your OAUTH token secret for Launchpad

#### Example:

Deploy contents of current working directory using default module:
```
dpl --provider="launchpad" \
--slug="~user-name/project-name/branch-name" \
--oauth_token="${LAUNCHPAD_OAUTH_TOKEN}" \
--oauth_token_secret="${LAUNCHPAD_OAUTH_TOKEN_SECRET}";
```

### TestFairy:

Your Android(apk)/iOS(ipa) file will be uploaded to TestFairy,
Expand Down
1 change: 1 addition & 0 deletions lib/dpl/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class Provider
autoload :Hackage, 'dpl/provider/hackage'
autoload :Heroku, 'dpl/provider/heroku'
autoload :Lambda, 'dpl/provider/lambda'
autoload :Launchpad, 'dpl/provider/launchpad'
autoload :Modulus, 'dpl/provider/modulus'
autoload :Nodejitsu, 'dpl/provider/nodejitsu'
autoload :NPM, 'dpl/provider/npm'
Expand Down
48 changes: 48 additions & 0 deletions lib/dpl/provider/launchpad.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
require 'net/http'
require 'net/https'

module DPL
class Provider
class Launchpad < Provider

def initialize(context, options)
super
@http = Net::HTTP.new('api.launchpad.net', 443)
@http.use_ssl = true
end

def check_auth
end

def needs_key?
false
end

def push_app
response = api_call('/1.0/' + options[:slug] + '/+code-import', {'ws.op' => 'requestImport'})
error('Deploy failed! Launchpad credentials invalid. ' + response.code.to_s) if response.code == '401'
error('Error: ' + response.code.to_s + ' ' + response.body) unless response.kind_of? Net::HTTPSuccess
end

private

def api_call(path, data)
req = Net::HTTP::Post.new(path)
req.set_form_data(data)
req['Authorization'] = authorization
return @http.request(req)
end

def authorization
return 'OAuth oauth_consumer_key="Travis%20Deploy", ' +
'oauth_nonce="' + rand(36**32).to_s(36) + '",' +
'oauth_signature="%26' + options[:oauth_token_secret] + '",' +
'oauth_signature_method="PLAINTEXT",' +
'oauth_timestamp="' + Time::now().to_i.to_s + '",' +
'oauth_token="' + options[:oauth_token] + '",' +
'oauth_version="1.0"'
end

end
end
end
33 changes: 33 additions & 0 deletions spec/provider/launchpad_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require 'spec_helper'
require 'dpl/provider/cloudcontrol'

describe DPL::Provider::Launchpad do
subject :provider do
described_class.new(DummyContext.new, :slug => '~user/repo/branch', :oauth_token => 'uezinoosinmxkewhochq', :oauth_token_secret => 'dinb6fao4jh0kfdn5mich31cbikdkpjplkmadhi80h93kbbaableeeg41mm0jab9jif8ch7i2k9a80n5')
end

its(:needs_key?) { should be false }

describe '#push_app' do
it 'on api success' do
expect(provider).to receive(:api_call).with('/1.0/~user/repo/branch/+code-import', {'ws.op' => 'requestImport'}).and_return Net::HTTPSuccess.new("HTTP/1.1", 200, "Ok")
provider.push_app
end

it 'on api failure' do
expect(provider).to receive(:api_call).with('/1.0/~user/repo/branch/+code-import', {'ws.op' => 'requestImport'}).and_return double("Net::HTTPUnauthorized", code: 401, body: "", class: Net::HTTPUnauthorized)
expect { provider.push_app }.to raise_error(DPL::Error)
end
end

describe 'private method' do
describe '#authorization' do
it 'should return correct oauth' do
result = provider.instance_eval { authorization }
expect(result).to include('oauth_token="uezinoosinmxkewhochq",')
expect(result).to include('oauth_signature="%26dinb6fao4jh0kfdn5mich31cbikdkpjplkmadhi80h93kbbaableeeg41mm0jab9jif8ch7i2k9a80n5",')
end
end
end

end

0 comments on commit f5a99db

Please sign in to comment.