Skip to content

Commit 69c7a3f

Browse files
authored
Show release PR URL and other minor changes in the output. (#54)
1 parent 9ecd477 commit 69c7a3f

File tree

4 files changed

+183
-12
lines changed

4 files changed

+183
-12
lines changed

exe/create-github-release

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,28 @@ puts unless options.quiet
1313
CreateGithubRelease::ReleaseTasks.new(project).run
1414

1515
puts <<~MESSAGE unless project.quiet
16-
Release '#{project.next_release_tag}' created successfully
17-
See the release notes at #{project.release_url}
16+
SUCCESS: created release '#{project.next_release_tag}'
1817
1918
Next steps:
20-
* Get someone to review and approve the release pull request
21-
* Merge the pull request manually from the command line with the following commands:
19+
20+
* Review the release notes:
21+
22+
#{project.release_url}
23+
24+
* Get someone to review and approve the release pull request:
25+
26+
#{project.release_pr_url}
27+
28+
* Merge the pull request manually from the command line with the following
29+
commands:
2230
2331
git checkout #{project.default_branch}
2432
git merge --ff-only #{project.release_branch}
2533
git push
2634
27-
Wait for the CI build to pass and then release the gem with the following command:
35+
* Wait for the CI build to pass on the default branch and then release the
36+
gem with the following command:
2837
2938
rake release:rubygem_push
39+
3040
MESSAGE

exe/revert-github-release

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,13 @@ class Parser
8686
It must be run in the root directory of the work tree with the release
8787
branch checked out (which is the state create-github-release leaves you in).
8888
89-
This script should be run beefore the release PR is merged.
89+
This script should be run before the release PR is merged.
9090
91-
This script removes the release branch and release tag both in the local
92-
repository and on the remote. Deleting the branch on GitHub will close the
93-
GitHub PR automatically.
91+
This script does the following:
92+
* Deletes the local and remote release branch
93+
* Deletes the local and remote release tag
94+
* Deletes the GitHub release object
95+
* Closes the GitHub release PR
9496
9597
Options:
9698
BANNER
@@ -172,4 +174,4 @@ end
172174

173175
revert_release!(options)
174176

175-
puts "Reverted release #{options.release_version}"
177+
puts "SUCCESS: reverted release '#{options.release_version}'"

lib/create_github_release/project.rb

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def initialize(options)
6969
:release_type, :pre, :pre_type, :release_url, :remote, :remote_base_url,
7070
:remote_repository, :remote_url, :changelog_path, :changes,
7171
:next_release_description, :last_release_changelog, :next_release_changelog,
72-
:first_commit, :verbose, :quiet
72+
:first_commit, :verbose, :quiet, :release_pr_number, :release_pr_url
7373

7474
# attr_writer :first_release
7575

@@ -324,6 +324,47 @@ def release_log_url
324324
end
325325
end
326326

327+
# @!attribute [rw] release_pr_number
328+
#
329+
# The number of the pull request created for the release or nil
330+
#
331+
# The PR must already exist.
332+
#
333+
# @example
334+
# options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
335+
# project = CreateGithubRelease::Project.new(options)
336+
# project.release_pr_number #=> '123'
337+
#
338+
# @return [String, nil]
339+
#
340+
# @api public
341+
#
342+
def release_pr_number
343+
@release_pr_number ||= begin
344+
pr_number = `gh pr list --search "head:#{release_branch}" --json number --jq ".[].number"`.chomp
345+
pr_number.empty? ? nil : pr_number
346+
end
347+
end
348+
349+
# @!attribute [rw] release_pr_url
350+
#
351+
# The url of the pull request created for the release or nil
352+
#
353+
# The PR must already exist.
354+
#
355+
# @example
356+
# options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
357+
# project = CreateGithubRelease::Project.new(options)
358+
# project.release_pr_url #=> 'https://github.com/org/repo/pull/123'
359+
#
360+
# @return [String]
361+
#
362+
# @api public
363+
#
364+
def release_pr_url
365+
@release_pr_url ||= release_pr_number.nil? ? nil : URI.parse("#{remote_url}/pull/#{release_pr_number}")
366+
end
367+
327368
# @!attribute [rw] release_type
328369
#
329370
# The type of the release being created (e.g. 'major', 'minor', 'patch')
@@ -713,12 +754,15 @@ def next_release_changelog
713754
CreateGithubRelease::Changelog.new(last_release_changelog, next_release_description).to_s
714755
end
715756

757+
# rubocop:disable Metrics/AbcSize
758+
716759
# Show the project details as a string
717760
#
718761
# @example
719762
# options = CreateGithubRelease::CommandLine::Options.new(release_type: 'major')
720763
# project = CreateGithubRelease::Project.new(options)
721764
# puts projects.to_s
765+
# first_release: false
722766
# default_branch: main
723767
# next_release_tag: v1.0.0
724768
# next_release_date: 2023-02-01
@@ -733,6 +777,8 @@ def next_release_changelog
733777
# remote_base_url: https://github.com/
734778
# remote_repository: org/repo
735779
# remote_url: https://github.com/org/repo
780+
# release_pr_number: 123
781+
# release_pr_url: https://github.com/org/repo/pull/123
736782
# changelog_path: CHANGELOG.md
737783
# verbose?: false
738784
# quiet?: false
@@ -758,11 +804,16 @@ def to_s
758804
remote_base_url: #{remote_base_url}
759805
remote_repository: #{remote_repository}
760806
remote_url: #{remote_url}
807+
release_pr_number: #{release_pr_number}
808+
release_pr_url: #{release_pr_url}
809+
changelog_path: #{changelog_path}
761810
verbose?: #{verbose?}
762811
quiet?: #{quiet?}
763812
OUTPUT
764813
end
765814

815+
# rubocop:enable Metrics/AbcSize
816+
766817
# @!attribute [rw] verbose
767818
#
768819
# If `true` enables verbose output

spec/create_github_release/project_spec.rb

Lines changed: 109 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,110 @@
981981
end
982982
end
983983

984+
describe '#release_pr_number' do
985+
subject { project.release_pr_number }
986+
987+
let(:release_pr_number) { '123' }
988+
let(:remote_url) { 'https://github.com/org/repo' }
989+
let(:release_pr_url) { "#{remote_url}/pull/#{release_pr_number}" }
990+
let(:next_release_version) { '1.0.0' }
991+
let(:next_release_branch) { "release-v#{next_release_version}" }
992+
993+
context 'when explicitly set' do
994+
let(:project_init_block) { ->(p) { p.release_pr_number = release_pr_number } }
995+
it { is_expected.to eq(release_pr_number) }
996+
end
997+
998+
context 'when there is no release PR' do
999+
let(:project_init_block) { ->(p) { p.next_release_version = next_release_version } }
1000+
1001+
let(:mocked_commands) do
1002+
[
1003+
MockedCommand.new(
1004+
%(gh pr list --search "head:#{next_release_branch}" --json number --jq ".[].number"),
1005+
stdout: "\n"
1006+
)
1007+
]
1008+
end
1009+
1010+
it 'should return nil' do
1011+
expect(subject).to be_nil
1012+
end
1013+
end
1014+
1015+
context 'when the release PR is 123' do
1016+
let(:project_init_block) { ->(p) { p.next_release_version = '1.0.0' } }
1017+
1018+
let(:mocked_commands) do
1019+
[
1020+
MockedCommand.new(
1021+
'gh pr list --search "head:release-v1.0.0" --json number --jq ".[].number"',
1022+
stdout: "#{release_pr_number}\n"
1023+
)
1024+
]
1025+
end
1026+
1027+
it 'should return "123"' do
1028+
expect(subject).to eq(release_pr_number)
1029+
end
1030+
end
1031+
end
1032+
1033+
describe '#release_pr_url' do
1034+
subject { project.release_pr_url }
1035+
1036+
let(:release_pr_number) { '123' }
1037+
let(:remote_url) { 'https://github.com/org/repo' }
1038+
let(:release_pr_url) { URI.parse("#{remote_url}/pull/#{release_pr_number}") }
1039+
let(:next_release_version) { '1.0.0' }
1040+
let(:next_release_branch) { "release-v#{next_release_version}" }
1041+
1042+
context 'when explicitly set' do
1043+
let(:project_init_block) { ->(p) { p.release_pr_url = release_pr_url } }
1044+
it { is_expected.to eq(release_pr_url) }
1045+
end
1046+
1047+
context 'when there is not release PR' do
1048+
let(:project_init_block) do
1049+
lambda do |p|
1050+
p.remote_url = remote_url
1051+
p.next_release_version = next_release_version
1052+
end
1053+
end
1054+
1055+
let(:mocked_commands) do
1056+
[
1057+
MockedCommand.new(
1058+
%(gh pr list --search "head:#{next_release_branch}" --json number --jq ".[].number"),
1059+
stdout: "\n"
1060+
)
1061+
]
1062+
end
1063+
1064+
it { is_expected.to be_nil }
1065+
end
1066+
1067+
context 'when the release PR is 123' do
1068+
let(:project_init_block) do
1069+
lambda do |p|
1070+
p.remote_url = remote_url
1071+
p.next_release_version = next_release_version
1072+
end
1073+
end
1074+
1075+
let(:mocked_commands) do
1076+
[
1077+
MockedCommand.new(
1078+
%(gh pr list --search "head:#{next_release_branch}" --json number --jq ".[].number"),
1079+
stdout: "#{release_pr_number}\n"
1080+
)
1081+
]
1082+
end
1083+
1084+
it { is_expected.to eq(release_pr_url) }
1085+
end
1086+
end
1087+
9841088
describe '#to_s' do
9851089
subject { project.to_s }
9861090

@@ -991,7 +1095,8 @@
9911095
MockedCommand.new('git show --format=format:%aI --quiet "v1.0.0"', stdout: "2023-02-01 00:00:00 -0800\n"),
9921096
MockedCommand.new('semverify current', stdout: "0.1.0\n"),
9931097
MockedCommand.new("git remote get-url 'origin'", stdout: "https://github.com/org/repo.git\n"),
994-
MockedCommand.new('git tag --list "v1.0.0"', stdout: "v1.0.0\n")
1098+
MockedCommand.new('git tag --list "v1.0.0"', stdout: "v1.0.0\n"),
1099+
MockedCommand.new('gh pr list --search "head:release-v1.0.0" --json number --jq ".[].number"', stdout: "123\n")
9951100
]
9961101
end
9971102

@@ -1011,6 +1116,9 @@
10111116
remote_base_url: https://github.com/
10121117
remote_repository: org/repo
10131118
remote_url: https://github.com/org/repo
1119+
release_pr_number: 123
1120+
release_pr_url: https://github.com/org/repo/pull/123
1121+
changelog_path: CHANGELOG.md
10141122
verbose?: false
10151123
quiet?: false
10161124
EXPECTED_RESULT

0 commit comments

Comments
 (0)