class Fastlane::Actions::AddFixVersionAction

Public Class Methods

authors() click to toggle source
# File lib/fastlane/plugin/add_fix_version/actions/add_fix_version_action.rb, line 94
def self.authors
  ["Dmitry Krasulia"]
end
available_options() click to toggle source
# File lib/fastlane/plugin/add_fix_version/actions/add_fix_version_action.rb, line 107
def self.available_options
  [
      FastlaneCore::ConfigItem.new(key: :url,
                                   description: "URL for JIRA instance",
                                   verify_block: proc do |value|
                                     UI.user_error!("No url for JIRA given, pass using `url: 'url'`") if value.to_s.length == 0
                                   end),
      FastlaneCore::ConfigItem.new(key: :username,
                                   optional: true,
                                   description: "Username for JIRA"),
      FastlaneCore::ConfigItem.new(key: :password,
                                   description: "Password for JIRA",
                                   optional: true,
                                   sensitive: true),
      FastlaneCore::ConfigItem.new(key: :auth_type,
                                   description: "Authorization type to use. Currently supported: :basic or :cookie",
                                   default_value: :basic),
      FastlaneCore::ConfigItem.new(key: :issue_ids,
                                   description: "Issue IDs or keys for JIRA, i.e. [\"IOS-123\", \"IOS-123\"]",
                                   optional: true,
                                   is_string: false),
      FastlaneCore::ConfigItem.new(key: :version_name,
                                   description: "Version name that will be set as fix version to specified issues.\nIf version does not exist, it will be created",
                                   is_string: true,
                                   optional: true),
      FastlaneCore::ConfigItem.new(key: :project_key,
                                   description: "Project ID or key where version will be created if needed",
                                   is_string: true,
                                   optional: true)

  ]
end
description() click to toggle source
# File lib/fastlane/plugin/add_fix_version/actions/add_fix_version_action.rb, line 90
def self.description
  "Create and mark tickets with fix version"
end
details() click to toggle source
# File lib/fastlane/plugin/add_fix_version/actions/add_fix_version_action.rb, line 102
def self.details
  # Optional:
  "Use only basic auth_type"
end
is_supported?(platform) click to toggle source
# File lib/fastlane/plugin/add_fix_version/actions/add_fix_version_action.rb, line 140
def self.is_supported?(platform)
  # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
  # See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform
  #
  # [:ios, :mac, :android].include?(platform)
  true
end
issue_ids_from_param(params) click to toggle source
# File lib/fastlane/plugin/add_fix_version/actions/add_fix_version_action.rb, line 33
def self.issue_ids_from_param(params)
  issue_ids = params[:issue_ids]

  if issue_ids.nil?
    issue_ids = Actions.lane_context[SharedValues::FL_JIRA_ISSUE_IDS]
  end

  if issue_ids.kind_of?(Array) == false || issue_ids.empty?
    UI.user_error!("No issue ids or keys were supplied or the value is not an array.")
    return
  end

  UI.message("Issues: #{issue_ids}")
  return issue_ids
end
return_value() click to toggle source
# File lib/fastlane/plugin/add_fix_version/actions/add_fix_version_action.rb, line 98
def self.return_value
  # If your method provides a return value, you can describe here what it does
end
run(params) click to toggle source
# File lib/fastlane/plugin/add_fix_version/actions/add_fix_version_action.rb, line 7
def self.run(params)
  
  Actions.verify_gem!('jira-ruby')
  require 'jira-ruby'
  
  site         = params[:url]
  project_id   = params[:project_key]
  version_name = params[:version_name]
  username =  params[:username]
  auth_type = params[:auth_type]
  password = params[:password]

  options = {
    site: site,
    auth_type: auth_type,
    username: username,
    password: password
  }

  client = JIRA::Client.new(options)

  issues = self.issue_ids_from_param(params)

  self.save_version(client, version_name, project_id, issues)
end
save_version(client, version_name, project_key, issue_ids) click to toggle source
# File lib/fastlane/plugin/add_fix_version/actions/add_fix_version_action.rb, line 49
def self.save_version(client, version_name, project_key, issue_ids)
  # create new version if needed
  begin
    project = client.Project.find(project_key)
  rescue => error
    UI.error("JIRA API call failed. Check if JIRA is available and correct credentials for user with proper permissions are provided!")
    UI.user_error!(error.response)
    return
  end

  is_version_created = false
  project.versions.each do |version|
    if version.name == version_name
      is_version_created = true
      break
    end
  end

  # if the version does not exist then create this JIRA version
  if is_version_created == false
    version = project.versions.build
    create_version_parameters = { "name" => version_name, "projectId" => project.id }
    version.save(create_version_parameters)
    UI.message("#{version_name} version is created.")
  else
    UI.message("#{version_name} version already exists and will be used as a fix version.")
  end

  # update issues with fix version
  issue_ids.each do |issue_id|
    begin
      issue = client.Issue.find(issue_id)
    rescue
      UI.error("JIRA issue with #{issue_id} is not found or specified user don't have permissions to see it. It won't be updated!")
    end
    add_new_version_parameters = { 'update' => { 'fixVersions' => [{ 'add' => { 'name' => version_name } }] } }
    issue.save(add_new_version_parameters)
    UI.message("#{issue_id} is updated with fix version #{version_name}")
  end
end