Class: Fastlane::Actions::ChangelogFromGitCommitsAction

Inherits:
Fastlane::Action show all
Defined in:
fastlane/lib/fastlane/actions/changelog_from_git_commits.rb

Constant Summary

Constants inherited from Fastlane::Action

Fastlane::Action::AVAILABLE_CATEGORIES, Fastlane::Action::RETURN_TYPES

Documentation collapse

Class Method Summary collapse

Methods inherited from Fastlane::Action

action_name, authors, deprecated_notes, lane_context, method_missing, other_action, sample_return_value, shell_out_should_use_bundle_exec?, step_text

Class Method Details

.authorObject



171
172
173
# File 'fastlane/lib/fastlane/actions/changelog_from_git_commits.rb', line 171

def self.author
  ['mfurtak', 'asfalcone', 'SiarheiFedartsou', 'allewun']
end

.available_optionsObject



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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'fastlane/lib/fastlane/actions/changelog_from_git_commits.rb', line 76

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :between,
                                 env_name: 'FL_CHANGELOG_FROM_GIT_COMMITS_BETWEEN',
                                 description: 'Array containing two Git revision values between which to collect messages, you mustn\'t use it with :commits_count key at the same time',
                                 optional: true,
                                 is_string: false,
                                 conflicting_options: [:commits_count],
                                 verify_block: proc do |value|
                                   if value.kind_of?(String)
                                     UI.user_error!(":between must contain comma") unless value.include?(',')
                                   else
                                     UI.user_error!(":between must be of type array") unless value.kind_of?(Array)
                                     UI.user_error!(":between must not contain nil values") if value.any?(&:nil?)
                                     UI.user_error!(":between must be an array of size 2") unless (value || []).size == 2
                                   end
                                 end),
    FastlaneCore::ConfigItem.new(key: :commits_count,
                                 env_name: 'FL_CHANGELOG_FROM_GIT_COMMITS_COUNT',
                                 description: 'Number of commits to include in changelog, you mustn\'t use it with :between key at the same time',
                                 optional: true,
                                 is_string: false,
                                 conflicting_options: [:between],
                                 type: Integer,
                                 verify_block: proc do |value|
                                   UI.user_error!(":commits_count must be >= 1") unless value.to_i >= 1
                                 end),
    FastlaneCore::ConfigItem.new(key: :path,
                                 env_name: 'FL_CHANGELOG_FROM_GIT_COMMITS_PATH',
                                 description: 'Path of the git repository',
                                 optional: true,
                                 default_value: './'),
    FastlaneCore::ConfigItem.new(key: :pretty,
                                 env_name: 'FL_CHANGELOG_FROM_GIT_COMMITS_PRETTY',
                                 description: 'The format applied to each commit while generating the collected value',
                                 optional: true,
                                 default_value: '%B',
                                 is_string: true),
    FastlaneCore::ConfigItem.new(key: :date_format,
                                 env_name: 'FL_CHANGELOG_FROM_GIT_COMMITS_DATE_FORMAT',
                                 description: 'The date format applied to each commit while generating the collected value',
                                 optional: true,
                                 is_string: true),
    FastlaneCore::ConfigItem.new(key: :ancestry_path,
                                 env_name: 'FL_CHANGELOG_FROM_GIT_COMMITS_ANCESTRY_PATH',
                                 description: 'Whether or not to use ancestry-path param',
                                 optional: true,
                                 default_value: false,
                                 is_string: false),
    FastlaneCore::ConfigItem.new(key: :tag_match_pattern,
                                 env_name: 'FL_CHANGELOG_FROM_GIT_COMMITS_TAG_MATCH_PATTERN',
                                 description: 'A glob(7) pattern to match against when finding the last git tag',
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :match_lightweight_tag,
                                 env_name: 'FL_CHANGELOG_FROM_GIT_COMMITS_MATCH_LIGHTWEIGHT_TAG',
                                 description: 'Whether or not to match a lightweight tag when searching for the last one',
                                 optional: true,
                                 default_value: true,
                                 is_string: false),
    FastlaneCore::ConfigItem.new(key: :quiet,
                                 env_name: 'FL_CHANGELOG_FROM_GIT_COMMITS_TAG_QUIET',
                                 description: 'Whether or not to disable changelog output',
                                 optional: true,
                                 default_value: false,
                                 is_string: false),
    FastlaneCore::ConfigItem.new(key: :include_merges,
                                 deprecated: "Use `:merge_commit_filtering` instead",
                                 env_name: 'FL_CHANGELOG_FROM_GIT_COMMITS_INCLUDE_MERGES',
                                 description: "Whether or not to include any commits that are merges",
                                 optional: true,
                                 is_string: false,
                                 type: Boolean,
                                 verify_block: proc do |value|
                                   UI.important("The :include_merges option is deprecated. Please use :merge_commit_filtering instead") unless value.nil?
                                 end),
    FastlaneCore::ConfigItem.new(key: :merge_commit_filtering,
                                 env_name: 'FL_CHANGELOG_FROM_GIT_COMMITS_MERGE_COMMIT_FILTERING',
                                 description: "Controls inclusion of merge commits when collecting the changelog. Valid values: #{GIT_MERGE_COMMIT_FILTERING_OPTIONS.map { |o| "`:#{o}`" }.join(', ')}",
                                 optional: true,
                                 default_value: 'include_merges',
                                 verify_block: proc do |value|
                                   matches_option = GIT_MERGE_COMMIT_FILTERING_OPTIONS.any? { |opt| opt.to_s == value }
                                   UI.user_error!("Valid values for :merge_commit_filtering are #{GIT_MERGE_COMMIT_FILTERING_OPTIONS.map { |o| "'#{o}'" }.join(', ')}") unless matches_option
                                 end)
  ]
end

.categoryObject



192
193
194
# File 'fastlane/lib/fastlane/actions/changelog_from_git_commits.rb', line 192

def self.category
  :source_control
end

.descriptionObject



62
63
64
# File 'fastlane/lib/fastlane/actions/changelog_from_git_commits.rb', line 62

def self.description
  "Collect git commit messages into a changelog"
end

.detailsObject



66
67
68
# File 'fastlane/lib/fastlane/actions/changelog_from_git_commits.rb', line 66

def self.details
  "By default, messages will be collected back to the last tag, but the range can be controlled"
end

.example_codeObject



179
180
181
182
183
184
185
186
187
188
189
190
# File 'fastlane/lib/fastlane/actions/changelog_from_git_commits.rb', line 179

def self.example_code
  [
    'changelog_from_git_commits',
    'changelog_from_git_commits(
      between: ["7b092b3", "HEAD"],            # Optional, lets you specify a revision/tag range between which to collect commit info
      pretty: "- (%ae) %s",                    # Optional, lets you provide a custom format to apply to each commit when generating the changelog text
      date_format: "short",                    # Optional, lets you provide an additional date format to dates within the pretty-formatted string
      match_lightweight_tag: false,            # Optional, lets you ignore lightweight (non-annotated) tags when searching for the last tag
      merge_commit_filtering: "exclude_merges" # Optional, lets you filter out merge commits
    )'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:



175
176
177
# File 'fastlane/lib/fastlane/actions/changelog_from_git_commits.rb', line 175

def self.is_supported?(platform)
  true
end

.outputObject



70
71
72
73
74
# File 'fastlane/lib/fastlane/actions/changelog_from_git_commits.rb', line 70

def self.output
  [
    ['FL_CHANGELOG', 'The changelog string generated from the collected git commit messages']
  ]
end

.return_typeObject



167
168
169
# File 'fastlane/lib/fastlane/actions/changelog_from_git_commits.rb', line 167

def self.return_type
  :string
end

.return_valueObject



163
164
165
# File 'fastlane/lib/fastlane/actions/changelog_from_git_commits.rb', line 163

def self.return_value
  "Returns a String containing your formatted git commits"
end

.run(params) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'fastlane/lib/fastlane/actions/changelog_from_git_commits.rb', line 8

def self.run(params)
  if params[:commits_count]
    UI.success("Collecting the last #{params[:commits_count]} Git commits")
  else
    if params[:between]
      if params[:between].kind_of?(String) && params[:between].include?(",") # :between is string
        from, to = params[:between].split(",", 2)
      elsif params[:between].kind_of?(Array)
        from, to = params[:between]
      end
    else
      from = Actions.last_git_tag_name(params[:match_lightweight_tag], params[:tag_match_pattern])
      UI.verbose("Found the last Git tag: #{from}")
      to = 'HEAD'
    end
    UI.success("Collecting Git commits between #{from} and #{to}")
  end

  # Normally it is not good practice to take arbitrary input and convert it to a symbol
  # because prior to Ruby 2.2, symbols are never garbage collected. However, we've
  # already validated that the input matches one of our allowed values, so this is OK
  merge_commit_filtering = params[:merge_commit_filtering].to_sym

  # We want to be specific and exclude nil for this comparison
  if params[:include_merges] == false
    merge_commit_filtering = :exclude_merges
  end

  params[:path] = './' unless params[:path]

  Dir.chdir(params[:path]) do
    if params[:commits_count]
      changelog = Actions.git_log_last_commits(params[:pretty], params[:commits_count], merge_commit_filtering, params[:date_format], params[:ancestry_path])
    else
      changelog = Actions.git_log_between(params[:pretty], from, to, merge_commit_filtering, params[:date_format], params[:ancestry_path])
    end

    changelog = changelog.gsub("\n\n", "\n") if changelog # as there are duplicate newlines
    Actions.lane_context[SharedValues::FL_CHANGELOG] = changelog

    if params[:quiet] == false
      puts("")
      puts(changelog)
      puts("")
    end

    changelog
  end
end