Skip to content

Commit 3ac393d

Browse files
authored
Fix create_github_release crashing when no release notes are given (#759)
2 parents 64a0694 + 8fdd882 commit 3ac393d

3 files changed

Lines changed: 80 additions & 2 deletions

File tree

CHANGELOG.md

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

1515
### Bug Fixes
1616

17-
_None_
17+
- `create_github_release` no longer crashes with `FrozenError` when the optional `release_notes_file_path` is omitted. [#759]
1818

1919
### Internal Changes
2020

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def self.run(params)
1414
# Replace full URLs to PRs/Issues that are in `[https://some-url]` brackets with shorthand, because GitHub does not render them properly otherwise.
1515
# That syntax is sometimes used by devs in `RELEASE-NOTES.txt` when pointing to a PR to another repo (e.g. Gutenberg PR from WP repo).
1616
# We should NOT transform URLs to PRs/Issues that are in `[text](url)` form (those are valid), only the ones directly in `[]` brackets.
17-
release_notes.gsub!(%r{\[https://github.com/([^/]*/[^/]*)/(pulls?|issues?)/([0-9]*)\]}, '[\1#\3]')
17+
release_notes = release_notes.gsub(%r{\[https://github.com/([^/]*/[^/]*)/(pulls?|issues?)/([0-9]*)\]}, '[\1#\3]')
1818
prerelease = params[:prerelease]
1919
is_draft = params[:is_draft]
2020

spec/create_github_release_spec.rb

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
describe Fastlane::Actions::CreateGithubReleaseAction do
6+
let(:test_token) { 'ghp_fake_token' }
7+
let(:test_repo) { 'repo-test/project-test' }
8+
let(:test_version) { '1.0.0' }
9+
let(:release_url) { 'https://github.com/repo-test/project-test/releases/tag/1.0.0' }
10+
let(:github_helper) { instance_double(Fastlane::Helper::GithubHelper) }
11+
12+
before do
13+
allow(Fastlane::Helper::GithubHelper).to receive(:new).and_return(github_helper)
14+
end
15+
16+
context 'when no release notes file is provided' do
17+
it 'creates the release with an empty description' do
18+
allow(github_helper).to receive(:create_release).with(
19+
repository: test_repo,
20+
version: test_version,
21+
name: nil,
22+
target: nil,
23+
description: '',
24+
assets: [],
25+
prerelease: false,
26+
is_draft: true
27+
).and_return(release_url)
28+
29+
result = run_described_fastlane_action(
30+
github_token: test_token,
31+
repository: test_repo,
32+
version: test_version,
33+
release_assets: []
34+
)
35+
36+
expect(result).to eq(release_url)
37+
end
38+
end
39+
40+
context 'when a release notes file is provided' do
41+
it 'rewrites bracketed GitHub PR and issue URLs to shorthand' do
42+
notes = <<~NOTES
43+
- Fix a thing [https://github.com/org-test/other-repo/pull/123]
44+
- Fix another thing [https://github.com/org-test/other-repo/issues/456]
45+
- Leave markdown links alone [as a link](https://github.com/org-test/other-repo/pull/789)
46+
NOTES
47+
48+
expected_description = <<~NOTES
49+
- Fix a thing [org-test/other-repo#123]
50+
- Fix another thing [org-test/other-repo#456]
51+
- Leave markdown links alone [as a link](https://github.com/org-test/other-repo/pull/789)
52+
NOTES
53+
54+
with_tmp_file(named: 'release-notes.txt', content: notes) do |notes_path|
55+
allow(github_helper).to receive(:create_release).with(
56+
repository: test_repo,
57+
version: test_version,
58+
name: nil,
59+
target: nil,
60+
description: expected_description,
61+
assets: [],
62+
prerelease: false,
63+
is_draft: true
64+
).and_return(release_url)
65+
66+
result = run_described_fastlane_action(
67+
github_token: test_token,
68+
repository: test_repo,
69+
version: test_version,
70+
release_assets: [],
71+
release_notes_file_path: notes_path
72+
)
73+
74+
expect(result).to eq(release_url)
75+
end
76+
end
77+
end
78+
end

0 commit comments

Comments
 (0)