Skip to content

Commit

Permalink
Merge pull request #46 from DeployGate/feature/v0.0.6
Browse files Browse the repository at this point in the history
v 0.0.6
  • Loading branch information
henteko committed Dec 7, 2015
2 parents 6b60b45 + 8202c1d commit 9de96ae
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 17 deletions.
5 changes: 3 additions & 2 deletions lib/deploygate/api/v1/push.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ class << self
# @param [String] target_user
# @param [String] token
# @param [String] message
# @param [String] distribution_key
# @param [Boolean] disable_notify
# @yield Upload process block
# @return [Hash]
def upload(file_path, target_user, token, message, disable_notify = false, &process_block)
def upload(file_path, target_user, token, message, distribution_key, disable_notify = false, &process_block)
res = nil
open(file_path) do |file|
res = Base.new(token).post(
sprintf(ENDPOINT, target_user),
{ :file => file , :message => message, :disable_notify => disable_notify ? 'yes' : 'no' }) { process_block.call unless process_block.nil? }
{ :file => file , :message => message, :distribution_key => distribution_key, :disable_notify => disable_notify ? 'yes' : 'no' }) { process_block.call unless process_block.nil? }
end

upload_results = {
Expand Down
1 change: 1 addition & 0 deletions lib/deploygate/command_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def run
c.description = 'upload to deploygate'
c.option '--message STRING', String, 'release message'
c.option '--user STRING', String, 'owner name or group name'
c.option '--distribution-key STRING', String, 'update distribution key'
c.option '--open', 'open browser (OSX only)'
c.option '--disable_notify', 'disable notify via email (iOS app only)'
c.action do |args, options|
Expand Down
13 changes: 7 additions & 6 deletions lib/deploygate/commands/deploy/push.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ def upload(args, options)
session = DeployGate::Session.new()
end

message = options.message
owner = options.user || session.name
open = options.open
disable_notify = options.disable_notify
file_path = args.first
message = options.message
owner = options.user || session.name
distribution_key = options.distribution_key
open = options.open
disable_notify = options.disable_notify
file_path = args.first

data = nil
print "Uploading to #{owner}.."
begin
data = DeployGate::Deploy.push(file_path, owner, message, disable_notify) {
data = DeployGate::Deploy.push(file_path, owner, message, distribution_key, disable_notify) {
print '.'
sleep 0.2
}
Expand Down
5 changes: 3 additions & 2 deletions lib/deploygate/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@ class << self
# @param [String] file_path
# @param [String] target_user
# @param [String] message
# @param [String] distribution_key
# @param [Boolean] disable_notify
# @yield Upload process block
# @return [Hash]
def push(file_path, target_user, message, disable_notify = false, &process_block)
def push(file_path, target_user, message, distribution_key, disable_notify = false, &process_block)
raise NotFileExistError, 'Target file is not found' if file_path.nil? || !File.exist?(file_path)

session = DeployGate::Session.new()
raise NotLoginError, 'Must login user' unless session.login?
token = session.token


data = API::V1::Push.upload(file_path, target_user, token, message, disable_notify) { process_block.call unless process_block.nil? }
data = API::V1::Push.upload(file_path, target_user, token, message, distribution_key || '', disable_notify) { process_block.call unless process_block.nil? }
raise UploadError, data[:message] if data[:error]

data
Expand Down
2 changes: 1 addition & 1 deletion lib/deploygate/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module DeployGate
VERSION = "0.0.5"
VERSION = "0.0.6"
end
4 changes: 2 additions & 2 deletions spec/deploygate/api/v1/push_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
to_return(:body => response.to_json)

call_process_block = false
results = DeployGate::API::V1::Push.upload(test_file_path, target_user, token, message)
results = DeployGate::API::V1::Push.upload(test_file_path, target_user, token, message, '')
expect(results).to eq ({
:error => response[:error],
:message => response[:because],
Expand All @@ -46,7 +46,7 @@
with(:headers => { 'AUTHORIZATION' => token }).
to_return(:body => response.to_json)

results = DeployGate::API::V1::Push.upload(test_file_path, target_user, token, message)
results = DeployGate::API::V1::Push.upload(test_file_path, target_user, token, message, '')
expect(results).to eq ({:error => response[:error], :message => response[:because]})
end
end
Expand Down
8 changes: 4 additions & 4 deletions spec/deploygate/deploy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
allow_any_instance_of(DeployGate::Session).to receive(:login?) { false }

expect {
DeployGate::Deploy.push(test_file_path, 'test', 'message')
DeployGate::Deploy.push(test_file_path, 'test', 'message', nil)
}.to raise_error DeployGate::Deploy::NotLoginError
end

it "NotFileExistError" do
expect {
DeployGate::Deploy.push('no_file_path', 'test', 'message')
DeployGate::Deploy.push('no_file_path', 'test', 'message', nil)
}.to raise_error DeployGate::Deploy::NotFileExistError
end

Expand All @@ -20,7 +20,7 @@
allow(DeployGate::API::V1::Push).to receive(:upload).and_return({:error => true, :message => 'error message'})

expect {
DeployGate::Deploy.push(test_file_path, 'test', 'message')
DeployGate::Deploy.push(test_file_path, 'test', 'message', nil)
}.to raise_error DeployGate::Deploy::UploadError
end
end
Expand All @@ -31,7 +31,7 @@
allow_any_instance_of(DeployGate::Session).to receive(:login?) { true }

expect {
DeployGate::Deploy.push(test_file_path, 'test', 'message')
DeployGate::Deploy.push(test_file_path, 'test', 'message', nil)
}.not_to raise_error
end
end
Expand Down

0 comments on commit 9de96ae

Please sign in to comment.