Class: Fastlane::Actions::GenerateChangelogAction

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

Class Method Summary collapse

Class Method Details

.authorsObject



37
38
39
# File 'lib/fastlane/plugin/changelog_generator/actions/generate_changelog_action.rb', line 37

def self.authors
  ["Fernando Saragoca"]
end

.available_optionsObject



45
46
47
48
49
50
51
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
# File 'lib/fastlane/plugin/changelog_generator/actions/generate_changelog_action.rb', line 45

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :github_project,
                                 env_name: 'GENERATE_CHANGELOG_GITHUB_PROJECT',
                                 description: 'GitHub project name, including organization'),
    FastlaneCore::ConfigItem.new(key: :github_api_token,
                                 env_name: 'GENERATE_CHANGELOG_GITHUB_API_TOKEN',
                                 description: 'API token to access GitHub API',
                                 default_value: ENV["GITHUB_API_TOKEN"]),
    FastlaneCore::ConfigItem.new(key: :base_branch,
                                 env_name: 'GENERATE_CHANGELOG_BASE_BRANCH',
                                 description: 'Base branch for pull requests'),
    FastlaneCore::ConfigItem.new(key: :template,
                                 env_name: 'GENERATE_CHANGELOG_TEMPLATE',
                                 description: 'Template for generating changelog',
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :template_path,
                                 env_name: 'GENERATE_CHANGELOG_TEMPLATE_PATH',
                                 description: 'Contents of path will override `template` param',
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :tags,
                                 env_name: 'GENERATE_CHANGELOG_TAGS',
                                 description: 'Tags to generate changelog',
                                 is_string: false,
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :max_number_of_tags,
                                 env_name: 'GENERATE_CHANGELOG_MAX_NUMBER_OF_TAGS',
                                 description: 'Number of tags to generate changelog when not filtering by tag',
                                 is_string: false,
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :include_unreleased_section,
                                 env_name: 'GENERATE_CHANGELOG_INCLUDE_UNRELEASED_SECTION',
                                 description: 'Includes an unreleased section',
                                 is_string: false,
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :output_path,
                                 env_name: 'GENERATE_CHANGELOG_OUTPUT_PATH',
                                 description: 'If set, will automatically write changelog to output path',
                                 optional: true)
  ]
end

.descriptionObject



33
34
35
# File 'lib/fastlane/plugin/changelog_generator/actions/generate_changelog_action.rb', line 33

def self.description
  "Changelog generation based on merged pull requests & tags"
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/fastlane/plugin/changelog_generator/actions/generate_changelog_action.rb', line 87

def self.is_supported?(platform)
  true
end

.return_valueObject



41
42
43
# File 'lib/fastlane/plugin/changelog_generator/actions/generate_changelog_action.rb', line 41

def self.return_value
  "Generated changelog"
end

.run(params) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/fastlane/plugin/changelog_generator/actions/generate_changelog_action.rb', line 4

def self.run(params)
  labels, pull_requests = Helper::ChangelogGeneratorFetcher.fetch_github_data(params, lane_context)

  tag_limit = params[:max_number_of_tags]
  tags = params[:tags] || Helper::ChangelogGeneratorHelper.git_tags(tag_limit)
  releases = []

  # Unreleased section
  if params[:include_unreleased_section]
    unreleased_section = Helper::ChangelogGeneratorRelease.new(labels, pull_requests, tags.first, nil)
    releases << unreleased_section if unreleased_section.data.count > 0
  end

  # Between tags sections
  tags.each_with_index do |tag, idx|
    if idx != 0
      previous_tag = tags[idx - 1]
      releases << Helper::ChangelogGeneratorRelease.new(labels, pull_requests, previous_tag, tag)
    end
  end

  # Last section
  if tags.count > 0 && params[:tags].nil? && (tag_limit.nil? || tags.count < tag_limit)
    releases << Helper::ChangelogGeneratorRelease.new(labels, pull_requests, nil, tags.last)
  end

  Helper::ChangelogGeneratorRender.new(releases, labels, params).to_markdown
end