diff --git a/lib/jekyll-github-metadata/repository_finder.rb b/lib/jekyll-github-metadata/repository_finder.rb index 88d32d1..cd7c8c7 100644 --- a/lib/jekyll-github-metadata/repository_finder.rb +++ b/lib/jekyll-github-metadata/repository_finder.rb @@ -61,9 +61,14 @@ def git_remote_url def nwo_from_git_origin_remote return unless Jekyll.env == "development" || Jekyll.env == "test" - matches = git_remote_url.chomp(".git").match %r!github.com(:|/)([\w-]+)/([\w\.-]+)! + matches = git_remote_url.chomp(".git").match github_remote_regex matches[2..3].join("/") if matches end + + def github_remote_regex + github_host_regex = Regexp.escape(Jekyll::GitHubMetadata::Pages.github_hostname) + %r!#{github_host_regex}(:|/)([\w-]+)/([\w\.-]+)! + end end end end diff --git a/spec/repository_finder_spec.rb b/spec/repository_finder_spec.rb index 736d750..4ccb10b 100644 --- a/spec/repository_finder_spec.rb +++ b/spec/repository_finder_spec.rb @@ -76,6 +76,15 @@ expect(subject.send(:nwo_from_git_origin_remote)).to include("afeld/hackerhours.org") end + it "handles private github instance addresses" do + allow(Jekyll::GitHubMetadata::Pages).to receive(:github_hostname).and_return "github.myorg.com" + allow(subject).to receive(:git_remote_url).and_return <<-EOS + origin https://github.myorg.com/myorg/myrepo.git (fetch) + origin https://github.myorg.com/myorg/myrepo.git (push) + EOS + expect(subject.send(:nwo_from_git_origin_remote)).to include("myorg/myrepo") + end + context "when git doesn't exist" do before(:each) do @old_path = ENV["PATH"]