class Fastlane::Actions::JiraBuildNumberAction

Public Class Methods

authors() click to toggle source
# File lib/fastlane/plugin/jira_build_number/actions/jira_build_number_action.rb, line 155
def self.authors
  ["https://github.com/telrod"]
end
available_options() click to toggle source
# File lib/fastlane/plugin/jira_build_number/actions/jira_build_number_action.rb, line 81
def self.available_options
  # Define all options your action supports.

  # Below a few examples
  [
      FastlaneCore::ConfigItem.new(key: :jira_username,
                                   env_name: "FL_JIRA_BUILD_NUMBER_JIRA_USERNAME", # The name of the environment variable
                                   description: "Jira username for JiraBuildNumberAction", # a short description of this parameter
                                   verify_block: proc do |value|
                                     UI.user_error!("No jira username for JiraBuildNumberAction given, pass using `build_number: 'build'`") unless (value and not value.empty?)
                                     # UI.user_error!("Couldn't find file at path '#{value}'") unless File.exist?(value)
                                   end),
      FastlaneCore::ConfigItem.new(key: :jira_password,
                                   env_name: "FL_JIRA_BUILD_NUMBER_JIRA_PASSWORD", # The name of the environment variable
                                   description: "Jira password for JiraBuildNumberAction", # a short description of this parameter
                                   verify_block: proc do |value|
                                     UI.user_error!("No jira password for JiraBuildNumberAction given, pass using `build_number: 'build'`") unless (value and not value.empty?)
                                     # UI.user_error!("Couldn't find file at path '#{value}'") unless File.exist?(value)
                                   end),
      FastlaneCore::ConfigItem.new(key: :jira_hostname,
                                   env_name: "FL_JIRA_BUILD_NUMBER_JIRA_HOSTNAME", # The name of the environment variable
                                   description: "Jira hostname for JiraBuildNumberAction", # a short description of this parameter
                                   verify_block: proc do |value|
                                     UI.user_error!("No jira hostname for JiraBuildNumberAction given, pass using `build_number: 'build'`") unless (value and not value.empty?)
                                     # UI.user_error!("Couldn't find file at path '#{value}'") unless File.exist?(value)
                                   end),
      FastlaneCore::ConfigItem.new(key: :jira_token,
                                   env_name: "FL_JIRA_BUILD_NUMBER_JIRA_TOKEN", # The name of the environment variable
                                   description: "Jira token for JiraBuildNumberAction", # a short description of this parameter
                                   verify_block: proc do |value|
                                     UI.user_error!("No jira basic token for JiraBuildNumberAction given, pass using `build_number: 'build'`") unless (value and not value.empty?)
                                     # UI.user_error!("Couldn't find file at path '#{value}'") unless File.exist?(value)
                                   end),
      FastlaneCore::ConfigItem.new(key: :build_number,
                                   env_name: "FL_JIRA_BUILD_NUMBER_BUILD_NUMBER", # The name of the environment variable
                                   description: "Build number for JiraBuildNumberAction", # a short description of this parameter
                                   verify_block: proc do |value|
                                     UI.user_error!("No build number for JiraBuildNumberAction given, pass using `build_number: 'build'`") unless (value and not value.empty?)
                                     # UI.user_error!("Couldn't find file at path '#{value}'") unless File.exist?(value)
                                   end),
      FastlaneCore::ConfigItem.new(key: :version_name,
                                   env_name: "FL_JIRA_BUILD_NUMBER_VERSION_NAME", # The name of the environment variable
                                   description: "Build version for JiraBuildNumberAction", # a short description of this parameter
                                   verify_block: proc do |value|
                                     UI.user_error!("No build version for JiraBuildNumberAction given, pass using `version_name: 'version'`") unless (value and not value.empty?)
                                     # UI.user_error!("Couldn't find file at path '#{value}'") unless File.exist?(value)
                                   end),
      FastlaneCore::ConfigItem.new(key: :commit_branch,
                                   env_name: "FL_JIRA_BUILD_NUMBER_COMMIT_BRANCH", # The name of the environment variable
                                   description: "Commit branch for JiraBuildNumberAction", # a short description of this parameter
                                   verify_block: proc do |value|
                                     UI.user_error!("No commit branch for JiraBuildNumberAction given, pass using `commit_branch: 'branch'`") unless (value and not value.empty?)
                                     # UI.user_error!("Couldn't find file at path '#{value}'") unless File.exist?(value)
                                   end),
      FastlaneCore::ConfigItem.new(key: :commit_message,
                                   env_name: "FL_JIRA_BUILD_NUMBER_COMMIT_MESSAGE", # The name of the environment variable
                                   description: "Commit message for JiraBuildNumberAction", # a short description of this parameter
                                   verify_block: proc do |value|
                                     UI.user_error!("No commit message for JiraBuildNumberAction given, pass using `commit_message: 'message'`") unless (value and not value.empty?)
                                     # UI.user_error!("Couldn't find file at path '#{value}'") unless File.exist?(value)
                                   end)
  ]
end
description() click to toggle source

@!group Documentation

# File lib/fastlane/plugin/jira_build_number/actions/jira_build_number_action.rb, line 71
def self.description
  "Adds build number from CI as comment to associated jira issue."
end
details() click to toggle source
# File lib/fastlane/plugin/jira_build_number/actions/jira_build_number_action.rb, line 75
def self.details
  # Optional:
  # this is your chance to provide a more detailed description of this action
  "Looks for the jira issue id in the branch or commit message and will insert the build number as a comment into that jira issue if found."
end
is_supported?(platform) click to toggle source
# File lib/fastlane/plugin/jira_build_number/actions/jira_build_number_action.rb, line 159
def self.is_supported?(platform)
  #  true
  [:ios, :android].include?(platform)

end
output() click to toggle source
# File lib/fastlane/plugin/jira_build_number/actions/jira_build_number_action.rb, line 145
def self.output
  [
      ['JIRA_ISSUE_ID_VALUE', 'The jira issue id if found within comment or branch name']
  ]
end
return_value() click to toggle source
# File lib/fastlane/plugin/jira_build_number/actions/jira_build_number_action.rb, line 151
def self.return_value
  "Returns jira issue id if found within comment or branch"
end
run(params) click to toggle source
# File lib/fastlane/plugin/jira_build_number/actions/jira_build_number_action.rb, line 11
def self.run(params)
  UI.message("Running jira build number action...")

  UI.message "Commit message: #{params[:commit_message]}"
  UI.message "Commit branch: #{params[:commit_branch]}"

  commitMessage = params[:commit_message]
  commitBranch = params[:commit_branch]

  # jiraTicketId = commitMessage.match((?<!([A-Za-z]{1,10})-?)[A-Z]+-\d+))
  jiraTicketId = searchForJiraTicketId(commitMessage)

  #UI.message "Jira ticket id: #{jiraTicketId}"

  if(jiraTicketId.nil?)
    jiraTicketId = searchForJiraTicketId(commitBranch)
  end

  UI.message "Jira ticket id: #{jiraTicketId}"

  buildNumber = params[:build_number].strip
  buildVersion = params[:version_name].strip

  UI.message "Build version: #{buildVersion}"
  UI.message "Build number: #{buildNumber}"

  jiraHostname = params[:jira_hostname]
  #jiraBasicToken = params[:jira_token]
  jiraUsername = params[:jira_username]
  jiraPassword = params[:jira_password]

  jiraBasicToken = Base64.encode64("#{jiraUsername}:#{jiraPassword}")

  #UI.message "token: #{jiraBasicToken}"

  payload = "{\"body\": \"Build: #{buildVersion}.#{buildNumber}\"}"

  #UI.message "payload: #{payload}"

  if(!jiraTicketId.nil?)
    response = RestClient.post "https://#{jiraHostname}/rest/api/2/issue/#{jiraTicketId}/comment",
                               payload,
                               {content_type: "application/json", Authorization: "Basic #{jiraBasicToken}"}
  end

  #UI.message "Jira post response: #{response.body}"

  # sh "shellcommand ./path"

  # Actions.lane_context[SharedValues::JIRA_BUILD_NUMBER_CUSTOM_VALUE] = "my_val"
end
searchForJiraTicketId(str) click to toggle source
# File lib/fastlane/plugin/jira_build_number/actions/jira_build_number_action.rb, line 63
def self.searchForJiraTicketId(str)
  /[A-Z]+[-](\d+)/.match(str)
end