class Fastlane::Actions::FindTicketsAction

Public Class Methods

author() click to toggle source
# File lib/fastlane/plugin/cerberus/actions/find_tickets_action.rb, line 109
def self.author
  'Harry Singh <hhs4harry@gmail.com>'
end
available_options() click to toggle source
# File lib/fastlane/plugin/cerberus/actions/find_tickets_action.rb, line 70
def self.available_options
  [
    FastlaneCore::ConfigItem.new(
      key: :from,
      env_name: 'FL_FIND_TICKETS_FROM',
      description:  'start commit',
      optional: true,
      default_value: 'HEAD'
    ),
    FastlaneCore::ConfigItem.new(
      key: :to,
      env_name: 'FL_FIND_TICKETS_TO',
      description:  'end commit',
      optional: true,
      default_value: ENV['GIT_PREVIOUS_SUCCESSFUL_COMMIT'] || 'HEAD'
    ),
    FastlaneCore::ConfigItem.new(
      key: :matching,
      env_name: 'FL_FIND_TICKETS_MATCHING',
      description:  'regex to extract ticket numbers',
      optional: true,
      default_value: '([A-Z]+-\d+)'
    ),
    FastlaneCore::ConfigItem.new(
      key: :excluding,
      env_name: 'FL_FIND_TICKETS_EXCLUDING',
      description:  'regex to exclude from the change log',
      optional: true
    ),
    FastlaneCore::ConfigItem.new(
      key: :pretty,
      env_name: 'FL_FIND_TICKETS_PRETTY_FORMAT',
      description:  'git pretty format',
      optional: true,
      default_value: '* (%h) %s'
    )
  ]
end
details() click to toggle source

@!group Documentation

# File lib/fastlane/plugin/cerberus/actions/find_tickets_action.rb, line 58
def self.details
  'Extracts the Jira issue keys between commits'
end
filter_tickets(tickets:, exclude_regex:) click to toggle source
# File lib/fastlane/plugin/cerberus/actions/find_tickets_action.rb, line 49
def self.filter_tickets(tickets:, exclude_regex:)
  return [] if tickets.to_s.empty?
  tickets.each.grep_v(exclude_regex)
end
is_supported?(platform) click to toggle source
# File lib/fastlane/plugin/cerberus/actions/find_tickets_action.rb, line 62
def self.is_supported?(platform)
  platform == :ios
end
log(from:, to:, pretty:) click to toggle source

@!group Helpers

# File lib/fastlane/plugin/cerberus/actions/find_tickets_action.rb, line 27
def self.log(from:, to:, pretty:)
  if to.to_s.empty? || from.to_s.empty?
    UI.important('Git Tickets: log(to:, from:) cannot be nil')
    return nil
  end

  other_action.changelog_from_git_commits(
    between: [from, to],
    pretty: pretty,
    merge_commit_filtering: :exclude_merges.to_s
  )
end
output() click to toggle source
# File lib/fastlane/plugin/cerberus/actions/find_tickets_action.rb, line 66
def self.output
  [String]
end
run(params) click to toggle source
# File lib/fastlane/plugin/cerberus/actions/find_tickets_action.rb, line 7
def self.run(params)
  regex = Regexp.new(params[:matching])
  changelog = log(from: params[:from], to: params[:to], pretty: params[:pretty])

  if changelog.to_s.empty?
    UI.important('Git Tickets: No changes found.')
    return []
  end

  tickets = tickets(log: changelog, regex: regex)
  exclude_regex = Regexp.new(params[:excluding]) unless params[:excluding].to_s.empty?
  tickets = filter_tickets(tickets: tickets, exclude_regex: exclude_regex) if exclude_regex
  UI.important("Jira Issues: #{tickets.join(', ')}")
  return tickets
end
tickets(log:, regex:) click to toggle source
# File lib/fastlane/plugin/cerberus/actions/find_tickets_action.rb, line 40
def self.tickets(log:, regex:)
  return [] if log.to_s.empty?
  log.each_line
     .map { |line| line.strip.scan(regex) }
     .flatten
     .reject(&:empty?)
     .uniq
end