Sha256: ba86de65ba8c0a283c38d0d1ea5ceb2beb5aeb911da81a60a405347ae1d9b924

Contents?: true

Size: 1.65 KB

Versions: 6

Compression:

Stored size: 1.65 KB

Contents

require "date" # necessary to get the Date.today convenience method
require_relative "../scripts"
require_relative "../changelog"

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

      attr_accessor :suffix
      attr_accessor :force
      alias_method :force?, :force

      TIMESTAMP_FORMAT = "%Y.%m.%d.%H.%M"

      def self.execute(suffix=nil, force=false)
        new(suffix, force).execute
      end

      def initialize(suffix=nil, force=false)
        @suffix = suffix
        @force = force
      end

      def execute
        if should_create_branch?
          update_changelog
          tag_release
        else
          raise Octopolo::WrongBranch.new("Must perform this script from the deploy branch (#{config.deploy_branch})")
        end
      end

      # Public: Whether to create a new branch
      #
      # Returns a Boolean
      def should_create_branch?
        force? || (git.current_branch == config.deploy_branch)
      end

      # Public: Generate a tag for the current release
      def tag_release
        git.new_tag tag_name
      end

      # Public: The name to apply to the new tag
      def tag_name
        @tag_name ||= %Q(#{Time.now.strftime(TIMESTAMP_FORMAT)}#{"_#{suffix}" if suffix})
      end

      def changelog
        @changelog ||= Changelog.new
      end

      def update_changelog
        changelog.open do |log|
          log.puts "#### #{tag_name}"
        end
        git.perform("add #{changelog.filename}")
        git.perform("commit -m 'Updating Changelog for #{tag_name}'")
      end

    end
  end

  WrongBranch = Class.new(StandardError)
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
octopolo-0.1.3 lib/octopolo/scripts/tag_release.rb
octopolo-0.1.2 lib/octopolo/scripts/tag_release.rb
octopolo-0.1.1 lib/octopolo/scripts/tag_release.rb
octopolo-0.1.0 lib/octopolo/scripts/tag_release.rb
octopolo-0.0.2 lib/octopolo/scripts/tag_release.rb
octopolo-0.0.1 lib/octopolo/scripts/tag_release.rb