Sha256: 721aaef3011f5819a53895d95bd586b99bc292e92417dfd9392528dbb5b65e8b

Contents?: true

Size: 923 Bytes

Versions: 11

Compression:

Stored size: 923 Bytes

Contents

require 'git_tracker/branch'
require 'git_tracker/commit_message'

module GitTracker
  class PrepareCommitMessage
    attr_reader :file, :source, :commit_sha

    def self.run(file, source=nil, commit_sha=nil)
      new(file, source, commit_sha).run
    end

    def initialize(file, source=nil, commit_sha=nil)
      @file = file
      @source = source
      @commit_sha = commit_sha
    end

    def run
      exit_when_commit_exists

      story = story_number_from_branch
      message = CommitMessage.new(file)
      exit if message.mentions_story?(story)
      keyword = message.keyword

      message_addition = [keyword, "##{story}"].compact.join(' ')
      message.append("[#{message_addition}]")
    end

    private

    def exit_when_commit_exists
      exit if source == 'commit'
    end

    def story_number_from_branch
      story = Branch.story_number
      exit unless story
      story
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
git_tracker-2.0.0 lib/git_tracker/prepare_commit_message.rb
git_tracker-1.6.3 lib/git_tracker/prepare_commit_message.rb
git_tracker-1.6.2 lib/git_tracker/prepare_commit_message.rb
git_tracker-1.6.1 lib/git_tracker/prepare_commit_message.rb
git_tracker-1.6.0 lib/git_tracker/prepare_commit_message.rb
git_tracker-1.5.1 lib/git_tracker/prepare_commit_message.rb
git_tracker-1.5.0 lib/git_tracker/prepare_commit_message.rb
git_tracker-1.4.0 lib/git_tracker/prepare_commit_message.rb
git_tracker-1.3.1 lib/git_tracker/prepare_commit_message.rb
git_tracker-1.3.0 lib/git_tracker/prepare_commit_message.rb
git_tracker-1.2.0 lib/git_tracker/prepare_commit_message.rb