From 552add87bc17b08a67f17f965d4c4aa6c031d89d Mon Sep 17 00:00:00 2001 From: Rusty Burchfield Date: Sun, 21 Oct 2018 09:18:55 -0700 Subject: [PATCH 01/14] Respect executable file extensions on windows The existing code does not find `git.exe` on Windows, and the metadata lookup fails. This change uses PATHEXT to get the list of valid extensions and checks for each. ``` irb(main):035:0> ENV['PATHEXT'] => ".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.RB;.RBW" ``` This change also checks if the file is executable to avoid false positives. --- lib/jekyll-github-metadata/repository_finder.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/jekyll-github-metadata/repository_finder.rb b/lib/jekyll-github-metadata/repository_finder.rb index ccd0cdb..ad7a897 100644 --- a/lib/jekyll-github-metadata/repository_finder.rb +++ b/lib/jekyll-github-metadata/repository_finder.rb @@ -46,10 +46,13 @@ def nwo_from_config end def git_exe_path + exts = (ENV['PATHEXT'] || '').split(File::PATH_SEPARATOR) + cmds = exts.map { |ext| "git#{ext}" } ENV["PATH"].to_s .split(File::PATH_SEPARATOR) - .map { |path| File.join(path, "git") } - .find { |path| File.exist?(path) } + .map { |path| cmds.map { |cmd| File.join(path, cmd) } } + .flatten + .find { |path| File.executable?(path) && !File.directory?(path) } end def git_remotes From 72b977ad9f28ead92cb87f82d160ba65972ac183 Mon Sep 17 00:00:00 2001 From: Rusty Burchfield Date: Sun, 21 Oct 2018 10:07:34 -0700 Subject: [PATCH 02/14] Fix git execution on Windows Backticks don't work properly without special quoting. Switch to Open3 for portability. --- lib/jekyll-github-metadata/repository_finder.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/jekyll-github-metadata/repository_finder.rb b/lib/jekyll-github-metadata/repository_finder.rb index ad7a897..27cb334 100644 --- a/lib/jekyll-github-metadata/repository_finder.rb +++ b/lib/jekyll-github-metadata/repository_finder.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require 'open3' + module Jekyll module GitHubMetadata class RepositoryFinder @@ -57,7 +59,8 @@ def git_exe_path def git_remotes return [] if git_exe_path.nil? - `#{git_exe_path} remote --verbose`.to_s.strip.split("\n") + output, status = Open3.capture2(git_exe_path, 'remote', '--verbose') + output.to_s.strip.split("\n") end def git_remote_url From d30a5313d6157df16766bffd8283d6be9a7d55f6 Mon Sep 17 00:00:00 2001 From: Rusty Burchfield Date: Sun, 21 Oct 2018 11:03:53 -0700 Subject: [PATCH 03/14] Drop support for 2.2 Some dependencies don't work on 2.2. ``` Gem::RuntimeRequirementNotMetError: jekyll-watch requires Ruby version >= 2.3.0. The current ruby version is 2.2.0. An error occurred while installing jekyll-watch (2.1.2), and Bundler cannot continue. ``` --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a22e14d..afc7129 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,6 @@ rvm: - 2.5 - 2.4 - 2.3 - - 2.2 env: matrix: - JEKYLL_VERSION=3.5 From e744b52429a5b6d14e3fc2db89d45d55d4ca2b7f Mon Sep 17 00:00:00 2001 From: Rusty Burchfield Date: Sun, 21 Oct 2018 11:11:34 -0700 Subject: [PATCH 04/14] Include blank extension for non-Windows systems --- lib/jekyll-github-metadata/repository_finder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jekyll-github-metadata/repository_finder.rb b/lib/jekyll-github-metadata/repository_finder.rb index 27cb334..4474239 100644 --- a/lib/jekyll-github-metadata/repository_finder.rb +++ b/lib/jekyll-github-metadata/repository_finder.rb @@ -48,7 +48,7 @@ def nwo_from_config end def git_exe_path - exts = (ENV['PATHEXT'] || '').split(File::PATH_SEPARATOR) + exts = (ENV['PATHEXT'] || '').split(File::PATH_SEPARATOR).push('') cmds = exts.map { |ext| "git#{ext}" } ENV["PATH"].to_s .split(File::PATH_SEPARATOR) From 5310d034008d260df11cc5fb2ad076b2cf89ab35 Mon Sep 17 00:00:00 2001 From: Rusty Burchfield Date: Sun, 21 Oct 2018 11:16:36 -0700 Subject: [PATCH 05/14] Fixup style --- lib/jekyll-github-metadata/repository_finder.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/jekyll-github-metadata/repository_finder.rb b/lib/jekyll-github-metadata/repository_finder.rb index 4474239..7ef46c2 100644 --- a/lib/jekyll-github-metadata/repository_finder.rb +++ b/lib/jekyll-github-metadata/repository_finder.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'open3' +require "open3" module Jekyll module GitHubMetadata @@ -48,7 +48,7 @@ def nwo_from_config end def git_exe_path - exts = (ENV['PATHEXT'] || '').split(File::PATH_SEPARATOR).push('') + exts = (ENV["PATHEXT"] || "").split(File::PATH_SEPARATOR).push("") cmds = exts.map { |ext| "git#{ext}" } ENV["PATH"].to_s .split(File::PATH_SEPARATOR) @@ -59,7 +59,7 @@ def git_exe_path def git_remotes return [] if git_exe_path.nil? - output, status = Open3.capture2(git_exe_path, 'remote', '--verbose') + output, _status = Open3.capture2(git_exe_path, "remote", "--verbose") output.to_s.strip.split("\n") end From 9ceab8218e40829c5d7b60bbd0c0f924f814304c Mon Sep 17 00:00:00 2001 From: Rusty Burchfield Date: Sat, 27 Oct 2018 09:16:40 -0700 Subject: [PATCH 06/14] Switch to Jekyll::Utils::Exec --- .../repository_finder.rb | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/lib/jekyll-github-metadata/repository_finder.rb b/lib/jekyll-github-metadata/repository_finder.rb index 7ef46c2..c28d631 100644 --- a/lib/jekyll-github-metadata/repository_finder.rb +++ b/lib/jekyll-github-metadata/repository_finder.rb @@ -47,19 +47,13 @@ def nwo_from_config repo if repo && repo.is_a?(String) && repo.include?("/") end - def git_exe_path - exts = (ENV["PATHEXT"] || "").split(File::PATH_SEPARATOR).push("") - cmds = exts.map { |ext| "git#{ext}" } - ENV["PATH"].to_s - .split(File::PATH_SEPARATOR) - .map { |path| cmds.map { |cmd| File.join(path, cmd) } } - .flatten - .find { |path| File.executable?(path) && !File.directory?(path) } - end - def git_remotes - return [] if git_exe_path.nil? - output, _status = Open3.capture2(git_exe_path, "remote", "--verbose") + output = "" + begin + _p, output = Jekyll::Utils::Exec.run("git", "remote", "--verbose") + rescue Errno::ENOENT => e + Jekyll.logger.warn "Git is not installed: ", e.message + end output.to_s.strip.split("\n") end From 1f99e1de97b62e84346358131d71433a6248bd77 Mon Sep 17 00:00:00 2001 From: Rusty Burchfield Date: Sat, 27 Oct 2018 09:18:12 -0700 Subject: [PATCH 07/14] Remove reference to removed method --- spec/repository_finder_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/repository_finder_spec.rb b/spec/repository_finder_spec.rb index ac1c8c7..7d5ce61 100644 --- a/spec/repository_finder_spec.rb +++ b/spec/repository_finder_spec.rb @@ -82,7 +82,6 @@ it "fails with a nice error message" do allow(subject).to receive(:git_remote_url).and_call_original - expect(subject.send(:git_exe_path)).to eql(nil) expect(subject.send(:git_remote_url)).to be_empty end end From 147d9fc8437230c3596ac62f191711e71a4b1690 Mon Sep 17 00:00:00 2001 From: Rusty Burchfield Date: Sat, 27 Oct 2018 09:41:52 -0700 Subject: [PATCH 08/14] Clear PATH instead of deleting --- spec/repository_finder_spec.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/spec/repository_finder_spec.rb b/spec/repository_finder_spec.rb index 7d5ce61..736d750 100644 --- a/spec/repository_finder_spec.rb +++ b/spec/repository_finder_spec.rb @@ -77,8 +77,11 @@ end context "when git doesn't exist" do - before(:each) { @old_path = ENV.delete("PATH").to_s.split(File::PATH_SEPARATOR) } - after(:each) { ENV["PATH"] = @old_path.join(File::PATH_SEPARATOR) } + before(:each) do + @old_path = ENV["PATH"] + ENV["PATH"] = "" + end + after(:each) { ENV["PATH"] = @old_path } it "fails with a nice error message" do allow(subject).to receive(:git_remote_url).and_call_original From 5341d34592a0022007a90380fb7d3a3f788d9dd8 Mon Sep 17 00:00:00 2001 From: Rusty Burchfield Date: Sat, 27 Oct 2018 10:22:52 -0700 Subject: [PATCH 09/14] Remove unused `require` --- lib/jekyll-github-metadata/repository_finder.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/jekyll-github-metadata/repository_finder.rb b/lib/jekyll-github-metadata/repository_finder.rb index c28d631..a0775f1 100644 --- a/lib/jekyll-github-metadata/repository_finder.rb +++ b/lib/jekyll-github-metadata/repository_finder.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require "open3" - module Jekyll module GitHubMetadata class RepositoryFinder From 598bc391ef7fb1393aa3aee3c17ba8d588e82da2 Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Sat, 27 Oct 2018 10:55:57 -0700 Subject: [PATCH 10/14] Update lib/jekyll-github-metadata/repository_finder.rb Co-Authored-By: GICodeWarrior --- lib/jekyll-github-metadata/repository_finder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jekyll-github-metadata/repository_finder.rb b/lib/jekyll-github-metadata/repository_finder.rb index a0775f1..35509e8 100644 --- a/lib/jekyll-github-metadata/repository_finder.rb +++ b/lib/jekyll-github-metadata/repository_finder.rb @@ -48,7 +48,7 @@ def nwo_from_config def git_remotes output = "" begin - _p, output = Jekyll::Utils::Exec.run("git", "remote", "--verbose") + _process, output = Jekyll::Utils::Exec.run("git", "remote", "--verbose") rescue Errno::ENOENT => e Jekyll.logger.warn "Git is not installed: ", e.message end From f369e513fc42f664a9af77652ec772554c155422 Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Sat, 27 Oct 2018 10:56:01 -0700 Subject: [PATCH 11/14] Update lib/jekyll-github-metadata/repository_finder.rb Co-Authored-By: GICodeWarrior --- lib/jekyll-github-metadata/repository_finder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jekyll-github-metadata/repository_finder.rb b/lib/jekyll-github-metadata/repository_finder.rb index 35509e8..63821e0 100644 --- a/lib/jekyll-github-metadata/repository_finder.rb +++ b/lib/jekyll-github-metadata/repository_finder.rb @@ -50,7 +50,7 @@ def git_remotes begin _process, output = Jekyll::Utils::Exec.run("git", "remote", "--verbose") rescue Errno::ENOENT => e - Jekyll.logger.warn "Git is not installed: ", e.message + Jekyll.logger.warn "Not Installed:", e.message end output.to_s.strip.split("\n") end From 27cc2d5ed99774eb048bad18202ec729afc32c7e Mon Sep 17 00:00:00 2001 From: Rusty Burchfield Date: Sat, 27 Oct 2018 11:00:04 -0700 Subject: [PATCH 12/14] Drop support for versions < 3.4 --- jekyll-github-metadata.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jekyll-github-metadata.gemspec b/jekyll-github-metadata.gemspec index 7e7b5b9..170e080 100644 --- a/jekyll-github-metadata.gemspec +++ b/jekyll-github-metadata.gemspec @@ -16,7 +16,7 @@ Gem::Specification.new do |spec| spec.files = `git ls-files -z`.split("\x0").grep(%r!^(lib|bin)/!) spec.require_paths = ["lib"] - spec.add_runtime_dependency "jekyll", ENV["JEKYLL_VERSION"] ? "~> #{ENV["JEKYLL_VERSION"]}" : "~> 3.1" + spec.add_runtime_dependency "jekyll", ENV["JEKYLL_VERSION"] ? "~> #{ENV["JEKYLL_VERSION"]}" : "~> 3.4" spec.add_runtime_dependency "octokit", "~> 4.0", "!= 4.4.0" spec.add_development_dependency "bundler", "~> 1.5" From 939614d380573bdc298a888e5fa86d9c35fe79e2 Mon Sep 17 00:00:00 2001 From: Rusty Burchfield Date: Tue, 6 Nov 2018 19:04:07 -0800 Subject: [PATCH 13/14] Rescue method instead of block --- lib/jekyll-github-metadata/repository_finder.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/jekyll-github-metadata/repository_finder.rb b/lib/jekyll-github-metadata/repository_finder.rb index 63821e0..8dfa796 100644 --- a/lib/jekyll-github-metadata/repository_finder.rb +++ b/lib/jekyll-github-metadata/repository_finder.rb @@ -46,13 +46,11 @@ def nwo_from_config end def git_remotes - output = "" - begin - _process, output = Jekyll::Utils::Exec.run("git", "remote", "--verbose") - rescue Errno::ENOENT => e - Jekyll.logger.warn "Not Installed:", e.message - end + _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 def git_remote_url From 3f3379b715b58cf0969a40b54f9b161b9ab1fb1a Mon Sep 17 00:00:00 2001 From: Rusty Burchfield Date: Tue, 6 Nov 2018 19:08:16 -0800 Subject: [PATCH 14/14] Return empty array, not string --- lib/jekyll-github-metadata/repository_finder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jekyll-github-metadata/repository_finder.rb b/lib/jekyll-github-metadata/repository_finder.rb index 8dfa796..88d32d1 100644 --- a/lib/jekyll-github-metadata/repository_finder.rb +++ b/lib/jekyll-github-metadata/repository_finder.rb @@ -50,7 +50,7 @@ def git_remotes output.to_s.strip.split("\n") rescue Errno::ENOENT => e Jekyll.logger.warn "Not Installed:", e.message - "" + [] end def git_remote_url