Merge pull request #62 from evkhramkov/feature/auto-create-app-parameters

Allow specifying app os, platform and display name for automated creation
This commit is contained in:
Evgeniy Khramkov 2019-06-10 11:28:46 -07:00 коммит произвёл GitHub
Родитель 2a3f243d9a e78680bb06
Коммит 8a1d35de52
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 86 добавлений и 16 удалений

Просмотреть файл

@ -16,6 +16,19 @@ lane :test_autocreation do
)
end
lane :test_autocreation_without_prompts do
# app should be autocreated if not found, without asking user
appcenter_upload(
api_token: ENV["TEST_APPCENTER_API_TOKEN"],
owner_name: ENV["TEST_APPCENTER_OWNER_NAME"],
app_name: "my-new-app-center-app",
app_display_name: "My New App Center App",
app_os: "Android",
app_platform: "Java",
apk: "./fastlane/app-release.apk"
)
end
lane :test_release_notes do
appcenter_upload(
api_token: ENV["TEST_APPCENTER_API_TOKEN"],

Просмотреть файл

@ -161,6 +161,9 @@ module Fastlane
api_token = params[:api_token]
owner_name = params[:owner_name]
app_name = params[:app_name]
app_display_name = params[:app_display_name]
app_os = params[:app_os]
app_platform = params[:app_platform]
platforms = {
"Android" => ['Java', 'React-Native', 'Xamarin'],
@ -168,17 +171,24 @@ module Fastlane
}
if Helper::AppcenterHelper.get_app(api_token, owner_name, app_name)
true
else
if Helper.test? || UI.confirm("App with name #{app_name} not found, create one?")
os = Helper.test? ? "Android" : UI.select("Select OS", ["Android", "iOS"])
platform = Helper.test? ? "Java" : UI.select("Select Platform", platforms[os])
return true
end
Helper::AppcenterHelper.create_app(api_token, owner_name, app_name, os, platform)
else
UI.error("Lane aborted")
false
end
should_create_app = !app_display_name.to_s.empty? || !app_os.to_s.empty? || !app_platform.to_s.empty?
if Helper.test? || should_create_app || UI.confirm("App with name #{app_name} not found, create one?")
app_display_name = app_name if app_display_name.to_s.empty?
os = app_os.to_s.empty? ?
(Helper.test? ? "Android" : UI.select("Select OS", ["Android", "iOS"])) :
app_os
platform = app_platform.to_s.empty? ?
(Helper.test? ? "Java" : UI.select("Select Platform", platforms[os])) :
app_platform
Helper::AppcenterHelper.create_app(api_token, owner_name, app_name, app_display_name, os, platform)
else
UI.error("Lane aborted")
false
end
end
@ -238,6 +248,24 @@ module Fastlane
UI.user_error!("No App name given, pass using `app_name: 'app name'`") unless value && !value.empty?
end),
FastlaneCore::ConfigItem.new(key: :app_display_name,
env_name: "APPCENTER_APP_DISPLAY_NAME",
description: "App display name to use when creating a new app",
optional: true,
type: String),
FastlaneCore::ConfigItem.new(key: :app_os,
env_name: "APPCENTER_APP_OS",
description: "App OS. Used for new app creation, if app with 'app_name' name was not found",
optional: true,
type: String),
FastlaneCore::ConfigItem.new(key: :app_platform,
env_name: "APPCENTER_APP_PLATFORM",
description: "App Platform. Used for new app creation, if app with 'app_name' name was not found",
optional: true,
type: String),
FastlaneCore::ConfigItem.new(key: :apk,
env_name: "APPCENTER_DISTRIBUTE_APK",
description: "Build release path for android build",

Просмотреть файл

@ -370,13 +370,13 @@ module Fastlane
UI.message("DEBUG: #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
false
else
UI.error("Error #{response.status}: #{response.body}")
UI.error("Error getting app #{owner}/#{app_name}, #{response.status}: #{response.body}")
false
end
end
# returns true if app exists, false in case of 404 and error otherwise
def self.create_app(api_token, owner_name, app_name, os, platform)
def self.create_app(api_token, owner_name, app_name, app_display_name, os, platform)
connection = self.connection
response = connection.post do |req|
@ -384,7 +384,7 @@ module Fastlane
req.headers['X-API-Token'] = api_token
req.headers['internal-request-source'] = "fastlane"
req.body = {
"display_name" => app_name,
"display_name" => app_display_name,
"name" => app_name,
"os" => os,
"platform" => platform
@ -395,7 +395,7 @@ module Fastlane
when 200...300
created = response.body
UI.message("DEBUG: #{JSON.pretty_generate(created)}") if ENV['DEBUG']
UI.success("Created #{os}/#{platform} app with name \"#{created['name']}\"")
UI.success("Created #{os}/#{platform} app with name \"#{created['name']}\" and display name \"#{created['display_name']}\"")
true
else
UI.error("Error creating app #{response.status}: #{response.body}")

Просмотреть файл

@ -6,8 +6,11 @@ def stub_check_app(status)
)
end
def stub_create_app(status)
def stub_create_app(status, app_name = "app", app_display_name = "app", app_os = "Android", app_platform = "Java")
stub_request(:post, "https://api.appcenter.ms/v0.1/apps")
.with(
body: "{\"display_name\":\"#{app_display_name}\",\"name\":\"#{app_name}\",\"os\":\"#{app_os}\",\"platform\":\"#{app_platform}\"}",
)
.to_return(
status: status,
body: "{\"name\":\"app\"}",
@ -703,7 +706,7 @@ describe Fastlane::Actions::AppcenterUploadAction do
it "creates app if it was not found" do
stub_check_app(404)
stub_create_app(200)
stub_create_app(200, "app", "app", "Android", "Java")
stub_create_release_upload(200)
stub_upload_build(200)
stub_update_release_upload(200, 'committed')
@ -724,6 +727,32 @@ describe Fastlane::Actions::AppcenterUploadAction do
end").runner.execute(:test)
end
it "creates app if it was not found with specified os, platform and display_name" do
stub_check_app(404)
stub_create_app(200, "app", "App Name", "Android", "Java")
stub_create_release_upload(200)
stub_upload_build(200)
stub_update_release_upload(200, 'committed')
stub_update_release(200)
stub_get_destination(200)
stub_add_to_destination(200)
stub_get_release(200)
Fastlane::FastFile.new.parse("lane :test do
appcenter_upload({
api_token: 'xxx',
owner_name: 'owner',
app_name: 'app',
app_display_name: 'App Name',
app_os: 'Android',
app_platform: 'Java',
apk: './spec/fixtures/appfiles/apk_file_empty.apk',
destinations: 'Testers',
destination_type: 'group'
})
end").runner.execute(:test)
end
it "handles app creation error" do
stub_check_app(404)
stub_create_app(500)