Class: Renegade::BranchName

Inherits:
Object
  • Object
show all
Defined in:
lib/renegade/branch_name.rb

Overview

Verify branch name

Constant Summary collapse

REGEX_STORY_BRANCH =
/^(?:story)-(\d{4,6})-?(.*)?$/
REGEX_BUG_BRANCH =
/^(?:bug)-(\d{4,6})-?(.*)?$/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBranchName

Returns a new instance of BranchName.



12
13
14
15
16
17
18
# File 'lib/renegade/branch_name.rb', line 12

def initialize
  # Instance variables
  @label = 'Branch Name'
  @warnings = []
  @errors = []
  @warning = 'Branches must start with bug-##### or story-#####.'
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



7
8
9
# File 'lib/renegade/branch_name.rb', line 7

def errors
  @errors
end

#warningObject (readonly)

Returns the value of attribute warning.



7
8
9
# File 'lib/renegade/branch_name.rb', line 7

def warning
  @warning
end

#warningsObject (readonly)

Returns the value of attribute warnings.



7
8
9
# File 'lib/renegade/branch_name.rb', line 7

def warnings
  @warnings
end

Class Method Details

.extract_id(branch_name) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/renegade/branch_name.rb', line 26

def self.extract_id(branch_name)
  data = {}
  if REGEX_STORY_BRANCH.match(branch_name)
    data['type'] = 'story'
    data['id'] = REGEX_STORY_BRANCH.match(branch_name)[1]
  elsif REGEX_BUG_BRANCH.match(branch_name)
    data['type'] = 'bug'
    data['id'] = REGEX_BUG_BRANCH.match(branch_name)[1]
  end

  data
end

Instance Method Details

#check_branch_name(branch_name) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/renegade/branch_name.rb', line 39

def check_branch_name(branch_name)
  if REGEX_STORY_BRANCH.match(branch_name) ||
     REGEX_BUG_BRANCH.match(branch_name) ||
     branch_name == 'master'
    # placeholder
    return true
  else
    @warnings.push(@warning)
    @warnings.push('You may continue to develop in this branch, but you'\
      ' will not be allowed to merge unless you rename it.')
    return false
  end
end

#run(branch_name) ⇒ Object



20
21
22
23
24
# File 'lib/renegade/branch_name.rb', line 20

def run(branch_name)
  # branch_name = `git name-rev --name-only HEAD`

  Status.report(@label, check_branch_name(branch_name), true)
end