From 2b342ec8c2a4cb0065d524441079d06450f507bd Mon Sep 17 00:00:00 2001 From: Mark Crossfield Date: Wed, 12 Dec 2018 17:38:02 +0000 Subject: [PATCH] Fix #120 by adapting the GitHub repo regex Alters the regex that extracts the org/username and repo name from the repo address, so that it can cope with repos that do not exist on github.com (e.g. GitHub Enterprise). Adds a test for this change. --- lib/jekyll-github-metadata/repository_finder.rb | 7 ++++++- spec/repository_finder_spec.rb | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) 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"]