Class: Fastlane::Actions::GetPrsBetweenTagsAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/wpmreleasetoolkit/actions/common/get_prs_between_tags.rb

Class Method Summary collapse

Class Method Details

.authorsObject



45
46
47
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/get_prs_between_tags.rb', line 45

def self.authors
  ['Automattic']
end

.available_optionsObject



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
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/get_prs_between_tags.rb', line 71

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :repository,
                                 env_names: %w[GIT_REPO_SLUG BUILDKITE_REPO],
                                 description: 'The repository name, including the organization (e.g. `wordpress-mobile/wordpress-ios`)',
                                 optional: false,
                                 default_value_dynamic: true,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :tag_name,
                                 description: 'The name of the tag for the release we are about to create. This can be an existing tag or a new one',
                                 optional: false,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :target_commitish,
                                 description: 'Specifies the commitish value that will be the target for the release\'s tag. ' \
                                              'Required if the supplied `tag_name` does not reference an existing tag. Ignored if the tag_name already exists. ' \
                                              'Defaults to the commit sha of the current HEAD',
                                 optional: true,
                                 default_value: `git rev-parse HEAD`.chomp,
                                 default_value_dynamic: true,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :previous_tag,
                                 description: 'The name of the previous tag to use as the starting point for the release notes. ' \
                                              'If not provided explicitly, GitHub will use the last tag as the starting point',
                                 optional: true,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :configuration_file_path,
                                 description: 'Path to a file in the repository containing configuration settings used for generating the release notes. ' \
                                              'If unspecified, the configuration file located in the repository at `.github/release.yml` or `.github/release.yaml` will be used. ' \
                                              'If that is not present, the default configuration will be used. ' \
                                              'See https://docs.github.com/en/repositories/releasing-projects-on-github/automatically-generated-release-notes#configuration-options',
                                 optional: true,
                                 type: String),
    Fastlane::Helper::GithubHelper.github_token_config_item,
  ]
end

.descriptionObject



41
42
43
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/get_prs_between_tags.rb', line 41

def self.description
  'Gets a markdown text containing the list of PRs that have been merged between two git tags'
end

.detailsObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/get_prs_between_tags.rb', line 53

def self.details
  <<~DETAILS
    Uses the GitHub API to get a generated changelog consisting of the list of PRs that have been merged between two git tags.
    The list of PRs can optionally be categorized using a config file (typically living at `.github/release.yml`)

    This is typically useful to generate a CHANGELOG-style list of PRs for a given build since a last build. For example:

    - List PRs between current beta that we just built (e.g. 12.3-rc-4) and the previous beta of the same version:
        git_prs_between_tags(tag_name: '12.3-rc-4', previous_tag: '12.3-rc-3')
    - List all PRs that landed since the last stable/final release:
        git_prs_between_tags(tag_name: '12.3-rc-4', previous_tag: '12.2')

    Tip: You can use the `find_previous_tag` action to help you find the previous_tag matching an expected pattern (like `12.3-rc-*`)

    See https://docs.github.com/en/rest/releases/releases?apiVersion=2022-11-28#generate-release-notes-content-for-a-release
  DETAILS
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/get_prs_between_tags.rb', line 107

def self.is_supported?(platform)
  true
end

.return_valueObject



49
50
51
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/get_prs_between_tags.rb', line 49

def self.return_value
  'The markdown-formatted string listing the PRs between the provided tags'
end

.run(params) ⇒ Object



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
32
33
34
35
36
37
38
39
# File 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/get_prs_between_tags.rb', line 7

def self.run(params)
  repository = params[:repository]
  tag_name = params[:tag_name]
  target_commitish = params[:target_commitish]
  previous_tag = params[:previous_tag]
  config_file_path = params[:configuration_file_path]
  gh_token = params[:github_token]

  # Get commit list
  github_helper = Fastlane::Helper::GithubHelper.new(github_token: gh_token)
  changelog = begin
    github_helper.generate_release_notes(
      repository: repository,
      tag_name: tag_name,
      previous_tag: previous_tag,
      target_commitish: target_commitish,
      config_file_path: config_file_path
    )
  rescue StandardError => e
    error_msg = "❌ Error computing the list of PRs since #{previous_tag || 'last release'}: `#{e.message}`"
    UI.important(error_msg)
    error_msg # Use error message as GitHub Release body to help us be aware of what went wrong.
  end

  previous_release_link = if previous_tag.nil?
                            'last release'
                          else
                            link = github_helper.get_release_url(repository: repository, tag_name: previous_tag)
                            "[#{previous_tag}](#{link})"
                          end
  changelog
    .gsub("## What's Changed", "## New PRs since #{previous_release_link}\n")
end