Class: RepoFactFinder
- Inherits:
-
Object
- Object
- RepoFactFinder
- Defined in:
- lib/ghdeploy/repo_fact_finder.rb
Constant Summary collapse
- URL_PATTERN =
%r{^((http[s]?|ftp):/)?/?([^:/\s]+)((/\w+)*/)([\w\-\.]+[^#?\s]+)(.*)?(#[\w\-]+)?}
Instance Attribute Summary collapse
-
#remote_name ⇒ Object
readonly
Returns the value of attribute remote_name.
Instance Method Summary collapse
- #api_endpoint ⇒ Object
-
#initialize(remote_name) ⇒ RepoFactFinder
constructor
A new instance of RepoFactFinder.
- #repo ⇒ Object
- #token ⇒ Object
Constructor Details
#initialize(remote_name) ⇒ RepoFactFinder
Returns a new instance of RepoFactFinder.
6 7 8 |
# File 'lib/ghdeploy/repo_fact_finder.rb', line 6 def initialize(remote_name) @remote_name = remote_name end |
Instance Attribute Details
#remote_name ⇒ Object (readonly)
Returns the value of attribute remote_name.
10 11 12 |
# File 'lib/ghdeploy/repo_fact_finder.rb', line 10 def remote_name @remote_name end |
Instance Method Details
#api_endpoint ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ghdeploy/repo_fact_finder.rb', line 12 def api_endpoint return @api_endpoint if @api_endpoint url = remote.url if url.start_with?('http') matches = URL_PATTERN.match(url) @api_endpoint = "#{matches[2]}://api.#{matches[3]}" else host = url.split('@').last.split(':').first @api_endpoint = "https://api.#{host}" end @api_endpoint = fix_enterprise_api_endpoint(@api_endpoint) end |
#repo ⇒ Object
25 26 27 28 29 |
# File 'lib/ghdeploy/repo_fact_finder.rb', line 25 def repo return @repo if @repo repo = url.split(%r{/|:}).last(2).join('/') @repo = repo.gsub(/(\.git)$/, '') end |
#token ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ghdeploy/repo_fact_finder.rb', line 31 def token github_host = api_endpoint.gsub(%r{^http[s]?://}, '') if github_host == 'api.github.com' ENV.fetch('GHDEPLOY_TOKEN') else key = github_host .gsub(/[\.\-]/, '_') .upcase .gsub(%r{/API/V3/}, '') ENV.fetch("GHDEPLOY_#{key}_TOKEN") end end |