Skip to content

Commit 6b0e295

Browse files
authored
Delete the release in GitHub and add a comment to the release PR (#52)
1 parent 87fc080 commit 6b0e295

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

exe/revert-github-release

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class Options
1919
def release_tag = @release_tag ||= "v#{release_version}"
2020
def release_branch = @release_branch ||= "release-#{release_tag}"
2121
def current_branch = @current_branch ||= `git rev-parse --abbrev-ref HEAD`.chomp
22+
def release_pr = @release_pr ||= `gh pr list --search "head:#{release_branch}" --json number --jq ".[].number"`.chomp
2223
def remote = @remote ||= 'origin'
2324
end
2425

@@ -79,6 +80,8 @@ class Parser
7980
Usage:
8081
#{File.basename($PROGRAM_NAME)} [--help | --version]
8182
83+
Version #{CreateGithubRelease::VERSION}
84+
8285
This script reverts the effect of running the create-github-release script.
8386
It must be run in the root directory of the work tree with the release
8487
branch checked out (which is the state create-github-release leaves you in).
@@ -139,6 +142,16 @@ def ref_exists?(name)
139142
$CHILD_STATUS.success?
140143
end
141144

145+
def revert_release!(options)
146+
`gh pr comment #{options.release_pr} --body="Reverting this release using revert-github-release"`
147+
`git checkout #{options.default_branch} >/dev/null`
148+
`git branch -D #{options.release_branch} >/dev/null`
149+
`git tag -d #{options.release_tag} >/dev/null`
150+
`git push #{options.remote} --delete #{options.release_branch} >/dev/null`
151+
`git push #{options.remote} --delete #{options.release_tag} >/dev/null`
152+
`gh release delete #{options.release_tag} --yes >/dev/null`
153+
end
154+
142155
unless in_work_tree? && in_root_directory?
143156
warn 'ERROR: Not in the root directory of a Git work tree'
144157
exit 1
@@ -157,10 +170,6 @@ unless ref_exists?(options.default_branch)
157170
exit 1
158171
end
159172

160-
`git checkout #{options.default_branch} >/dev/null`
161-
`git branch -D #{options.release_branch} >/dev/null`
162-
`git tag -d #{options.release_tag} >/dev/null`
163-
`git push #{options.remote} --delete #{options.release_branch} >/dev/null`
164-
`git push #{options.remote} --delete #{options.release_tag} >/dev/null`
173+
revert_release!(options)
165174

166175
puts "Reverted release #{options.release_version}"

0 commit comments

Comments
 (0)