jekyll-github-metadata 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 552e948d80c87cc232d4e5174c01b67865d39d80
4
- data.tar.gz: f0616b53308ff040e37ae03579447188d960070b
3
+ metadata.gz: efed2aebc358aaa6e7cee8d1c5e03e0eca432453
4
+ data.tar.gz: 424595a71e84aa1917bfb2198b73d0e95132268c
5
5
  SHA512:
6
- metadata.gz: a7121114126260d7ab0863786f2f2f4700cb81017f7225b40ee36dadddbb4654d49e2bf1db75cd5f14e1447624554cbe8b5f79e11a9adf6c923f07dcc604db9e
7
- data.tar.gz: 5a94679c3e92759b9929f0c3f44e15745f2e8eefa9e3268d24b3e5bc5274473760823d7f8ca2b4d6d9978aecffbeae26a14cd7c2b2404d1ea5f9266429ffd515
6
+ metadata.gz: 3253b80572e5551d4635c4d878374839be39bbc42af2e756e67b9664e82fe7967b6242501c9b4e62294eed007f7eb9946343e9848df9f2bc379f02f020c39daf
7
+ data.tar.gz: e81fe89c4d4912f1a0450a3c2df85d6f3511beb0bed3ec0f8a610208aee198e2680dc5ea7d58439abd6ca15db3cf1f77be1ff553e2cc26a3f8d8158c050ce2d3
@@ -1,7 +1,12 @@
1
- require 'jekyll'
2
1
  require 'octokit'
3
2
 
4
3
  module Jekyll
4
+ unless const_defined? :Errors
5
+ module Errors
6
+ FatalException = Class.new(::RuntimeError) unless const_defined? :FatalException
7
+ end
8
+ end
9
+
5
10
  module GitHubMetadata
6
11
  NoRepositoryError = Class.new(Jekyll::Errors::FatalException)
7
12
 
@@ -14,9 +19,10 @@ module Jekyll
14
19
 
15
20
  class << self
16
21
  attr_accessor :repository
22
+ attr_writer :client
17
23
 
18
24
  def environment
19
- Jekyll.env || Pages.env || 'development'
25
+ Jekyll.respond_to?(:env) ? Jekyll.env : (Pages.env || 'development')
20
26
  end
21
27
 
22
28
  def client
@@ -26,6 +32,8 @@ module Jekyll
26
32
  def values
27
33
  @values ||= Hash.new
28
34
  end
35
+ alias_method :to_h, :values
36
+ alias_method :to_liquid, :to_h
29
37
 
30
38
  def clear_values!
31
39
  @values = Hash.new
@@ -34,27 +42,20 @@ module Jekyll
34
42
  def reset!
35
43
  clear_values!
36
44
  @client = nil
45
+ @repository = nil
37
46
  end
38
47
 
39
48
  def [](key)
40
49
  values[key.to_s]
41
50
  end
42
51
 
43
- def to_h
44
- values
45
- end
46
-
47
- def to_liquid
48
- to_h
49
- end
50
-
51
52
  def register_value(key, value)
52
53
  values[key.to_s] = Value.new(key.to_s, value)
53
54
  end
54
55
 
55
56
  # Reset our values hash.
56
57
  def init!
57
- reset!
58
+ clear_values!
58
59
 
59
60
  # Environment-Specific
60
61
  register_value('environment', proc { environment })
@@ -100,11 +101,15 @@ module Jekyll
100
101
  register_value('url', proc { |_,r| r.pages_url })
101
102
  register_value('contributors', proc { |c,r| c.contributors(r.nwo) })
102
103
  register_value('releases', proc { |c,r| c.releases(r.nwo) })
104
+
105
+ values
106
+ end
107
+
108
+ if Jekyll.const_defined? :Site
109
+ require_relative 'jekyll-github-metadata/ghp_metadata_generator'
103
110
  end
104
111
  end
105
112
 
106
113
  init!
107
114
  end
108
115
  end
109
-
110
- require_relative 'jekyll-github-metadata/ghp_metadata_generator'
@@ -14,21 +14,18 @@ module Jekyll
14
14
 
15
15
  def build_octokit_client(options = nil)
16
16
  options = options || Hash.new
17
- if ENV['JEKYLL_GITHUB_TOKEN'] || Octokit.access_token
18
- options.merge!(:access_token => ENV['JEKYLL_GITHUB_TOKEN'] || Octokit.access_token)
19
- elsif !ENV['NO_NETRC'] && File.exist?(File.join(ENV['HOME'], '.netrc')) && safe_require('netrc')
20
- options.merge!(:netrc => true)
21
- else
22
- Jekyll.logger.warn "GitHubMetadata:", "No GitHub API authentication could be found." +
23
- " Some fields may be missing or have incorrect data."
17
+ unless options.key? :access_token
18
+ options.merge! pluck_auth_method
24
19
  end
25
20
  Octokit::Client.new({:auto_paginate => true}.merge(options))
26
21
  end
27
22
 
28
23
  def method_missing(meth, *args, &block)
29
24
  if @client.respond_to?(meth)
30
- instance_variable_get(:"@#{meth}") ||
31
- instance_variable_set(:"@#{meth}", save_from_errors { @client.send(meth, *args, &block) })
25
+ instance_var_name = meth.to_s.sub('?', '_')
26
+ Jekyll.logger.debug "GitHub Metadata:", "Calling @client.#{meth}(#{args.map(&:inspect).join(", ")})"
27
+ instance_variable_get(:"@#{instance_var_name}") ||
28
+ instance_variable_set(:"@#{instance_var_name}", save_from_errors { @client.send(meth, *args, &block) })
32
29
  else
33
30
  super(meth, *args, &block)
34
31
  end
@@ -46,6 +43,20 @@ module Jekyll
46
43
  Octokit::TooManyRequests
47
44
  default
48
45
  end
46
+
47
+ private
48
+
49
+ def pluck_auth_method
50
+ if ENV['JEKYLL_GITHUB_TOKEN'] || Octokit.access_token
51
+ { :access_token => ENV['JEKYLL_GITHUB_TOKEN'] || Octokit.access_token }
52
+ elsif !ENV['NO_NETRC'] && File.exist?(File.join(ENV['HOME'], '.netrc')) && safe_require('netrc')
53
+ { :netrc => true }
54
+ else
55
+ Jekyll.logger.warn "GitHub Metadata:", "No GitHub API authentication could be found." +
56
+ " Some fields may be missing or have incorrect data."
57
+ {}.freeze
58
+ end
59
+ end
49
60
  end
50
61
  end
51
62
  end
@@ -1,12 +1,11 @@
1
- require 'jekyll'
2
-
3
1
  module Jekyll
4
2
  module GitHubMetadata
5
3
  class GHPMetadataGenerator < Jekyll::Generator
6
4
  def generate(site)
7
5
  Jekyll.logger.debug "Generator:", "Calling GHPMetadataGenerator"
8
- GitHubMetadata.repository = GitHubMetadata::Repository.new(nwo(site))
9
- GitHubMetadata.init!
6
+ initialize_repo! nwo(site)
7
+ Jekyll.logger.debug "GitHub Metadata:", "Generating for #{GitHubMetadata.repository.nwo}"
8
+
10
9
  site.config['github'] =
11
10
  case site.config['github']
12
11
  when nil
@@ -18,6 +17,15 @@ module Jekyll
18
17
  end
19
18
  end
20
19
 
20
+ private
21
+
22
+ def initialize_repo!(repo_nwo)
23
+ if GitHubMetadata.repository.nil? || GitHubMetadata.repository.nwo != repo_nwo
24
+ GitHubMetadata.init!
25
+ GitHubMetadata.repository = GitHubMetadata::Repository.new(repo_nwo)
26
+ end
27
+ end
28
+
21
29
  def nwo(site)
22
30
  ENV['PAGES_REPO_NWO'] || \
23
31
  site.config['repository'] || \
@@ -6,37 +6,58 @@ module Jekyll
6
6
  'PAGES_ENV' => 'dotcom'.freeze,
7
7
  'PAGES_API_URL' => 'https://api.github.com'.freeze,
8
8
  'PAGES_HELP_URL' => 'https://help.github.com'.freeze,
9
- 'PAGES_GITHUB_HOSTNAME' => 'https://github.com'.freeze,
9
+ 'PAGES_GITHUB_HOSTNAME' => 'github.com'.freeze,
10
10
  'PAGES_PAGES_HOSTNAME' => 'github.io'.freeze,
11
- 'SSL' => 'false'.freeze
11
+ 'SSL' => 'false'.freeze,
12
+ 'SUBDOMAIN_ISOLATION' => 'false'.freeze
12
13
  }.freeze
13
14
 
14
15
  def ssl?
15
- env_var('SSL').eql? 'true'
16
+ env_var('SSL') == 'true' || test?
16
17
  end
17
18
 
18
19
  def scheme
19
20
  ssl? ? "https" : "http"
20
21
  end
21
22
 
23
+ def subdomain_isolation?
24
+ env_var('SUBDOMAIN_ISOLATION').eql? 'true'
25
+ end
26
+
27
+ def test?; env == 'test' end
28
+ def dotcom?; env == 'dotcom' end
29
+ def enterprise?; env == 'enterprise' end
30
+
31
+ def custom_domains_enabled?
32
+ dotcom? || test?
33
+ end
34
+
22
35
  def env
23
36
  env_var 'PAGES_ENV'
24
37
  end
25
38
 
39
+ def github_url
40
+ if dotcom?
41
+ "https://github.com".freeze
42
+ else
43
+ "#{scheme}://#{github_hostname}"
44
+ end
45
+ end
46
+
26
47
  def api_url
27
- trim_last_slash env_var('PAGES_API_URL', Octokit.api_endpoint)
48
+ trim_last_slash env_var('PAGES_API_URL', ENV['API_URL'])
28
49
  end
29
50
 
30
51
  def help_url
31
- trim_last_slash env_var('PAGES_HELP_URL')
52
+ trim_last_slash env_var('PAGES_HELP_URL', ENV['HELP_URL'])
32
53
  end
33
54
 
34
55
  def github_hostname
35
- trim_last_slash env_var('PAGES_GITHUB_HOSTNAME', Octokit.web_endpoint)
56
+ trim_last_slash env_var('PAGES_GITHUB_HOSTNAME', ENV['GITHUB_HOSTNAME'])
36
57
  end
37
58
 
38
59
  def pages_hostname
39
- trim_last_slash env_var('PAGES_PAGES_HOSTNAME')
60
+ trim_last_slash env_var('PAGES_PAGES_HOSTNAME', ENV['PAGES_HOSTNAME'])
40
61
  end
41
62
 
42
63
  private
@@ -9,7 +9,7 @@ module Jekyll
9
9
  end
10
10
 
11
11
  def organization_repository?
12
- !!GitHubMetadata.client.organization(owner)
12
+ !!Value.new(proc { |c| c.organization(owner) }).render
13
13
  end
14
14
 
15
15
  def git_ref
@@ -29,7 +29,7 @@ module Jekyll
29
29
  end
30
30
 
31
31
  def owner_url
32
- "#{Pages.github_hostname}/#{owner}"
32
+ "#{Pages.github_url}/#{owner}"
33
33
  end
34
34
 
35
35
  def owner_gravatar_url
@@ -41,7 +41,7 @@ module Jekyll
41
41
  end
42
42
 
43
43
  def repository_url
44
- "#{Pages.github_hostname}/#{nwo}"
44
+ "#{owner_url}/#{name}"
45
45
  end
46
46
 
47
47
  def zip_url
@@ -73,46 +73,79 @@ module Jekyll
73
73
  end
74
74
 
75
75
  def project_page?
76
- !primary?
76
+ !user_page?
77
77
  end
78
78
 
79
- def primary?
80
- user_page_domains.include? name.downcase
79
+ def github_repo?
80
+ !Pages.enterprise? && owner.eql?('github')
81
81
  end
82
82
 
83
- def github_repo?
84
- owner.eql?('github')
83
+ def primary?
84
+ if Pages.enterprise?
85
+ name.downcase == "#{owner.to_s.downcase}.#{Pages.github_hostname}"
86
+ else
87
+ user_page_domains.include? name.downcase
88
+ end
85
89
  end
86
90
 
87
91
  def default_user_domain
88
92
  if github_repo?
89
93
  "#{owner}.#{Pages.github_hostname}".downcase
94
+ elsif Pages.enterprise?
95
+ Pages.pages_hostname.downcase
90
96
  else
91
97
  "#{owner}.#{Pages.pages_hostname}".downcase
92
98
  end
93
99
  end
94
100
 
95
101
  def user_page_domains
96
- [
97
- default_user_domain,
98
- "#{owner}.github.com".downcase # legacy
99
- ]
102
+ domains = [default_user_domain]
103
+ domains.push "#{owner}.github.com".downcase unless Pages.enterprise?
104
+ domains
105
+ end
106
+
107
+ def user_domain
108
+ domain = default_user_domain
109
+ user_page_domains.each do |user_repo|
110
+ candidate_nwo = "#{owner}/#{user_repo}"
111
+ next unless Value.new(proc { |client| client.repository? candidate_nwo }).render
112
+ domain = self.class.new(candidate_nwo).domain
113
+ end
114
+ domain
100
115
  end
101
116
 
102
117
  def pages_url
103
- if cname || primary?
118
+ if !Pages.custom_domains_enabled?
119
+ path = user_page? ? owner : nwo
120
+ if Pages.subdomain_isolation?
121
+ URI.join("#{Pages.scheme}://#{Pages.pages_hostname}/", path).to_s
122
+ else
123
+ URI.join("#{Pages.github_url}/pages/", path).to_s
124
+ end
125
+ elsif cname || primary?
104
126
  "#{Pages.scheme}://#{domain}"
105
127
  else
106
- URI.join("#{Pages.scheme}://#{domain}", "#{name}/")
128
+ URI.join("#{Pages.scheme}://#{domain}", name).to_s
107
129
  end
108
130
  end
109
131
 
110
132
  def cname
133
+ return @cname if defined?(@cname)
134
+ return unless Pages.custom_domains_enabled?
111
135
  @cname ||= (Value.new('cname', proc { |c| c.pages(nwo) }).render || {'cname' => nil})['cname']
112
136
  end
113
137
 
114
138
  def domain
115
- cname || default_user_domain
139
+ @domain ||=
140
+ if !Pages.custom_domains_enabled?
141
+ Pages.github_hostname
142
+ elsif cname # explicit CNAME
143
+ cname
144
+ elsif primary? # user/org repo
145
+ default_user_domain
146
+ else # project repo
147
+ user_domain
148
+ end
116
149
  end
117
150
  end
118
151
  end
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module GitHubMetadata
3
- VERSION = '1.2.0'
3
+ VERSION = '1.3.0'
4
4
  end
5
5
  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: 1.2.0
4
+ version: 1.3.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: 2016-02-05 00:00:00.000000000 Z
11
+ date: 2016-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octokit