Class: Fastlane::Actions::FindTicketsAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/cerberus/actions/find_tickets_action.rb

Helpers collapse

Documentation collapse

Class Method Summary collapse

Class Method Details

.authorObject



109
110
111
# File 'lib/fastlane/plugin/cerberus/actions/find_tickets_action.rb', line 109

def self.author
  'Harry Singh <[email protected]>'
end

.available_optionsObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# 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

.detailsObject



58
59
60
# 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:) ⇒ Object



49
50
51
52
# 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) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/fastlane/plugin/cerberus/actions/find_tickets_action.rb', line 62

def self.is_supported?(platform)
  platform == :ios
end

.log(from:, to:, pretty:) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# 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

.outputObject



66
67
68
# File 'lib/fastlane/plugin/cerberus/actions/find_tickets_action.rb', line 66

def self.output
  [String]
end

.run(params) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 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:) ⇒ Object



40
41
42
43
44
45
46
47
# 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