Class: MrBump::GitConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/mr_bump/git_config.rb

Overview

This class gathers configuration infromation from git

Constant Summary collapse

GITHUB_URL_REGEX =
Regexp.new(
  '(https?://((?<user>[\w_\-\d]+)@)?|git@)(?<domain>github.com)[:/](?<path>[\w_\-\d]+)/' \
  '(?<repo_name>[\w_\-\d\.]+?)(\.git)?$'
).freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo_name, repo_host, repo_path, username, user) ⇒ GitConfig

Returns a new instance of GitConfig.



14
15
16
17
18
19
20
21
# File 'lib/mr_bump/git_config.rb', line 14

def initialize(repo_name, repo_host, repo_path, username, user)
  @repo_name = repo_name
  @repo_url = repo_host + '/' + repo_path + '/'
  @host = repo_host
  @path = repo_path
  @username = username
  @user = user || `git config user.name`
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



8
9
10
# File 'lib/mr_bump/git_config.rb', line 8

def host
  @host
end

#orginObject (readonly)

Returns the value of attribute orgin.



8
9
10
# File 'lib/mr_bump/git_config.rb', line 8

def orgin
  @orgin
end

#pathObject (readonly)

Returns the value of attribute path.



8
9
10
# File 'lib/mr_bump/git_config.rb', line 8

def path
  @path
end

#repo_nameObject (readonly)

Returns the value of attribute repo_name.



8
9
10
# File 'lib/mr_bump/git_config.rb', line 8

def repo_name
  @repo_name
end

#repo_urlObject (readonly)

Returns the value of attribute repo_url.



8
9
10
# File 'lib/mr_bump/git_config.rb', line 8

def repo_url
  @repo_url
end

#userObject (readonly)

Returns the value of attribute user.



8
9
10
# File 'lib/mr_bump/git_config.rb', line 8

def user
  @user
end

#usernameObject (readonly)

Returns the value of attribute username.



8
9
10
# File 'lib/mr_bump/git_config.rb', line 8

def username
  @username
end

Class Method Details

.from_current_pathObject



31
32
33
# File 'lib/mr_bump/git_config.rb', line 31

def self.from_current_path
  from_origin(`git remote get-url origin`.strip)
end

.from_origin(origin, user = nil) ⇒ Object

Raises:

  • (ArgumentError)


23
24
25
26
27
28
29
# File 'lib/mr_bump/git_config.rb', line 23

def self.from_origin(origin, user = nil)
  match = GITHUB_URL_REGEX.match(origin)
  raise ArgumentError,
        "Couldn't parse needed information from remote url '#{git_url}'" unless match
  GitConfig.new(match['repo_name'], "https://#{match['domain']}",
                "#{match['path']}/#{match['repo_name']}", match['user'], user)
end

Instance Method Details

#get_sha(pattern) ⇒ Object



43
44
45
# File 'lib/mr_bump/git_config.rb', line 43

def get_sha(pattern)
  `git log --grep=#{pattern} --merges --format=format:%H`.split("\n").first
end

#user_iconObject



35
36
37
# File 'lib/mr_bump/git_config.rb', line 35

def user_icon
  'https://avatars.githubusercontent.com/' + username if username
end


39
40
41
# File 'lib/mr_bump/git_config.rb', line 39

def user_link
  'https://github.com/' + username if username
end