Class: Abak::Flow::Branch

Inherits:
Object
  • Object
show all
Defined in:
lib/abak-flow/branch.rb

Constant Summary collapse

FOLDER_HOTFIX =
"hotfix".freeze
FOLDER_FEATURE =
"feature".freeze
TASK_FORMAT =
'\w+\-\d{1,}'.freeze
MAGICK_WORDS =
%w{close closes closed fix fixes fixed
resolve resolves resolved}.freeze
DEVELOPMENT =
"develop".freeze
MASTER =
"master".freeze
MAPPING =
{
  FOLDER_HOTFIX  => MASTER,
  FOLDER_FEATURE => DEVELOPMENT
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(branch) ⇒ Branch

Returns a new instance of Branch.



22
23
24
25
26
27
28
# File 'lib/abak-flow/branch.rb', line 22

def initialize(branch)
  @manager = Manager.instance
  @branch = branch.is_a?(Git::Branch) ? branch
                                      : @manager.git.branch(branch)

  parse_branch_name
end

Instance Attribute Details

#folderObject (readonly)

Returns the value of attribute folder.



19
20
21
# File 'lib/abak-flow/branch.rb', line 19

def folder
  @folder
end

#taskObject (readonly)

Returns the value of attribute task.



20
21
22
# File 'lib/abak-flow/branch.rb', line 20

def task
  @task
end

Instance Method Details



45
46
47
48
49
50
51
52
53
# File 'lib/abak-flow/branch.rb', line 45

def compare_link(branch)
  diff = "#{@manager.repository.upstream.owner}:#{branch}...#{@branch}"

  File.join [
    @manager.github.web_endpoint,
    @manager.repository.origin.to_s,
    "compare", diff
  ]
end

#current?Boolean

Returns:

  • (Boolean)


112
113
114
# File 'lib/abak-flow/branch.rb', line 112

def current?
  @branch.current
end

#delete_on_localObject



84
85
86
# File 'lib/abak-flow/branch.rb', line 84

def delete_on_local
  @branch.delete
end

#delete_on_remoteObject



79
80
81
82
# File 'lib/abak-flow/branch.rb', line 79

def delete_on_remote
  origin = @manager.repository.origin.repo
  @manager.git.push(origin, ":#{@branch}")
end

#develop?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/abak-flow/branch.rb', line 88

def develop?
  name == DEVELOPMENT
end

#extract_base_name(options = Hash.new) ⇒ Object



55
56
57
58
# File 'lib/abak-flow/branch.rb', line 55

def extract_base_name(options = Hash.new)
  mappable? ? MAPPING[folder]
            : options.fetch(:if_undef, name)
end

#extract_bodyObject

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



66
67
68
69
70
71
72
# File 'lib/abak-flow/branch.rb', line 66

def extract_body
  return I18n.t("commands.publish.nothing") if
    tasks_from_commit_message.empty? && !tracker_task?

  [tasks_from_commit_message, task].flatten.uniq
    .map { |x| "http://jira.railsc.ru/browse/#{x}" } * "\n"
end

#extract_titleObject



60
61
62
63
# File 'lib/abak-flow/branch.rb', line 60

def extract_title
  tracker_task? ? task
                : message
end

#feature?Boolean

Returns:

  • (Boolean)


100
101
102
# File 'lib/abak-flow/branch.rb', line 100

def feature?
  folder == FOLDER_FEATURE
end

#hotfix?Boolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/abak-flow/branch.rb', line 96

def hotfix?
  folder == FOLDER_HOTFIX
end

#mappable?Boolean

Returns:

  • (Boolean)


108
109
110
# File 'lib/abak-flow/branch.rb', line 108

def mappable?
  hotfix? || feature?
end

#master?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/abak-flow/branch.rb', line 92

def master?
  name == MASTER
end

#messageObject



34
35
36
37
38
39
# File 'lib/abak-flow/branch.rb', line 34

def message
  content = @branch.gcommit.message.split("\n", 2).first
  return content if content.length < 72

  content[0...72] << "..."
end

#nameObject



30
31
32
# File 'lib/abak-flow/branch.rb', line 30

def name
  @branch.full
end

#to_sObject



41
42
43
# File 'lib/abak-flow/branch.rb', line 41

def to_s
  @branch.to_s
end

#tracker_task?Boolean

Returns:

  • (Boolean)


104
105
106
# File 'lib/abak-flow/branch.rb', line 104

def tracker_task?
  !(task =~ /^#{TASK_FORMAT}$/).nil?
end

#updateObject



74
75
76
77
# File 'lib/abak-flow/branch.rb', line 74

def update
  origin = @manager.repository.origin.repo
  @manager.git.push(origin, @branch)
end

#valid?Boolean

Returns:

  • (Boolean)


116
117
118
# File 'lib/abak-flow/branch.rb', line 116

def valid?
  !@branch.name.empty?
end