microsoft / fastlane-plugin-appcenter

App Center fastlane integration.
MIT License
508 stars 128 forks source link

Could not find option 'version' in the list of available options: api_token, owner_name, app_name #241

Closed asalom closed 2 years ago

asalom commented 4 years ago

Hello! I am currently trying to find the URL of a particular AppCenter build. For this I first upload the build with appcenter_upload and then run appcenter_fetch_version_number to obtain the ID number of the build so I can construct the URL from it. According to the readme appcenter_fetch_version_number accepts a parameter version (like appcenter_upload does). However when I try to execute I get an error.

This invocation:

appcenter_fetch_version_number(
    api_token: "XX",
    owner_name: "XX",
    app_name: "XX",
    version: "713"
  )

Throws the following error:

Could not find option 'version' in the list of available options: api_token, owner_name, app_name

fastlane-plugin-appcenter version is 1.9.0

yujincat commented 3 years ago

Hi :-) We could not find any issue in the invocation. Can you specify more details of the issue?

theleanship commented 3 years ago

Got the same issue

[!] Could not find option 'version' in the list of available options: api_token, owner_name, app_name

Not sure if you would expect it to show up as an optional var but it does not show as an option on the action

fastlane action appcenter_fetch_version_number
[✔] 🚀
+------------------------------------+---------+---------------------------------+
|                                  Used plugins                                  |
+------------------------------------+---------+---------------------------------+
| Plugin                             | Version | Action                          |
+------------------------------------+---------+---------------------------------+
| fastlane-plugin-appcenter          | 1.9.0   | appcenter_fetch_version_number  |
|                                    |         | appcenter_fetch_devices         |
|                                    |         | appcenter_upload                |
| fastlane-plugin-increment_version  | 0.0.10  | increment_version_name          |
| _name                              |         |                                 |
| fastlane-plugin-increment_version  | 0.4.3   | increment_version_code          |
| _code                              |         |                                 |
| fastlane-plugin-load_json          | 0.0.1   | load_json                       |
+------------------------------------+---------+---------------------------------+

Loading documentation for appcenter_fetch_version_number:

+-------------------------------------------------------------+
|               appcenter_fetch_version_number                |
+-------------------------------------------------------------+
| Fetches the latest version number of an app from App Center |
|                                                             |
| Created by jspargo, ShopKeep                                |
+-------------------------------------------------------------+

+------------+---------------------------+----------------------+---------+
|                 appcenter_fetch_version_number Options                  |
+------------+---------------------------+----------------------+---------+
| Key        | Description               | Env Var              | Default |
+------------+---------------------------+----------------------+---------+
| api_token  | API Token for App Center  | APPCENTER_API_TOKEN  |         |
|            | Access                    |                      |         |
| owner_name | Name of the owner of the  | APPCENTER_OWNER_NAME |         |
|            | application on App        |                      |         |
|            | Center                    |                      |         |
| app_name   | Name of the application   | APPCENTER_APP_NAME   |         |
|            | on App Center             |                      |         |
+------------+---------------------------+----------------------+---------+
* = default value is dependent on the user's system

More information can be found on https://docs.fastlane.tools/actions/appcenter_fetch_version_number
theleanship commented 3 years ago

Hey @yujincat, I looked into the contents of the gem locally and it seems out of date and lacking the version option

image

require 'json'
require 'net/http'
require 'fastlane_core/ui/ui'

module Fastlane
  UI = FastlaneCore::UI unless Fastlane.const_defined?("UI")

  module Actions
    class AppcenterFetchVersionNumberAction < Action
      def self.description
        "Fetches the latest version number of an app from App Center"
      end

      def self.authors
        ["jspargo", "ShopKeep"]
      end

      def self.run(params)
        api_token = params[:api_token]
        app_name = params[:app_name]
        owner_name = params[:owner_name]

        releases = Helper::AppcenterHelper.fetch_releases(
          api_token: api_token,
          owner_name: owner_name,
          app_name: app_name
        )

        UI.abort_with_message!("No versions found for '#{app_name}' owned by #{owner_name}") unless releases
        sorted_release = releases.sort_by { |release| release['id'] }.reverse!
        latest_release = sorted_release.first

        if latest_release.nil?
          UI.user_error!("This app has no releases yet")
          return nil
        end

        return {
          "id" => latest_release['id'],
          "version" => latest_release['short_version'],
          "build_number" => latest_release['version']
        }
      end

      def self.available_options
        [
          FastlaneCore::ConfigItem.new(key: :api_token,
                                       env_name: "APPCENTER_API_TOKEN",
                                       description: "API Token for App Center Access",
                                       verify_block: proc do |value|
                                         UI.user_error!("No API token for App Center given, pass using `api_token: 'token'`") unless value && !value.empty?
                                       end),
          FastlaneCore::ConfigItem.new(key: :owner_name,
                                       env_name: "APPCENTER_OWNER_NAME",
                                       description: "Name of the owner of the application on App Center",
                                       verify_block: proc do |value|
                                         UI.user_error!("No owner name for App Center given, pass using `owner_name: 'owner name'`") unless value && !value.empty?
                                       end),
          FastlaneCore::ConfigItem.new(key: :app_name,
                                       env_name: "APPCENTER_APP_NAME",
                                       description: "Name of the application on App Center",
                                       verify_block: proc do |value|
                                         UI.user_error!("No app name for App Center given, pass using `app_name: 'app name'`") unless value && !value.empty?
                                       end)
        ]
      end

      def self.is_supported?(platform)
        [:ios, :android].include?(platform)
      end

      def self.get_apps(api_token)
        host_uri = URI.parse('https://api.appcenter.ms')
        http = Net::HTTP.new(host_uri.host, host_uri.port)
        http.use_ssl = true
        apps_request = Net::HTTP::Get.new("/v0.1/apps")
        apps_request['X-API-Token'] = api_token
        apps_response = http.request(apps_request)
        return [] unless apps_response.kind_of?(Net::HTTPOK)
        return JSON.parse(apps_response.body)
      end
    end
  end
end
theleanship commented 3 years ago

This is working with the latest version now.

DmitriyKirakosyan commented 2 years ago

I'm closing this issue, but feel free to reopen if anyone still faces it.