Class: Fastlane::Actions::ChangelogFromGitCommitsAction

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

Documentation collapse

Class Method Summary collapse

Methods inherited from Fastlane::Action

action_name, authors, method_missing, other_action, sh, step_text

Class Method Details

.authorObject



105
106
107
# File 'lib/fastlane/actions/changelog_from_git_commits.rb', line 105

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

.available_optionsObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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
# File 'lib/fastlane/actions/changelog_from_git_commits.rb', line 52

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',
                                 optional: true,
                                 is_string: false,
                                 verify_block: proc do |value|
                                   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),
    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: :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: :include_merges,
                                 env_name: 'FL_CHANGELOG_FROM_GIT_COMMITS_INCLUDE_MERGES',
                                 description: "Whether or not to include any commits that are merges\n" + '(DEPRECATED - use :merge_commit_filtering)'.red,
                                 optional: true,
                                 is_string: false,
                                 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.\nValid 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

.descriptionObject



40
41
42
# File 'lib/fastlane/actions/changelog_from_git_commits.rb', line 40

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

.detailsObject



44
45
46
# File 'lib/fastlane/actions/changelog_from_git_commits.rb', line 44

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

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


109
110
111
# File 'lib/fastlane/actions/changelog_from_git_commits.rb', line 109

def self.is_supported?(platform)
  true
end

.outputObject



48
49
50
# File 'lib/fastlane/actions/changelog_from_git_commits.rb', line 48

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

.return_valueObject



101
102
103
# File 'lib/fastlane/actions/changelog_from_git_commits.rb', line 101

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
# File 'lib/fastlane/actions/changelog_from_git_commits.rb', line 8

def self.run(params)
  if params[:between]
    from, to = params[:between]
  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}")

  # 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

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

  changelog
end