Class: Releasinator::GitHubRepo

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ GitHubRepo

Returns a new instance of GitHubRepo.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/github_repo.rb', line 9

def initialize(url)
  @url = url
  if url.start_with?("https")
    # https: "https://github.com/braebot/test.git"
    slash_split = url.split("/")
    @domain = slash_split[2]
    @repo = slash_split.last.split(".git").first
    slash_split.pop
    @org = slash_split.last
  else
    # ssh: [email protected]:braebot/test.git"
    colon_split = url.split(":")
    at_split = colon_split.first.split("@")
    @domain = at_split.last
    slash_split = colon_split.last.split("/")
    @org = slash_split.first
    @repo = slash_split.last.split(".git").first
  end

  @url.freeze
  @org.freeze
  @repo.freeze
  @domain.freeze

  if @domain == "github.com"
    check_token("GITHUB_TOKEN")
    @client = Octokit::Client.new(:access_token => ENV["GITHUB_TOKEN"])
  else
    env_key = "#{@domain.gsub(".", "_").upcase}_GITHUB_TOKEN"
    check_token(env_key)
    @client = Octokit::Client.new(:access_token => ENV[env_key], :api_endpoint => "https://#{@domain}/api/v3/")
  end
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



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

def client
  @client
end

#domainObject (readonly)

Returns the value of attribute domain.



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

def domain
  @domain
end

#orgObject (readonly)

Returns the value of attribute org.



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

def org
  @org
end

#repoObject (readonly)

Returns the value of attribute repo.



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

def repo
  @repo
end

#urlObject (readonly)

Returns the value of attribute url.



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

def url
  @url
end

Instance Method Details

#check_token(token_param) ⇒ Object



43
44
45
46
47
48
# File 'lib/github_repo.rb', line 43

def check_token(token_param)
  if !ENV[token_param]
    Printer.fail("#{token_param} environment variable required.  Please set this to your personal access token.")
    abort()
  end 
end