class Abak::Flow::Branch

Constants

DEVELOPMENT
FOLDER_FEATURE
FOLDER_HOTFIX
MAGICK_WORDS
MAPPING
MASTER
TASK_FORMAT

Attributes

folder[R]
task[R]

Public Class Methods

new(branch) click to toggle source
# File lib/abak-flow/branch.rb, line 22
def initialize(branch)
  @branch = branch.is_a?(Git::Branch) ? branch
                                      : Manager.git.branch(branch)

  parse_branch_name
end

Public Instance Methods

current?() click to toggle source
# File lib/abak-flow/branch.rb, line 111
def current?
  @branch.current
end
delete_on_local() click to toggle source
# File lib/abak-flow/branch.rb, line 83
def delete_on_local
  @branch.delete
end
delete_on_remote() click to toggle source
# File lib/abak-flow/branch.rb, line 78
def delete_on_remote
  origin = Manager.repository.origin.repo
  Manager.git.push(origin, ":#{@branch}")
end
develop?() click to toggle source
# File lib/abak-flow/branch.rb, line 87
def develop?
  name == DEVELOPMENT
end
extract_base_name(options = Hash.new) click to toggle source
# File lib/abak-flow/branch.rb, line 54
def extract_base_name(options = Hash.new)
  mappable? ? MAPPING[folder]
            : options.fetch(:if_undef, name)
end
extract_body() click to toggle source

TODO : Сделать настраевыемым трекер и формат задачи

# File lib/abak-flow/branch.rb, line 65
def extract_body
  return I18n.t("abak.flow.commands.publish.words.nothing") if
    tasks_from_commit_message.empty? && !tracker_task?

  [tasks_from_commit_message, task].flatten.compact.uniq
    .map { |x| "http://jira.railsc.ru/browse/#{x}" } * "\n"
end
extract_title() click to toggle source
# File lib/abak-flow/branch.rb, line 59
def extract_title
  tracker_task? ? task
                : message
end
feature?() click to toggle source
# File lib/abak-flow/branch.rb, line 99
def feature?
  folder == FOLDER_FEATURE
end
hotfix?() click to toggle source
# File lib/abak-flow/branch.rb, line 95
def hotfix?
  folder == FOLDER_HOTFIX
end
mappable?() click to toggle source
# File lib/abak-flow/branch.rb, line 107
def mappable?
  hotfix? || feature?
end
master?() click to toggle source
# File lib/abak-flow/branch.rb, line 91
def master?
  name == MASTER
end
message() click to toggle source
# File lib/abak-flow/branch.rb, line 33
def message
  content = @branch.gcommit.message.split("\n", 2).first
  return content if content.length < 72

  content[0...72] << "..."
end
name() click to toggle source
# File lib/abak-flow/branch.rb, line 29
def name
  @branch.full
end
to_s() click to toggle source
# File lib/abak-flow/branch.rb, line 40
def to_s
  @branch.to_s
end
tracker_task?() click to toggle source
# File lib/abak-flow/branch.rb, line 103
def tracker_task?
  !(task =~ /^#{TASK_FORMAT}$/).nil?
end
update() click to toggle source
# File lib/abak-flow/branch.rb, line 73
def update
  origin = Manager.repository.origin.repo
  Manager.git.push(origin, @branch)
end
valid?() click to toggle source
# File lib/abak-flow/branch.rb, line 115
def valid?
  !@branch.name.strip.empty?
end

Private Instance Methods

parse_branch_name() click to toggle source
# File lib/abak-flow/branch.rb, line 126
def parse_branch_name
  matches = name.match(/^(?<prefix>.+)\/(?<task>.+)$/)

  @folder, @task = matches.nil? ? [nil, nil]
                                : [matches[:prefix], matches[:task]]
end
tasks_from_commit_message() click to toggle source
# File lib/abak-flow/branch.rb, line 120
def tasks_from_commit_message
  @parsed_tasks ||=
    @branch.gcommit.contents
           .scan(/(?:#{MAGICK_WORDS * "|"})\s+(#{TASK_FORMAT})/i)
end