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
# 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

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



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

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)


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

def current?
  @branch.current
end

#delete_on_localObject



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

def delete_on_local
  @branch.delete
end

#delete_on_remoteObject



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

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

#develop?Boolean

Returns:

  • (Boolean)


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

def develop?
  name == DEVELOPMENT
end

#extract_base_name(options = Hash.new) ⇒ Object



54
55
56
57
# 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_bodyObject

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



65
66
67
68
69
70
71
# 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_titleObject



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

def extract_title
  tracker_task? ? task
                : message
end

#feature?Boolean

Returns:

  • (Boolean)


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

def feature?
  folder == FOLDER_FEATURE
end

#hotfix?Boolean

Returns:

  • (Boolean)


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

def hotfix?
  folder == FOLDER_HOTFIX
end

#mappable?Boolean

Returns:

  • (Boolean)


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

def mappable?
  hotfix? || feature?
end

#master?Boolean

Returns:

  • (Boolean)


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

def master?
  name == MASTER
end

#messageObject



33
34
35
36
37
38
# 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

#nameObject



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

def name
  @branch.full
end

#to_sObject



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

def to_s
  @branch.to_s
end

#tracker_task?Boolean

Returns:

  • (Boolean)


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

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

#updateObject



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

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

#valid?Boolean

Returns:

  • (Boolean)


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

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