Skip to content

Commit

Permalink
Refactor assertions (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcouball committed Nov 2, 2022
1 parent 0f3733e commit c3ed55b
Show file tree
Hide file tree
Showing 24 changed files with 400 additions and 285 deletions.
11 changes: 9 additions & 2 deletions lib/create_github_release.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
# frozen_string_literal: true

require 'create_github_release/assertion_base'
require 'create_github_release/assertions'
require 'create_github_release/command_line_parser'

require 'create_github_release/options'

require 'create_github_release/assertion_base'
require 'create_github_release/assertions'
require 'create_github_release/release_assertions'

# require 'create_github_release/task_base'
# require 'create_github_release/tasks'
# require 'create_github_release/release_tasks'

require 'create_github_release/version'

# Main module for this gem
Expand Down
6 changes: 4 additions & 2 deletions lib/create_github_release/assertions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
require_relative 'assertions/in_git_repo'
require_relative 'assertions/in_repo_root_directory'
require_relative 'assertions/local_and_remote_on_same_commit'
require_relative 'assertions/local_release_branch_does_not_exist'
require_relative 'assertions/local_release_tag_does_not_exist'
require_relative 'assertions/no_staged_changes'
require_relative 'assertions/no_uncommitted_changes'
require_relative 'assertions/on_default_branch'
require_relative 'assertions/release_branch_does_not_exist'
require_relative 'assertions/release_tag_does_not_exist'
require_relative 'assertions/remote_release_branch_does_not_exist'
require_relative 'assertions/remote_release_tag_does_not_exist'
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'English'
require 'create_github_release/assertion_base'

module CreateGithubRelease
module Assertions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require 'English'
require 'tmpdir'
require 'create_github_release/assertion_base'

module CreateGithubRelease
module Assertions
Expand Down
1 change: 1 addition & 0 deletions lib/create_github_release/assertions/docker_is_running.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'English'
require 'create_github_release/assertion_base'

module CreateGithubRelease
module Assertions
Expand Down
1 change: 1 addition & 0 deletions lib/create_github_release/assertions/gh_command_exists.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'English'
require 'create_github_release/assertion_base'

module CreateGithubRelease
module Assertions
Expand Down
1 change: 1 addition & 0 deletions lib/create_github_release/assertions/in_git_repo.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'English'
require 'create_github_release/assertion_base'

module CreateGithubRelease
module Assertions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require 'English'
require 'fileutils'
require 'create_github_release/assertion_base'

module CreateGithubRelease
module Assertions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'English'
require 'create_github_release/assertion_base'

module CreateGithubRelease
module Assertions
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# frozen_string_literal: true

require 'English'
require 'create_github_release/assertion_base'

module CreateGithubRelease
module Assertions
# Assert that the release branch does not exist in the local repository
#
# @api public
#
class LocalReleaseBranchDoesNotExist < AssertionBase
# Assert that the release branch does not exist in the local repository
#
# @example
# require 'create_github_release'
#
# options = CreateGithubRelease::Options.new { |o| o.release_type = 'major' }
# assertion = CreateGithubRelease::Assertions::LocalReleaseBranchDoesNotExist.new(options)
# begin
# assertion.assert
# puts 'Assertion passed'
# rescue SystemExit
# puts 'Assertion failed'
# end
#
# @return [void]
#
# @raise [SystemExit] if the assertion fails
#
def assert
print "Checking that local branch ' #{options.branch}' does not exist..."

if `git branch --list '#{options.branch}' | wc -l`.to_i.zero? && $CHILD_STATUS.success?
puts 'OK'
else
error 'Could not list branches' unless $CHILD_STATUS.success?
error "'#{options.branch}' already exists."
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# frozen_string_literal: true

require 'English'
require 'create_github_release/assertion_base'

module CreateGithubRelease
module Assertions
# Assert that the release tag does not exist in the local repository
#
# @api public
#
class LocalReleaseTagDoesNotExist < AssertionBase
# Assert that the release tag does not exist in the local repository
#
# @example
# require 'create_github_release'
#
# options = CreateGithubRelease::Options.new { |o| o.release_type = 'major' }
# assertion = CreateGithubRelease::Assertions::LocalReleaseTagDoesNotExist.new(options)
# begin
# assertion.assert
# puts 'Assertion passed'
# rescue SystemExit
# puts 'Assertion failed'
# end
#
# @return [void]
#
# @raise [SystemExit] if the assertion fails
#
def assert
print "Checking that local tag '#{options.tag}' does not exist..."

tags = `git tag --list "#{options.tag}"`.chomp
error 'Could not list tags' unless $CHILD_STATUS.success?

if tags.split.empty?
puts 'OK'
else
error "Local tag '#{options.tag}' already exists"
end
end
end
end
end
1 change: 1 addition & 0 deletions lib/create_github_release/assertions/no_staged_changes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'English'
require 'create_github_release/assertion_base'

module CreateGithubRelease
module Assertions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'English'
require 'create_github_release/assertion_base'

module CreateGithubRelease
module Assertions
Expand Down
1 change: 1 addition & 0 deletions lib/create_github_release/assertions/on_default_branch.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'English'
require 'create_github_release/assertion_base'

module CreateGithubRelease
module Assertions
Expand Down

This file was deleted.

73 changes: 0 additions & 73 deletions lib/create_github_release/assertions/release_tag_does_not_exist.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# frozen_string_literal: true

require 'English'
require 'create_github_release/assertion_base'

module CreateGithubRelease
module Assertions
# Assert that the release branch does not exist in the remote repository
#
# @api public
#
class RemoteReleaseBranchDoesNotExist < AssertionBase
# Assert that the release branch does not exist in the remote repository
#
# @example
# require 'create_github_release'
#
# options = CreateGithubRelease::Options.new { |o| o.release_type = 'major' }
# assertion = CreateGithubRelease::Assertions::RemoteReleaseBranchDoesNotExist.new(options)
# begin
# assertion.assert
# puts 'Assertion passed'
# rescue SystemExit
# puts 'Assertion failed'
# end
#
# @return [void]
#
# @raise [SystemExit] if the assertion fails
#
def assert
print "Checking that the remote branch '#{options.branch}' does not exist..."
`git ls-remote --heads --exit-code '#{options.remote}' '#{options.branch}' >/dev/null 2>&1`
if $CHILD_STATUS.exitstatus == 2
puts 'OK'
else
error 'Could not list branches' unless $CHILD_STATUS.success?
error "'#{options.branch}' already exists"
end
end
end
end
end
Loading

0 comments on commit c3ed55b

Please sign in to comment.