Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
require: rubocop-jekyll
inherit_gem:
jekyll: .rubocop.yml
rubocop-jekyll: .rubocop.yml

AllCops:
TargetRubyVersion: 2.2
TargetRubyVersion: 2.4
Exclude:
- vendor/**/*
- script/*

Metrics/LineLength:
Enabled: false
Expand Down
15 changes: 9 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@ language: ruby
sudo: false
cache: bundler
rvm:
- &latest_ruby 2.6
- 2.5
- 2.4
- 2.3
env:
matrix:
- JEKYLL_VERSION=3.7
- JEKYLL_VERSION=3.8
matrix:
include:
- rvm: *latest_ruby
env: JEKYLL_VERSION=3.7.0
branches:
only:
- master

before_install:
- gem update --system
- gem update --system

before_script: bundle update
script: script/cibuild

notifications:
irc:
on_success: change
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
source "https://rubygems.org"
gemspec

gem "jekyll", "~> #{ENV["JEKYLL_VERSION"]}" if ENV["JEKYLL_VERSION"]

group :test do
gem "webmock", "~> 2.0"
end
7 changes: 3 additions & 4 deletions jekyll-github-metadata.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ 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.4"
spec.add_runtime_dependency "jekyll", "~> 3.4"
spec.add_runtime_dependency "octokit", "~> 4.0", "!= 4.4.0"

spec.add_development_dependency "bundler", "~> 1.5"
spec.add_development_dependency "netrc"
spec.add_development_dependency "pry"
spec.add_development_dependency "rake"
spec.add_development_dependency "rspec"
spec.add_development_dependency "pry"
spec.add_development_dependency "rubocop", "~> 0.57.2"
spec.add_development_dependency "rubocop-jekyll", "~> 0.5.0"
end
4 changes: 1 addition & 3 deletions lib/jekyll-github-metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ module GitHubMetadata

NoRepositoryError = RepositoryFinder::NoRepositoryError

if Jekyll.const_defined? :Site
require_relative "jekyll-github-metadata/site_github_munger"
end
require_relative "jekyll-github-metadata/site_github_munger" if Jekyll.const_defined? :Site

class << self
attr_reader :repository_finder
Expand Down
6 changes: 3 additions & 3 deletions lib/jekyll-github-metadata/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ def default_octokit_options

def build_octokit_client(options = nil)
options ||= {}
unless options.key? :access_token
options.merge! pluck_auth_method
end
options.merge!(pluck_auth_method) unless options.key?(:access_token)
Octokit::Client.new(default_octokit_options.merge(options))
end

Expand Down Expand Up @@ -118,6 +116,7 @@ def client_inspect
end
end

# rubocop:disable Metrics/CyclomaticComplexity
def pluck_auth_method
if ENV["JEKYLL_GITHUB_TOKEN"] || Octokit.access_token
{ :access_token => ENV["JEKYLL_GITHUB_TOKEN"] || Octokit.access_token }
Expand All @@ -129,6 +128,7 @@ def pluck_auth_method
{}.freeze
end
end
# rubocop:enable Metrics/CyclomaticComplexity

def cache_key(method, *args)
Digest::SHA1.hexdigest(method.to_s + args.join(", "))
Expand Down
4 changes: 2 additions & 2 deletions lib/jekyll-github-metadata/edit-link-tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def self.def_hash_delegator(hash_method, key, method, default = nil)
end
end

MISSING_DATA_MSG = "Cannot generate edit URLs due to missing site.github data".freeze
LINK_TEXT_REGEX = %r!(?:\"(.*)\"|'(.*)')!
MISSING_DATA_MSG = "Cannot generate edit URLs due to missing site.github data"
LINK_TEXT_REGEX = %r!(?:\"(.*)\"|'(.*)')!.freeze

extend Forwardable
private def_hash_delegator :site, :github, :site_github, {}
Expand Down
9 changes: 6 additions & 3 deletions lib/jekyll-github-metadata/metadata_drop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class MetadataDrop < Jekyll::Drops::Drop
def key?(key)
return false if key.nil?
return true if self.class.mutable? && @mutations.key?(key)

respond_to?(key) || fallback_data.key?(key)
end

Expand Down Expand Up @@ -71,11 +72,13 @@ def keys
def_delegator :repository, :source, :source

def versions
@versions ||= begin
return @versions if defined?(@versions)

begin
require "github-pages"
GitHubPages.versions
@versions = GitHubPages.versions
rescue LoadError
{}
@versions = {}
end
end

Expand Down
33 changes: 21 additions & 12 deletions lib/jekyll-github-metadata/pages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ module GitHubMetadata
class Pages
class << self
DEFAULTS = {
"PAGES_ENV" => "development".freeze,
"PAGES_API_URL" => "https://api.github.com".freeze,
"PAGES_HELP_URL" => "https://help.github.com".freeze,
"PAGES_GITHUB_HOSTNAME" => "github.com".freeze,
"PAGES_PAGES_HOSTNAME" => "github.io".freeze,
"SSL" => "false".freeze,
"SUBDOMAIN_ISOLATION" => "false".freeze,
"PAGES_ENV" => "development",
"PAGES_API_URL" => "https://api.github.com",
"PAGES_HELP_URL" => "https://help.github.com",
"PAGES_GITHUB_HOSTNAME" => "github.com",
"PAGES_PAGES_HOSTNAME" => "github.io",
"SSL" => "false",
"SUBDOMAIN_ISOLATION" => "false",
"PAGES_PREVIEW_HTML_URL" => nil,
"PAGE_BUILD_ID" => nil,
}.freeze
Expand All @@ -32,13 +32,21 @@ def subdomain_isolation?
env_var("SUBDOMAIN_ISOLATION").eql? "true"
end

def test?; env == "test" end
def test?
env == "test"
end

def dotcom?; env == "dotcom" end
def dotcom?
env == "dotcom"
end

def enterprise?; env == "enterprise" end
def enterprise?
env == "enterprise"
end

def development?; env == "development" end
def development?
env == "development"
end

def custom_domains_enabled?
dotcom? || test?
Expand All @@ -54,7 +62,7 @@ def repo_pages_html_url_preview?

def github_url
if dotcom? || github_hostname == "github.com"
"https://github.com".freeze
"https://github.com"
else
"#{scheme}://#{github_hostname}"
end
Expand Down Expand Up @@ -89,6 +97,7 @@ def configuration
end

private

def env_var(key, intermediate_default = nil)
!ENV[key].to_s.empty? ? ENV[key] : (intermediate_default || DEFAULTS[key])
end
Expand Down
2 changes: 2 additions & 0 deletions lib/jekyll-github-metadata/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ def default_user_domain

def cname
return nil unless Pages.custom_domains_enabled?

repo_pages_info["cname"]
end

Expand All @@ -182,6 +183,7 @@ def url_without_path

def memoize_value(var_name, value)
return instance_variable_get(var_name) if instance_variable_defined?(var_name)

instance_variable_set(var_name, value.render)
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/jekyll-github-metadata/repository_compat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def user_domain
repo.user_page_domains.each do |user_repo|
candidate_nwo = "#{repo.owner}/#{user_repo}"
next unless Jekyll::GitHubMetadata.client.repository?(candidate_nwo)

domain = Jekyll::GitHubMetadata::Repository.new(candidate_nwo).repo_compat.domain
end
domain
Expand Down
3 changes: 2 additions & 1 deletion lib/jekyll-github-metadata/repository_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def nwo_from_env

def nwo_from_config
repo = site.config["repository"]
repo if repo && repo.is_a?(String) && repo.include?("/")
repo if repo&.is_a?(String) && repo&.include?("/")
end

def git_remotes
Expand All @@ -61,6 +61,7 @@ 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 github_remote_regex
matches[2..3].join("/") if matches
end
Expand Down
2 changes: 2 additions & 0 deletions lib/jekyll-github-metadata/sanitizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module Sanitizer
# resource - an Object
#
# Returns the sanitized resource.
# rubocop:disable Metrics/CyclomaticComplexity
def sanitize(resource)
case resource
when Array
Expand All @@ -36,6 +37,7 @@ def sanitize(resource)
end
end
end
# rubocop:enable Metrics/CyclomaticComplexity

# Sanitize the Sawyer Resource or Hash
# Note: the object must respond to :to_hash for this to work.
Expand Down
1 change: 1 addition & 0 deletions lib/jekyll-github-metadata/site_github_munger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def drop
def add_url_and_baseurl_fallbacks!
site.config["url"] ||= Value.new("url", proc { |_c, r| r.url_without_path })
return unless should_set_baseurl?

site.config["baseurl"] = Value.new("baseurl", proc { |_c, r| r.baseurl })
end

Expand Down
2 changes: 2 additions & 0 deletions lib/jekyll-github-metadata/value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def initialize(*args)

def render
return @rendered if defined? @rendered

@rendered = @value = Sanitizer.sanitize(call_or_value)
rescue RuntimeError, NameError => e
Jekyll::GitHubMetadata.log :error, "Error processing value '#{key}':"
Expand All @@ -46,6 +47,7 @@ def to_liquid
# or returns the raw value if it's a literal
def call_or_value
return value unless value.respond_to?(:call)

case value.arity
when 0
value.call
Expand Down
2 changes: 1 addition & 1 deletion lib/jekyll-github-metadata/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module Jekyll
module GitHubMetadata
VERSION = "2.10.0".freeze
VERSION = "2.10.0"
end
end
6 changes: 4 additions & 2 deletions script/console.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require 'octokit'
require 'pry'
# frozen_string_literal: true

require "octokit"
require "pry"

stack = Faraday::RackBuilder.new do |builder|
builder.use Octokit::Middleware::FollowRedirects
Expand Down
12 changes: 6 additions & 6 deletions spec/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

RSpec.describe(Jekyll::GitHubMetadata::Client) do
let(:token) { "abc1234" }
subject { described_class.new({ :access_token => token }) }
subject { described_class.new(:access_token => token) }

it "whitelists certain api calls" do
described_class::API_CALLS.each do |method_name|
Expand All @@ -20,15 +20,15 @@

it "can check if it's authenticated" do
expect(subject.authenticated?).to be(true)
expect(described_class.new({ :access_token => nil }).authenticated?).to be(false)
expect(described_class.new({ :access_token => "" }).authenticated?).to be(false)
expect(described_class.new(:access_token => nil).authenticated?).to be(false)
expect(described_class.new(:access_token => "").authenticated?).to be(false)
end

it "raises an error for any api call with bad credentials" do
stub_request(:get, url("/repos/jekyll/github-metadata/contributors?per_page=100"))
.with(:headers => request_headers.merge({
"Authorization" => "token #{token}",
}))
.with(:headers => request_headers.merge(
"Authorization" => "token #{token}"
))
.to_return(
:status => 401,
:headers => WebMockHelper::RESPONSE_HEADERS,
Expand Down
12 changes: 6 additions & 6 deletions spec/pages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

context ".configuration" do
it "returns the entire configuration" do
expect(described_class.configuration).to eql({
expect(described_class.configuration).to eql(
"api_url" => "https://api.github.com",
"custom_domains_enabled?" => true,
"development?" => false,
Expand All @@ -46,8 +46,8 @@
"scheme" => "https",
"ssl?" => true,
"subdomain_isolation?" => false,
"test?" => true,
})
"test?" => true
)
end
end

Expand Down Expand Up @@ -108,10 +108,10 @@
end

it "is true in PAGES_ENV=test" do
with_env({
with_env(
"PAGES_ENV" => "test",
"SSL" => "false",
}) do
"SSL" => "false"
) do
expect(described_class.ssl?).to be true
end
end
Expand Down
Loading