jekyll-github-metadata 2.5.1 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jekyll-github-metadata.rb +20 -5
- data/lib/jekyll-github-metadata/client.rb +24 -4
- data/lib/jekyll-github-metadata/metadata_drop.rb +13 -74
- data/lib/jekyll-github-metadata/repository.rb +4 -0
- data/lib/jekyll-github-metadata/repository_finder.rb +71 -0
- data/lib/jekyll-github-metadata/site_github_munger.rb +13 -14
- data/lib/jekyll-github-metadata/value.rb +24 -30
- data/lib/jekyll-github-metadata/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d2c8a4d83077bd33381eed7bd0d71a7a8e5d247
|
4
|
+
data.tar.gz: 8950850bbb6509507e2e0a23bde092dad36bfc5a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a53d6ba55983aea9549fdba81ee41f60da3625f38aca9f79023f790d9653bf9237aa7c3737388c9c4940dcf7373c2aff00208bb1e5669c5de86e36ce66ab87b
|
7
|
+
data.tar.gz: 46051024d33c1024d3893af0b6530473545c96edd8650f80e87c17dcbac31dd8746b6358bc1e57e177374c1109af78e0915c9d62c546bc0e15bd4a7ca96da093
|
@@ -18,25 +18,30 @@ module Jekyll
|
|
18
18
|
end
|
19
19
|
|
20
20
|
module GitHubMetadata
|
21
|
-
NoRepositoryError = Class.new(Jekyll::Errors::FatalException)
|
22
|
-
|
23
21
|
autoload :Client, "jekyll-github-metadata/client"
|
24
22
|
autoload :MetadataDrop, "jekyll-github-metadata/metadata_drop"
|
25
23
|
autoload :Pages, "jekyll-github-metadata/pages"
|
26
24
|
autoload :Repository, "jekyll-github-metadata/repository"
|
25
|
+
autoload :RepositoryFinder, "jekyll-github-metadata/repository_finder"
|
27
26
|
autoload :RepositoryCompat, "jekyll-github-metadata/repository_compat"
|
28
27
|
autoload :Sanitizer, "jekyll-github-metadata/sanitizer"
|
29
28
|
autoload :Value, "jekyll-github-metadata/value"
|
30
29
|
autoload :VERSION, "jekyll-github-metadata/version"
|
31
30
|
|
31
|
+
NoRepositoryError = RepositoryFinder::NoRepositoryError
|
32
|
+
|
32
33
|
if Jekyll.const_defined? :Site
|
33
34
|
require_relative "jekyll-github-metadata/site_github_munger"
|
34
35
|
end
|
35
36
|
|
36
37
|
class << self
|
37
|
-
|
38
|
+
attr_reader :repository_finder
|
38
39
|
attr_writer :client, :logger
|
39
40
|
|
41
|
+
def site
|
42
|
+
repository_finder.site
|
43
|
+
end
|
44
|
+
|
40
45
|
def environment
|
41
46
|
Jekyll.respond_to?(:env) ? Jekyll.env : (Pages.env || "development")
|
42
47
|
end
|
@@ -61,9 +66,19 @@ module Jekyll
|
|
61
66
|
@client ||= Client.new
|
62
67
|
end
|
63
68
|
|
69
|
+
def repository
|
70
|
+
@repository ||= GitHubMetadata::Repository.new(repository_finder.nwo).tap do |repo|
|
71
|
+
Jekyll::GitHubMetadata.log :debug, "Generating for #{repo.nwo}"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def site=(new_site)
|
76
|
+
reset!
|
77
|
+
@repository_finder = GitHubMetadata::RepositoryFinder.new(new_site)
|
78
|
+
end
|
79
|
+
|
64
80
|
def reset!
|
65
|
-
@logger = nil
|
66
|
-
@client = nil
|
81
|
+
@logger = @client = @repository = @nwo = @site = nil
|
67
82
|
end
|
68
83
|
end
|
69
84
|
end
|
@@ -58,7 +58,7 @@ module Jekyll
|
|
58
58
|
method = method_name.to_s
|
59
59
|
if accepts_client_method?(method_name)
|
60
60
|
key = cache_key(method_name, args)
|
61
|
-
|
61
|
+
GitHubMetadata.log :debug, "Calling @client.#{method}(#{args.map(&:inspect).join(", ")})"
|
62
62
|
cache[key] ||= save_from_errors { @client.public_send(method_name, *args, &block) }
|
63
63
|
elsif @client.respond_to?(method_name)
|
64
64
|
raise InvalidMethodError, "#{method_name} is not whitelisted on #{inspect}"
|
@@ -68,24 +68,44 @@ module Jekyll
|
|
68
68
|
end
|
69
69
|
|
70
70
|
def save_from_errors(default = false)
|
71
|
+
unless internet_connected?
|
72
|
+
GitHubMetadata.log :warn, "No internet connection. GitHub metadata may be missing or incorrect."
|
73
|
+
return default
|
74
|
+
end
|
75
|
+
|
71
76
|
yield @client
|
72
77
|
rescue Octokit::Unauthorized
|
73
78
|
raise BadCredentialsError, "The GitHub API credentials you provided aren't valid."
|
74
79
|
rescue Faraday::Error::ConnectionFailed, Octokit::TooManyRequests => e
|
75
|
-
|
80
|
+
GitHubMetadata.log :warn, e.message
|
76
81
|
default
|
77
82
|
rescue Octokit::NotFound
|
78
83
|
default
|
79
84
|
end
|
80
85
|
|
81
86
|
def inspect
|
82
|
-
"#<#{self.class.name} @client=#{client_inspect}>"
|
87
|
+
"#<#{self.class.name} @client=#{client_inspect} @internet_connected=#{internet_connected?}>"
|
83
88
|
end
|
84
89
|
|
85
90
|
def authenticated?
|
86
91
|
!@client.access_token.to_s.empty?
|
87
92
|
end
|
88
93
|
|
94
|
+
def internet_connected?
|
95
|
+
return @internet_connected if defined?(@internet_connected)
|
96
|
+
|
97
|
+
require "resolv"
|
98
|
+
begin
|
99
|
+
Resolv::DNS.open do |dns|
|
100
|
+
dns.timeouts = 2
|
101
|
+
dns.getaddress("api.github.com")
|
102
|
+
end
|
103
|
+
@internet_connected = true
|
104
|
+
rescue Resolv::ResolvError
|
105
|
+
@internet_connected = false
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
89
109
|
private
|
90
110
|
|
91
111
|
def client_inspect
|
@@ -102,7 +122,7 @@ module Jekyll
|
|
102
122
|
elsif !ENV["NO_NETRC"] && File.exist?(File.join(ENV["HOME"], ".netrc")) && safe_require("netrc")
|
103
123
|
{ :netrc => true }
|
104
124
|
else
|
105
|
-
|
125
|
+
GitHubMetadata.log :warn, "No GitHub API authentication could be found." \
|
106
126
|
" Some fields may be missing or have incorrect data."
|
107
127
|
{}.freeze
|
108
128
|
end
|
@@ -8,11 +8,6 @@ module Jekyll
|
|
8
8
|
|
9
9
|
mutable true
|
10
10
|
|
11
|
-
def initialize(site)
|
12
|
-
@site = site
|
13
|
-
super(nil)
|
14
|
-
end
|
15
|
-
|
16
11
|
def to_s
|
17
12
|
require "json"
|
18
13
|
JSON.pretty_generate to_h
|
@@ -34,20 +29,7 @@ module Jekyll
|
|
34
29
|
def_delegator :"Jekyll::GitHubMetadata::Pages", :api_url, :api_url
|
35
30
|
def_delegator :"Jekyll::GitHubMetadata::Pages", :help_url, :help_url
|
36
31
|
|
37
|
-
|
38
|
-
@versions ||= begin
|
39
|
-
require "github-pages"
|
40
|
-
GitHubPages.versions
|
41
|
-
rescue LoadError
|
42
|
-
{}
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def build_revision
|
47
|
-
@build_revision ||= begin
|
48
|
-
ENV["JEKYLL_BUILD_REVISION"] || `git rev-parse HEAD`.strip
|
49
|
-
end
|
50
|
-
end
|
32
|
+
private def_delegator :"Jekyll::GitHubMetadata", :repository
|
51
33
|
|
52
34
|
def_delegator :repository, :owner_public_repositories, :public_repositories
|
53
35
|
def_delegator :repository, :organization_public_members, :organization_members
|
@@ -74,67 +56,24 @@ module Jekyll
|
|
74
56
|
def_delegator :repository, :contributors, :contributors
|
75
57
|
def_delegator :repository, :releases, :releases
|
76
58
|
def_delegator :repository, :latest_release, :latest_release
|
59
|
+
def_delegator :repository, :private?, :private
|
77
60
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
61
|
+
def versions
|
62
|
+
@versions ||= begin
|
63
|
+
require "github-pages"
|
64
|
+
GitHubPages.versions
|
65
|
+
rescue LoadError
|
66
|
+
{}
|
84
67
|
end
|
85
68
|
end
|
86
69
|
|
87
|
-
def
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
def git_remotes
|
92
|
-
return [] if git_exe_path.nil?
|
93
|
-
`#{git_exe_path} remote --verbose`.to_s.strip.split("\n")
|
94
|
-
end
|
95
|
-
|
96
|
-
def git_remote_url
|
97
|
-
git_remotes.grep(%r!\Aorigin\t!).map do |remote|
|
98
|
-
remote.sub(%r!\Aorigin\t(.*) \([a-z]+\)!, "\\1")
|
99
|
-
end.uniq.first || ""
|
100
|
-
end
|
101
|
-
|
102
|
-
def nwo_from_git_origin_remote
|
103
|
-
return unless Jekyll.env == "development" || Jekyll.env == "test"
|
104
|
-
matches = git_remote_url.chomp(".git").match %r!github.com(:|/)([\w-]+)/([\w\.-]+)!
|
105
|
-
matches[2..3].join("/") if matches
|
106
|
-
end
|
107
|
-
|
108
|
-
def nwo_from_env
|
109
|
-
ENV["PAGES_REPO_NWO"]
|
110
|
-
end
|
111
|
-
|
112
|
-
def nwo_from_config(site)
|
113
|
-
repo = site.config["repository"]
|
114
|
-
repo if repo && repo.is_a?(String) && repo.include?("/")
|
70
|
+
def build_revision
|
71
|
+
@build_revision ||= begin
|
72
|
+
ENV["JEKYLL_BUILD_REVISION"] || `git rev-parse HEAD`.strip
|
73
|
+
end
|
115
74
|
end
|
116
75
|
|
117
|
-
|
118
|
-
# In order of precedence, this method uses:
|
119
|
-
# 1. the environment variable $PAGES_REPO_NWO
|
120
|
-
# 2. 'repository' variable in the site config
|
121
|
-
# 3. the 'origin' git remote's URL
|
122
|
-
#
|
123
|
-
# site - the Jekyll::Site being processed
|
124
|
-
#
|
125
|
-
# Return the name with owner (e.g. 'parkr/my-repo') or raises an
|
126
|
-
# error if one cannot be found.
|
127
|
-
def nwo(site)
|
128
|
-
nwo_from_env || \
|
129
|
-
nwo_from_config(site) || \
|
130
|
-
nwo_from_git_origin_remote || \
|
131
|
-
proc do
|
132
|
-
raise GitHubMetadata::NoRepositoryError, "No repo name found. " \
|
133
|
-
"Specify using PAGES_REPO_NWO environment variables, " \
|
134
|
-
"'repository' in your configuration, or set up an 'origin' " \
|
135
|
-
"git remote pointing to your github.com repository."
|
136
|
-
end.call
|
137
|
-
end
|
76
|
+
private
|
138
77
|
|
139
78
|
# Nothing to see here.
|
140
79
|
def fallback_data
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module GitHubMetadata
|
3
|
+
class RepositoryFinder
|
4
|
+
NoRepositoryError = Class.new(Jekyll::Errors::FatalException)
|
5
|
+
|
6
|
+
attr_reader :site
|
7
|
+
def initialize(site)
|
8
|
+
@site = site
|
9
|
+
end
|
10
|
+
|
11
|
+
# Public: fetches the repository name with owner to fetch metadata for.
|
12
|
+
# In order of precedence, this method uses:
|
13
|
+
# 1. the environment variable $PAGES_REPO_NWO
|
14
|
+
# 2. 'repository' variable in the site config
|
15
|
+
# 3. the 'origin' git remote's URL
|
16
|
+
#
|
17
|
+
# site - the Jekyll::Site being processed
|
18
|
+
#
|
19
|
+
# Return the name with owner (e.g. 'parkr/my-repo') or raises an
|
20
|
+
# error if one cannot be found.
|
21
|
+
def nwo
|
22
|
+
@nwo ||= begin
|
23
|
+
nwo_from_env || \
|
24
|
+
nwo_from_config || \
|
25
|
+
nwo_from_git_origin_remote || \
|
26
|
+
proc do
|
27
|
+
raise NoRepositoryError, "No repo name found. " \
|
28
|
+
"Specify using PAGES_REPO_NWO environment variables, " \
|
29
|
+
"'repository' in your configuration, or set up an 'origin' " \
|
30
|
+
"git remote pointing to your github.com repository."
|
31
|
+
end.call
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def nwo_from_env
|
38
|
+
ENV["PAGES_REPO_NWO"]
|
39
|
+
end
|
40
|
+
|
41
|
+
def nwo_from_config
|
42
|
+
repo = site.config["repository"]
|
43
|
+
repo if repo && repo.is_a?(String) && repo.include?("/")
|
44
|
+
end
|
45
|
+
|
46
|
+
def git_exe_path
|
47
|
+
ENV["PATH"].to_s
|
48
|
+
.split(File::PATH_SEPARATOR)
|
49
|
+
.map { |path| File.join(path, "git") }
|
50
|
+
.find { |path| File.exist?(path) }
|
51
|
+
end
|
52
|
+
|
53
|
+
def git_remotes
|
54
|
+
return [] if git_exe_path.nil?
|
55
|
+
`#{git_exe_path} remote --verbose`.to_s.strip.split("\n")
|
56
|
+
end
|
57
|
+
|
58
|
+
def git_remote_url
|
59
|
+
git_remotes.grep(%r!\Aorigin\t!).map do |remote|
|
60
|
+
remote.sub(%r!\Aorigin\t(.*) \([a-z]+\)!, "\\1")
|
61
|
+
end.uniq.first || ""
|
62
|
+
end
|
63
|
+
|
64
|
+
def nwo_from_git_origin_remote
|
65
|
+
return unless Jekyll.env == "development" || Jekyll.env == "test"
|
66
|
+
matches = git_remote_url.chomp(".git").match %r!github.com(:|/)([\w-]+)/([\w\.-]+)!
|
67
|
+
matches[2..3].join("/") if matches
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -4,10 +4,13 @@ require "uri"
|
|
4
4
|
module Jekyll
|
5
5
|
module GitHubMetadata
|
6
6
|
class SiteGitHubMunger
|
7
|
-
|
7
|
+
extend Forwardable
|
8
|
+
|
9
|
+
def_delegators :"Jekyll::GitHubMetadata", :site
|
10
|
+
private def_delegator :"Jekyll::GitHubMetadata", :repository
|
8
11
|
|
9
12
|
def initialize(site)
|
10
|
-
|
13
|
+
Jekyll::GitHubMetadata.site = site
|
11
14
|
end
|
12
15
|
|
13
16
|
def munge!
|
@@ -16,9 +19,8 @@ module Jekyll
|
|
16
19
|
# This is the good stuff.
|
17
20
|
site.config["github"] = github_namespace
|
18
21
|
|
19
|
-
return unless should_add_fallbacks?
|
20
|
-
add_url_and_baseurl_fallbacks!
|
21
22
|
add_title_and_description_fallbacks!
|
23
|
+
add_url_and_baseurl_fallbacks! if should_add_url_fallbacks?
|
22
24
|
end
|
23
25
|
|
24
26
|
private
|
@@ -35,13 +37,14 @@ module Jekyll
|
|
35
37
|
end
|
36
38
|
|
37
39
|
def drop
|
38
|
-
@drop ||= MetadataDrop.new(site)
|
40
|
+
@drop ||= MetadataDrop.new(GitHubMetadata.site)
|
39
41
|
end
|
40
42
|
|
41
43
|
# Set `site.url` and `site.baseurl` if unset.
|
42
44
|
def add_url_and_baseurl_fallbacks!
|
43
|
-
site.config["url"] ||=
|
44
|
-
|
45
|
+
site.config["url"] ||= Value.new("url", proc { |_c, r| r.url_without_path })
|
46
|
+
return unless should_set_baseurl?
|
47
|
+
site.config["baseurl"] = Value.new("baseurl", proc { |_c, r| r.baseurl })
|
45
48
|
end
|
46
49
|
|
47
50
|
# Set the baseurl only if it is `nil` or `/`
|
@@ -51,17 +54,13 @@ module Jekyll
|
|
51
54
|
end
|
52
55
|
|
53
56
|
def add_title_and_description_fallbacks!
|
54
|
-
site.config["title"] ||=
|
55
|
-
site.config["description"] ||=
|
57
|
+
site.config["title"] ||= Value.new("title", proc { |_c, r| r.name })
|
58
|
+
site.config["description"] ||= Value.new("description", proc { |_c, r| r.tagline })
|
56
59
|
end
|
57
60
|
|
58
|
-
def
|
61
|
+
def should_add_url_fallbacks?
|
59
62
|
Jekyll.env == "production" || Pages.page_build?
|
60
63
|
end
|
61
|
-
|
62
|
-
def repository
|
63
|
-
drop.send(:repository)
|
64
|
-
end
|
65
64
|
end
|
66
65
|
end
|
67
66
|
end
|
@@ -3,6 +3,9 @@ require "json"
|
|
3
3
|
module Jekyll
|
4
4
|
module GitHubMetadata
|
5
5
|
class Value
|
6
|
+
extend Forwardable
|
7
|
+
def_delegators :render, :+, :to_s, :to_json, :eql?, :hash
|
8
|
+
|
6
9
|
attr_reader :key, :value
|
7
10
|
|
8
11
|
def initialize(*args)
|
@@ -19,48 +22,39 @@ module Jekyll
|
|
19
22
|
end
|
20
23
|
|
21
24
|
def render
|
22
|
-
@
|
23
|
-
|
24
|
-
when 0
|
25
|
-
@value.call
|
26
|
-
when 1
|
27
|
-
@value.call(GitHubMetadata.client)
|
28
|
-
when 2
|
29
|
-
@value.call(GitHubMetadata.client, GitHubMetadata.repository)
|
30
|
-
else
|
31
|
-
raise ArgumentError, "Whoa, arity of 0, 1, or 2 please in your procs."
|
32
|
-
end
|
33
|
-
else
|
34
|
-
@value
|
35
|
-
end
|
36
|
-
@value = Sanitizer.sanitize(@value)
|
25
|
+
return @rendered if defined? @rendered
|
26
|
+
@rendered = @value = Sanitizer.sanitize(call_or_value)
|
37
27
|
rescue RuntimeError, NameError => e
|
38
28
|
Jekyll::GitHubMetadata.log :error, "Error processing value '#{key}':"
|
39
29
|
raise e
|
40
30
|
end
|
41
31
|
|
42
|
-
def to_s
|
43
|
-
render.to_s
|
44
|
-
end
|
45
|
-
|
46
|
-
def to_json(*)
|
47
|
-
render.to_json
|
48
|
-
end
|
49
|
-
|
50
32
|
def to_liquid
|
51
33
|
case render
|
52
|
-
when nil
|
53
|
-
nil
|
54
|
-
when true, false
|
55
|
-
value
|
56
|
-
when Hash
|
57
|
-
value
|
58
|
-
when String, Numeric, Array
|
34
|
+
when nil, true, false, Hash, String, Numeric, Array
|
59
35
|
value
|
60
36
|
else
|
61
37
|
to_json
|
62
38
|
end
|
63
39
|
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
# Calls the value Proc with the appropriate number of arguments
|
44
|
+
# or returns the raw value if it's a literal
|
45
|
+
def call_or_value
|
46
|
+
return value unless value.respond_to?(:call)
|
47
|
+
case value.arity
|
48
|
+
when 0
|
49
|
+
value.call
|
50
|
+
when 1
|
51
|
+
value.call(GitHubMetadata.client)
|
52
|
+
when 2
|
53
|
+
value.call(GitHubMetadata.client, GitHubMetadata.repository)
|
54
|
+
else
|
55
|
+
raise ArgumentError, "Whoa, arity of 0, 1, or 2 please in your procs."
|
56
|
+
end
|
57
|
+
end
|
64
58
|
end
|
65
59
|
end
|
66
60
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-github-metadata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Parker Moore
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: octokit
|
@@ -127,6 +127,7 @@ files:
|
|
127
127
|
- lib/jekyll-github-metadata/pages.rb
|
128
128
|
- lib/jekyll-github-metadata/repository.rb
|
129
129
|
- lib/jekyll-github-metadata/repository_compat.rb
|
130
|
+
- lib/jekyll-github-metadata/repository_finder.rb
|
130
131
|
- lib/jekyll-github-metadata/sanitizer.rb
|
131
132
|
- lib/jekyll-github-metadata/site_github_munger.rb
|
132
133
|
- lib/jekyll-github-metadata/value.rb
|