Class: Fastlane::Actions::GenerateReleaseChangelogAction

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

Class Method Summary collapse

Class Method Details

.authorsObject



45
46
47
# File 'lib/fastlane/plugin/changelog_generator/actions/generate_release_changelog_action.rb', line 45

def self.authors
  ["Fernando Saragoca"]
end

.available_optionsObject



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
# File 'lib/fastlane/plugin/changelog_generator/actions/generate_release_changelog_action.rb', line 53

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: :tag_a,
                                 env_name: 'GENERATE_CHANGELOG_TAG_A',
                                 description: 'Tag to filter pull requests',
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :tag_b,
                                 env_name: 'GENERATE_CHANGELOG_TAG_B',
                                 description: 'Tag to filter pull requests',
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :skip_tag_b,
                                 env_name: 'GENERATE_CHANGELOG_SKIP_TAG_B',
                                 description: 'Skip second tag',
                                 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



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

def self.description
  "Changelog generation based on merged pull requests & tags, filtered by one or two tags"
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/fastlane/plugin/changelog_generator/actions/generate_release_changelog_action.rb', line 93

def self.is_supported?(platform)
  true
end

.prompt_tag(message = '', excluded_tags = [], allow_none = false) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/fastlane/plugin/changelog_generator/actions/generate_release_changelog_action.rb', line 17

def self.prompt_tag(message = '', excluded_tags = [], allow_none = false)
  no_tag_text = 'No tag'
  other_tag_text = 'Enter tag manually'
  tag_limit = 10

  available_tags = Helper::ChangelogGeneratorHelper.git_tags
  available_tags.reject! { |tag| excluded_tags.include?(tag) }
  tags_count = available_tags.count

  available_tags = available_tags.take(tag_limit)
  available_tags << no_tag_text if allow_none
  available_tags << other_tag_text if tags_count > tag_limit

  if allow_none && available_tags.count == 1
    UI.important("Skiping second tag because there are no tags available.")
    return nil
  end

  tag = UI.select(message, available_tags)
  tag = nil if tag == no_tag_text
  tag = UI.input('Tag: ') if tag == other_tag_text
  tag
end

.return_valueObject



49
50
51
# File 'lib/fastlane/plugin/changelog_generator/actions/generate_release_changelog_action.rb', line 49

def self.return_value
  "Generated changelog"
end

.run(params) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/fastlane/plugin/changelog_generator/actions/generate_release_changelog_action.rb', line 4

def self.run(params)
  tag_a = params[:tag_a] || prompt_tag("Please enter first tag: ")
  tag_b = params[:tag_b]
  if tag_b.nil? && params[:skip_tag_b].nil?
    tag_b = prompt_tag("Please enter second tag: ", [tag_a], true)
  end

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

  release = Helper::ChangelogGeneratorRelease.new(labels, pull_requests, tag_b, tag_a)
  Helper::ChangelogGeneratorRender.new([release], labels, params).to_markdown
end