Skip to content

Commit 35c8b66

Browse files
authored
Add optional name parameter to create_github_release action (#703)
2 parents 87883d2 + 244db41 commit 35c8b66

4 files changed

Lines changed: 22 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ _None_
1010

1111
### New Features
1212

13-
_None_
13+
- Added optional `name` parameter to `create_github_release` action, allowing a custom release title independent of the git tag. Defaults to `version` for backward compatibility. [#703]
1414

1515
### Bug Fixes
1616

lib/fastlane/plugin/wpmreleasetoolkit/actions/common/create_github_release_action.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def self.run(params)
2828
url = github_helper.create_release(
2929
repository: repository,
3030
version: version,
31+
name: params[:name],
3132
target: params[:target],
3233
description: release_notes,
3334
assets: assets,
@@ -64,9 +65,13 @@ def self.available_options
6465
type: String),
6566
FastlaneCore::ConfigItem.new(key: :version,
6667
env_name: 'GHHELPER_CREATE_RELEASE_VERSION',
67-
description: 'The version of the release',
68+
description: 'The version of the release. Used as the git tag name',
6869
optional: false,
6970
type: String),
71+
FastlaneCore::ConfigItem.new(key: :name,
72+
description: 'The display name (title) of the GitHub release. Defaults to the version if not provided',
73+
optional: true,
74+
type: String),
7075
FastlaneCore::ConfigItem.new(key: :target,
7176
env_name: 'GHHELPER_TARGET_COMMITISH',
7277
description: 'The branch name or commit SHA the new tag should point to - if that tag does not exist yet when publishing the release. If omitted, will default to the current HEAD commit at the time of this call',

lib/fastlane/plugin/wpmreleasetoolkit/helper/github_helper.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ def create_milestone(repository:, title:, due_date:, days_until_submission:, day
166166
# Creates a Release on GitHub as a Draft
167167
#
168168
# @param [String] repository The repository to create the GitHub release on. Typically a repo slug (<org>/<repo>).
169-
# @param [String] version The version for which to create this release. Will be used both as the name of the tag and the name of the release.
169+
# @param [String] version The version for which to create this release. Will be used as the git tag name.
170+
# @param [String?] name The display name (title) of the GitHub release. Defaults to the version if not provided.
170171
# @param [String?] target The commit SHA or branch name that this release will point to when it's published and creates the tag.
171172
# If nil (the default), will use the repo's current HEAD commit at the time this method is called.
172173
# Unused if the tag already exists.
@@ -175,11 +176,11 @@ def create_milestone(repository:, title:, due_date:, days_until_submission:, day
175176
# @param [TrueClass|FalseClass] prerelease Indicates if this should be created as a pre-release (i.e. for alpha/beta)
176177
# @param [TrueClass|FalseClass] is_draft Indicates if this should be created as a draft release
177178
#
178-
def create_release(repository:, version:, description:, assets:, prerelease:, is_draft:, target: nil)
179+
def create_release(repository:, version:, description:, assets:, prerelease:, is_draft:, target: nil, name: nil)
179180
release = client.create_release(
180181
repository,
181182
version, # tag name
182-
name: version, # release name
183+
name: name || version, # release name
183184
target_commitish: target || Git.open(Dir.pwd).log.first.sha,
184185
prerelease: prerelease,
185186
draft: is_draft,

spec/github_helper_spec.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,11 +555,21 @@ def create_milestone(due_date:, days_until_submission:, days_until_release:)
555555
expect(url).to eq(release_url)
556556
end
557557

558-
def create_release(is_draft:, assets: [])
558+
it 'uses a custom name when provided' do
559+
custom_name = 'Version 1.0'
560+
options = { body: test_description, draft: true, name: custom_name, prerelease: false, target_commitish: test_target }
561+
expect(client).to receive(:create_release).with(test_repo, test_tag, options)
562+
allow(client).to receive(:create_release).and_return(html_url: release_url)
563+
url = create_release(is_draft: true, name: custom_name)
564+
expect(url).to eq(release_url)
565+
end
566+
567+
def create_release(is_draft:, assets: [], name: nil)
559568
helper = described_class.new(github_token: 'Fake-GitHubToken-123')
560569
helper.create_release(
561570
repository: test_repo,
562571
version: test_tag,
572+
name: name,
563573
target: test_target,
564574
description: test_description,
565575
assets: assets,

0 commit comments

Comments
 (0)