Sha256: ac2345a2ba27696934adbea0ba81067b666d49e139c029fe155afe14723de405

Contents?: true

Size: 1.23 KB

Versions: 42

Compression:

Stored size: 1.23 KB

Contents

require_relative "../git"
require_relative "../scripts"

module Octopolo
  module Scripts
    class StaleBranches
      include CLIWrapper
      include ConfigWrapper
      include GitWrapper

      attr_accessor :delete
      alias_method :delete?, :delete

      DEFAULT_BRANCHES = %W(HEAD master staging production)

      def initialize(delete=false)
        @delete = delete
      end

      def execute
        if delete?
          delete_stale_branches
        else
          display_stale_branches
        end
      end

      # Private: Display the stale branches in the project
      def display_stale_branches
        stale_branches.each do |branch_name|
          cli.say "* #{branch_name}"
        end
      end
      private :display_stale_branches

      # Private: Delete the stale branches in the project
      def delete_stale_branches
        stale_branches.each do |branch_name|
          git.delete_branch(branch_name)
        end
      end
      private :delete_stale_branches

      # Private: The list of stale branches for the project
      #
      # Returns an Array of Strings
      def stale_branches
        git.stale_branches(config.deploy_branch, config.branches_to_keep)
      end
      private :stale_branches
    end
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
octopolo-0.0.2 lib/octopolo/scripts/stale_branches.rb
octopolo-0.0.1 lib/octopolo/scripts/stale_branches.rb