class Codeowners::Config

Connfigure and manage the git config file.

Public Class Methods

new(git = AnonymousGit.new) click to toggle source
# File lib/codeowners/config.rb, line 31
def initialize(git = AnonymousGit.new)
  @git = git
end

Public Instance Methods

default_organization() click to toggle source
# File lib/codeowners/config.rb, line 43
def default_organization
  config_org = @git.config('user.organization')
  return config_org.strip unless config_org.nil? || config_org.strip.empty?

  parse_organization_from_origin || ''
end
default_organization=(name) click to toggle source
# File lib/codeowners/config.rb, line 50
def default_organization=(name)
  @git.config('user.organization', name)
end
default_owner() click to toggle source
# File lib/codeowners/config.rb, line 35
def default_owner
  @git.config('user.owner')
end
default_owner=(name) click to toggle source
# File lib/codeowners/config.rb, line 39
def default_owner=(name)
  @git.config('user.owner', name)
end
to_h() click to toggle source
# File lib/codeowners/config.rb, line 54
def to_h
  {
    default_owner: default_owner,
    default_organization: default_organization
  }
end

Protected Instance Methods

parse_organization_from_origin() click to toggle source
# File lib/codeowners/config.rb, line 63
def parse_organization_from_origin
  origin_url = @git.config('remote.origin.url')
  return if origin_url.nil? || origin_url.strip.empty?

  org_regexp = origin_url.match(%r{^https?://.+?/(?<org>.+?)/|:(?<org>.+?)/})
  return if org_regexp.nil? || org_regexp[:org].strip.empty?

  org_regexp[:org].strip
end