Class: MrBump::GitConfig
- Inherits:
-
Object
- Object
- MrBump::GitConfig
- 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
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#orgin ⇒ Object
readonly
Returns the value of attribute orgin.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#repo_name ⇒ Object
readonly
Returns the value of attribute repo_name.
-
#repo_url ⇒ Object
readonly
Returns the value of attribute repo_url.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Class Method Summary collapse
Instance Method Summary collapse
- #get_sha(pattern) ⇒ Object
-
#initialize(repo_name, repo_host, repo_path, username, user) ⇒ GitConfig
constructor
A new instance of GitConfig.
- #user_icon ⇒ Object
- #user_link ⇒ Object
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
#host ⇒ Object (readonly)
Returns the value of attribute host.
8 9 10 |
# File 'lib/mr_bump/git_config.rb', line 8 def host @host end |
#orgin ⇒ Object (readonly)
Returns the value of attribute orgin.
8 9 10 |
# File 'lib/mr_bump/git_config.rb', line 8 def orgin @orgin end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
8 9 10 |
# File 'lib/mr_bump/git_config.rb', line 8 def path @path end |
#repo_name ⇒ Object (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_url ⇒ Object (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 |
#user ⇒ Object (readonly)
Returns the value of attribute user.
8 9 10 |
# File 'lib/mr_bump/git_config.rb', line 8 def user @user end |
#username ⇒ Object (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_path ⇒ Object
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
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_icon ⇒ Object
35 36 37 |
# File 'lib/mr_bump/git_config.rb', line 35 def user_icon 'https://avatars.githubusercontent.com/' + username if username end |
#user_link ⇒ Object
39 40 41 |
# File 'lib/mr_bump/git_config.rb', line 39 def user_link 'https://github.com/' + username if username end |