Class: Harvest::Vcs

Inherits:
Object
  • Object
show all
Defined in:
lib/harvest/vcs.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_code) ⇒ Vcs

Returns a new instance of Vcs.



11
12
13
14
# File 'lib/harvest/vcs.rb', line 11

def initialize(project_code)
  @project_code = project_code
  @current_branch = git_command_for_current_branch[0..-2]
end

Instance Attribute Details

#current_branchObject (readonly)

Returns the value of attribute current_branch.



3
4
5
# File 'lib/harvest/vcs.rb', line 3

def current_branch
  @current_branch
end

#project_codeObject (readonly)

Returns the value of attribute project_code.



3
4
5
# File 'lib/harvest/vcs.rb', line 3

def project_code
  @project_code
end

Class Method Details

.current_projectObject



5
6
7
8
9
# File 'lib/harvest/vcs.rb', line 5

def self.current_project
  remote_url = `git config --local remote.origin.url`.strip

  URI(remote_url).path.split('/').last.gsub('.git', '')
end

Instance Method Details

#ticket_idObject



16
17
18
19
20
21
22
# File 'lib/harvest/vcs.rb', line 16

def ticket_id
  branch_names = current_branch.gsub(/[^0-9a-z]/i, ' ').split
  
  return nil if branch_names.index(project_code).nil?
  
  branch_names[branch_names.index(project_code)+1]
end