Class: Octopolo::DatedBranchCreator
- Inherits:
-
Object
- Object
- Octopolo::DatedBranchCreator
- Includes:
- CLIWrapper, ConfigWrapper, GitWrapper
- Defined in:
- lib/octopolo/dated_branch_creator.rb
Constant Summary collapse
- InvalidBranchType =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#branch_type ⇒ Object
Returns the value of attribute branch_type.
-
#should_delete_old_branches ⇒ Object
Returns the value of attribute should_delete_old_branches.
Attributes included from GitWrapper
Attributes included from CLIWrapper
Attributes included from ConfigWrapper
Class Method Summary collapse
-
.perform(branch_type, should_delete_old_branches = false) ⇒ Object
Public: Create a new branch of the given type for today’s date.
Instance Method Summary collapse
-
#branch_name ⇒ Object
Public: The name of the branch to create.
-
#create_branch ⇒ Object
Public: Create the desired branch.
-
#date_suffix ⇒ Object
Public: The date suffix to append to the branch name.
-
#delete_old_branches ⇒ Object
Public: If necessary, and if user opts to, delete old branches of its type.
-
#extra_branches ⇒ Object
Public: The list of extra branches that exist after creating the new branch.
-
#initialize(branch_type, should_delete_old_branches = false) ⇒ DatedBranchCreator
constructor
Public: Initialize a new instance of DatedBranchCreator.
-
#perform ⇒ Object
Public: Create the branch and handle related processing.
Constructor Details
#initialize(branch_type, should_delete_old_branches = false) ⇒ DatedBranchCreator
Public: Initialize a new instance of DatedBranchCreator
branch_type - Name of the type of branch (e.g., staging or deployable) should_delete_old_branches - Flag to delete old branches of the given type.
18 19 20 21 |
# File 'lib/octopolo/dated_branch_creator.rb', line 18 def initialize(branch_type, should_delete_old_branches=false) self.branch_type = branch_type self.should_delete_old_branches = should_delete_old_branches end |
Instance Attribute Details
#branch_type ⇒ Object
Returns the value of attribute branch_type.
11 12 13 |
# File 'lib/octopolo/dated_branch_creator.rb', line 11 def branch_type @branch_type end |
#should_delete_old_branches ⇒ Object
Returns the value of attribute should_delete_old_branches.
12 13 14 |
# File 'lib/octopolo/dated_branch_creator.rb', line 12 def should_delete_old_branches @should_delete_old_branches end |
Class Method Details
.perform(branch_type, should_delete_old_branches = false) ⇒ Object
Public: Create a new branch of the given type for today’s date
branch_type - Name of the type of branch (e.g., staging or deployable) should_delete_old_branches - Flag to delete old branches of the given type.
Returns a DatedBranchCreator
29 30 31 32 33 |
# File 'lib/octopolo/dated_branch_creator.rb', line 29 def self.perform(branch_type, should_delete_old_branches=false) new(branch_type, should_delete_old_branches).tap do |creator| creator.perform end end |
Instance Method Details
#branch_name ⇒ Object
Public: The name of the branch to create
52 53 54 55 56 57 58 59 |
# File 'lib/octopolo/dated_branch_creator.rb', line 52 def branch_name case branch_type when Git::DEPLOYABLE_PREFIX, Git::STAGING_PREFIX, Git::QAREADY_PREFIX "#{branch_type}.#{date_suffix}" else raise InvalidBranchType, "'#{branch_type}' is not a valid branch type" end end |
#create_branch ⇒ Object
Public: Create the desired branch
42 43 44 |
# File 'lib/octopolo/dated_branch_creator.rb', line 42 def create_branch git.new_branch(branch_name, config.deploy_branch) end |
#date_suffix ⇒ Object
Public: The date suffix to append to the branch name
47 48 49 |
# File 'lib/octopolo/dated_branch_creator.rb', line 47 def date_suffix Date.today.strftime("%Y.%m.%d") end |
#delete_old_branches ⇒ Object
Public: If necessary, and if user opts to, delete old branches of its type
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/octopolo/dated_branch_creator.rb', line 62 def delete_old_branches return unless extra_branches.any? should_delete = should_delete_old_branches || cli.ask_boolean("Do you want to delete the old #{branch_type} branch(es)? (#{extra_branches.join(", ")})") if should_delete extra_branches.each do |extra| Git.delete_branch(extra) end end end |
#extra_branches ⇒ Object
Public: The list of extra branches that exist after creating the new branch
Returns an Array of Strings of the branch names
76 77 78 79 80 81 82 83 |
# File 'lib/octopolo/dated_branch_creator.rb', line 76 def extra_branches case branch_type when Git::DEPLOYABLE_PREFIX, Git::STAGING_PREFIX, Git::QAREADY_PREFIX Git.branches_for(branch_type) - [branch_name] else raise InvalidBranchType, "'#{branch_type}' is not a valid branch type" end end |
#perform ⇒ Object
Public: Create the branch and handle related processing
36 37 38 39 |
# File 'lib/octopolo/dated_branch_creator.rb', line 36 def perform create_branch delete_old_branches end |