class Jekyll::GitHubMetadata::RepositoryFinder
Constants
- NoRepositoryError
Attributes
site[R]
Public Class Methods
new(site)
click to toggle source
# File lib/jekyll-github-metadata/repository_finder.rb, line 9 def initialize(site) @site = site end
Public Instance Methods
nwo()
click to toggle source
Public: fetches the repository name with owner to fetch metadata for. In order of precedence, this method uses:
-
the environment variable $PAGES_REPO_NWO
-
‘repository’ variable in the site config
-
the ‘origin’ git remote’s URL
site - the Jekyll::Site being processed
Return the name with owner (e.g. ‘parkr/my-repo’) or raises an error if one cannot be found.
# File lib/jekyll-github-metadata/repository_finder.rb, line 23 def nwo @nwo ||= begin nwo_from_env || \ nwo_from_config || \ nwo_from_git_origin_remote || \ proc do raise NoRepositoryError, "No repo name found. " \ "Specify using PAGES_REPO_NWO environment variables, " \ "'repository' in your configuration, or set up an 'origin' " \ "git remote pointing to your github.com repository." end.call end end
Private Instance Methods
git_remote_url()
click to toggle source
# File lib/jekyll-github-metadata/repository_finder.rb, line 56 def git_remote_url git_remotes.grep(%r!\Aorigin\t!).map do |remote| remote.sub(%r!\Aorigin\t(.*) \([a-z]+\)!, "\\1") end.uniq.first || "" end
git_remotes()
click to toggle source
# File lib/jekyll-github-metadata/repository_finder.rb, line 48 def git_remotes _process, output = Jekyll::Utils::Exec.run("git", "remote", "--verbose") output.to_s.strip.split("\n") rescue Errno::ENOENT => e Jekyll.logger.warn "Not Installed:", e.message [] end
github_remote_regex()
click to toggle source
# File lib/jekyll-github-metadata/repository_finder.rb, line 69 def github_remote_regex github_host_regex = Regexp.escape(Jekyll::GitHubMetadata::Pages.github_hostname) %r!#{github_host_regex}(:|/)([\w-]+)/([\w\.-]+)! end
nwo_from_config()
click to toggle source
# File lib/jekyll-github-metadata/repository_finder.rb, line 43 def nwo_from_config repo = site.config["repository"] repo if repo&.is_a?(String) && repo&.include?("/") end
nwo_from_env()
click to toggle source
# File lib/jekyll-github-metadata/repository_finder.rb, line 39 def nwo_from_env ENV["PAGES_REPO_NWO"] end
nwo_from_git_origin_remote()
click to toggle source
# File lib/jekyll-github-metadata/repository_finder.rb, line 62 def nwo_from_git_origin_remote return unless Jekyll.env == "development" || Jekyll.env == "test" matches = git_remote_url.chomp(".git").match github_remote_regex matches[2..3].join("/") if matches end