module Jekyll
  module GitHubMetadata
    class GHPMetadataGenerator < Jekyll::Generator
      safe true

      def generate(site)
        Jekyll.logger.debug "Generator:", "Calling GHPMetadataGenerator"
        initialize_repo! nwo(site)
        Jekyll.logger.debug "GitHub Metadata:", "Generating for #{GitHubMetadata.repository.nwo}"

        site.config['github'] =
          case site.config['github']
          when nil
            GitHubMetadata.to_liquid
          when Hash
            Jekyll::Utils.deep_merge_hashes(GitHubMetadata.to_liquid, site.config['github'])
          else
            site.config['github']
          end
      end

      private

      def initialize_repo!(repo_nwo)
        if GitHubMetadata.repository.nil? || GitHubMetadata.repository.nwo != repo_nwo
          GitHubMetadata.init!
          GitHubMetadata.repository = GitHubMetadata::Repository.new(repo_nwo)
        end
      end

      def git_remote_url
        `git remote get-url origin`
      end

      def git_nwo
        return unless Jekyll.env == "development"
        matches = git_remote_url.match %r{github.com(:|/)([\w-]+)/([\w-]+)}
        matches[2..3].join("/") if matches
      end

      def nwo(site)
        ENV['PAGES_REPO_NWO'] || \
          site.config['repository'] || \
          git_nwo || \
          proc {
            raise GitHubMetadata::NoRepositoryError, "No repo name found. "
              "Specify using PAGES_REPO_NWO or 'repository' in your configuration."
          }.call
      end
    end
  end
end

module Jekyll
  module GitHubMetadata
    class GHPMetadataGenerator < Jekyll::Generator
      safe true

      def generate(site)
        Jekyll.logger.debug "Generator:", "Calling GHPMetadataGenerator"
        initialize_repo! nwo(site)
        Jekyll.logger.debug "GitHub Metadata:", "Generating for #{GitHubMetadata.repository.nwo}"

        site.config['github'] =
          case site.config['github']
          when nil
            GitHubMetadata.to_liquid
          when Hash
            Jekyll::Utils.deep_merge_hashes(GitHubMetadata.to_liquid, site.config['github'])
          else
            site.config['github']
          end
      end

      private

      def initialize_repo!(repo_nwo)
        if GitHubMetadata.repository.nil? || GitHubMetadata.repository.nwo != repo_nwo
          GitHubMetadata.init!
          GitHubMetadata.repository = GitHubMetadata::Repository.new(repo_nwo)
        end
      end

      def git_remote_url
        `git remote --verbose`.split("\n").grep(%r{\Aorigin\t(.*) \(push\)})
      end

      def git_nwo
        return unless Jekyll.env == "development"
        matches = git_remote_url.match %r{github.com(:|/)([\w-]+)/([\w-]+)}
        matches[2..3].join("/") if matches
      end

      def nwo(site)
        ENV['PAGES_REPO_NWO'] || \
          site.config['repository'] || \
          git_nwo || \
          proc {
            raise GitHubMetadata::NoRepositoryError, "No repo name found. "
              "Specify using PAGES_REPO_NWO or 'repository' in your configuration."
          }.call
      end
    end
  end
end

Use `git remote --verbose` instead of `git remote get-url` because get-url is too new
Use `git remote --verbose` instead of `git remote get-url` because get-url is too new

Travis's git doesn't have it, so others' git setups likely won't either.

https://github.com/git/git/commit/96f78d39989d1fcf393d7bc42357467dd8cf0f15#diff-388838443870b4d1c62785151773c6ff