Thanks to visit codestin.com
Credit goes to github.com

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
1 change: 1 addition & 0 deletions lib/jekyll-github-metadata/metadata_drop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def keys
def_delegator :repository, :releases, :releases
def_delegator :repository, :latest_release, :latest_release
def_delegator :repository, :private?, :private
def_delegator :repository, :license, :license

def versions
@versions ||= begin
Expand Down
70 changes: 33 additions & 37 deletions lib/jekyll-github-metadata/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,34 @@ module Jekyll
module GitHubMetadata
class Repository
attr_reader :nwo, :owner, :name

# Defines an instance method that delegates to a hash's key
#
# hash - a symbol representing the instance method to delegate to. The
# instance method should return a hash or respond to #[]
# key - the key to call within the hash
# method - (optional) the instance method the key should be aliased to.
# If not specified, defaults to the hash key
#
# Returns a symbol representing the instance method
def self.def_hash_delegator(hash, key, method)
define_method(method || key) do
public_send(hash)[key.to_s]
end
end

extend Forwardable
def_hash_delegator :repo_info, :license, :license
def_hash_delegator :repo_info, :language, :language
def_hash_delegator :repo_info, :description, :tagline
def_hash_delegator :repo_info, :has_downloads, :show_downloads?
def_hash_delegator :repo_info, :private, :private?
def_hash_delegator :latest_release, :url, :latest_release_url

def_delegator :uri, :host, :domain
def_delegator :uri, :scheme, :url_scheme
def_delegator :uri, :path, :baseurl

def initialize(name_with_owner)
@nwo = name_with_owner
@owner = nwo.split("/").first
Expand All @@ -13,7 +41,10 @@ def repo_compat
end

def repo_info
@repo_info ||= (Value.new(proc { |c| c.repository(nwo) }).render || {})
@repo_info ||= begin
options = { :accept => "application/vnd.github.drax-preview+json" }
(Value.new(proc { |c| c.repository(nwo, options) }).render || {})
end
end

def repo_pages_info
Expand All @@ -28,14 +59,6 @@ def repo_pages_info_opts
end
end

def language
repo_info["language"]
end

def tagline
repo_info["description"]
end

def owner_url
"#{Pages.github_url}/#{owner}"
end
Expand Down Expand Up @@ -64,10 +87,6 @@ def releases_url
"#{repository_url}/releases"
end

def latest_release_url
latest_release["url"]
end

def issues_url
"#{repository_url}/issues" if repo_info["has_issues"]
end
Expand All @@ -76,14 +95,6 @@ def wiki_url
"#{repository_url}/wiki" if repo_info["has_wiki"]
end

def show_downloads?
!!repo_info["has_downloads"]
end

def private?
!!repo_info["private"]
end

def organization_repository?
memoize_value :@is_organization_repository, Value.new(proc { |c| !!c.organization(owner) })
end
Expand Down Expand Up @@ -118,10 +129,6 @@ def git_ref
end
end

def user_page?
primary?
end

def project_page?
!user_page?
end
Expand All @@ -137,6 +144,7 @@ def primary?
user_page_domains.include? name.downcase
end
end
alias_method :user_page?, :primary?

def user_page_domains
domains = [default_user_domain]
Expand Down Expand Up @@ -171,18 +179,6 @@ def url_without_path
uri.dup.tap { |u| u.path = "" }.to_s
end

def domain
uri.host
end

def url_scheme
uri.scheme
end

def baseurl
uri.path
end

private

def memoize_value(var_name, value)
Expand Down
2 changes: 1 addition & 1 deletion spec/site_github_munger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
let(:user_config) { {} }
let(:site) { Jekyll::Site.new(Jekyll::Configuration.from(user_config)) }
subject { described_class.new(site) }
let!(:stubs) { stub_all_api_requests }

context "generating" do
let!(:stubs) { stub_all_api_requests }
before(:each) do
ENV["JEKYLL_ENV"] = "production"
subject.munge!
Expand Down
3 changes: 2 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

module WebMockHelper
REQUEST_HEADERS = {
"Accept" => "application/vnd.github.v3+json",
"Accept" => %r!application/vnd\.github\.(v3|drax-preview)\+json!,
"Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
"Content-Type" => "application/json",
"User-Agent" => "Octokit Ruby Gem #{Octokit::VERSION}",
Expand Down Expand Up @@ -149,6 +149,7 @@ def expected_values
"releases" => %r!"tag_name"=>"v1.1.0"!,
"latest_release" => %r!assets_url!,
"private" => false,
"license" => %r!"key"=>"mit"!,
}
end

Expand Down
2 changes: 1 addition & 1 deletion spec/webmock/api_get_repo.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"id":24088214,"name":"github-metadata","full_name":"jekyll/github-metadata","owner":{"login":"jekyll","id":3083652,"avatar_url":"https://avatars.githubusercontent.com/u/3083652?v=3","gravatar_id":"","url":"https://api.github.com/users/jekyll","html_url":"https://github.com/jekyll","followers_url":"https://api.github.com/users/jekyll/followers","following_url":"https://api.github.com/users/jekyll/following{/other_user}","gists_url":"https://api.github.com/users/jekyll/gists{/gist_id}","starred_url":"https://api.github.com/users/jekyll/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jekyll/subscriptions","organizations_url":"https://api.github.com/users/jekyll/orgs","repos_url":"https://api.github.com/users/jekyll/repos","events_url":"https://api.github.com/users/jekyll/events{/privacy}","received_events_url":"https://api.github.com/users/jekyll/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/jekyll/github-metadata","description":":octocat: `site.github`","fork":false,"url":"https://api.github.com/repos/jekyll/github-metadata","forks_url":"https://api.github.com/repos/jekyll/github-metadata/forks","keys_url":"https://api.github.com/repos/jekyll/github-metadata/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jekyll/github-metadata/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jekyll/github-metadata/teams","hooks_url":"https://api.github.com/repos/jekyll/github-metadata/hooks","issue_events_url":"https://api.github.com/repos/jekyll/github-metadata/issues/events{/number}","events_url":"https://api.github.com/repos/jekyll/github-metadata/events","assignees_url":"https://api.github.com/repos/jekyll/github-metadata/assignees{/user}","branches_url":"https://api.github.com/repos/jekyll/github-metadata/branches{/branch}","tags_url":"https://api.github.com/repos/jekyll/github-metadata/tags","blobs_url":"https://api.github.com/repos/jekyll/github-metadata/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jekyll/github-metadata/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jekyll/github-metadata/git/refs{/sha}","trees_url":"https://api.github.com/repos/jekyll/github-metadata/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jekyll/github-metadata/statuses/{sha}","languages_url":"https://api.github.com/repos/jekyll/github-metadata/languages","stargazers_url":"https://api.github.com/repos/jekyll/github-metadata/stargazers","contributors_url":"https://api.github.com/repos/jekyll/github-metadata/contributors","subscribers_url":"https://api.github.com/repos/jekyll/github-metadata/subscribers","subscription_url":"https://api.github.com/repos/jekyll/github-metadata/subscription","commits_url":"https://api.github.com/repos/jekyll/github-metadata/commits{/sha}","git_commits_url":"https://api.github.com/repos/jekyll/github-metadata/git/commits{/sha}","comments_url":"https://api.github.com/repos/jekyll/github-metadata/comments{/number}","issue_comment_url":"https://api.github.com/repos/jekyll/github-metadata/issues/comments{/number}","contents_url":"https://api.github.com/repos/jekyll/github-metadata/contents/{+path}","compare_url":"https://api.github.com/repos/jekyll/github-metadata/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jekyll/github-metadata/merges","archive_url":"https://api.github.com/repos/jekyll/github-metadata/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jekyll/github-metadata/downloads","issues_url":"https://api.github.com/repos/jekyll/github-metadata/issues{/number}","pulls_url":"https://api.github.com/repos/jekyll/github-metadata/pulls{/number}","milestones_url":"https://api.github.com/repos/jekyll/github-metadata/milestones{/number}","notifications_url":"https://api.github.com/repos/jekyll/github-metadata/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jekyll/github-metadata/labels{/name}","releases_url":"https://api.github.com/repos/jekyll/github-metadata/releases{/id}","deployments_url":"https://api.github.com/repos/jekyll/github-metadata/deployments","created_at":"2014-09-16T06:32:03Z","updated_at":"2016-01-30T15:32:29Z","pushed_at":"2016-02-05T20:28:20Z","git_url":"git://github.com/jekyll/github-metadata.git","ssh_url":"[email protected]:jekyll/github-metadata.git","clone_url":"https://github.com/jekyll/github-metadata.git","svn_url":"https://github.com/jekyll/github-metadata","homepage":"https://help.github.com/articles/repository-metadata-on-github-pages","size":67,"stargazers_count":22,"watchers_count":22,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":5,"forks":4,"open_issues":5,"watchers":22,"default_branch":"master","permissions":{"admin":true,"push":true,"pull":true},"organization":{"login":"jekyll","id":3083652,"avatar_url":"https://avatars.githubusercontent.com/u/3083652?v=3","gravatar_id":"","url":"https://api.github.com/users/jekyll","html_url":"https://github.com/jekyll","followers_url":"https://api.github.com/users/jekyll/followers","following_url":"https://api.github.com/users/jekyll/following{/other_user}","gists_url":"https://api.github.com/users/jekyll/gists{/gist_id}","starred_url":"https://api.github.com/users/jekyll/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jekyll/subscriptions","organizations_url":"https://api.github.com/users/jekyll/orgs","repos_url":"https://api.github.com/users/jekyll/repos","events_url":"https://api.github.com/users/jekyll/events{/privacy}","received_events_url":"https://api.github.com/users/jekyll/received_events","type":"Organization","site_admin":false},"network_count":4,"subscribers_count":5}
{"id":24088214,"name":"github-metadata","full_name":"jekyll/github-metadata","owner":{"login":"jekyll","id":3083652,"avatar_url":"https://avatars.githubusercontent.com/u/3083652?v=3","gravatar_id":"","url":"https://api.github.com/users/jekyll","html_url":"https://github.com/jekyll","followers_url":"https://api.github.com/users/jekyll/followers","following_url":"https://api.github.com/users/jekyll/following{/other_user}","gists_url":"https://api.github.com/users/jekyll/gists{/gist_id}","starred_url":"https://api.github.com/users/jekyll/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jekyll/subscriptions","organizations_url":"https://api.github.com/users/jekyll/orgs","repos_url":"https://api.github.com/users/jekyll/repos","events_url":"https://api.github.com/users/jekyll/events{/privacy}","received_events_url":"https://api.github.com/users/jekyll/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/jekyll/github-metadata","description":":octocat: `site.github`","fork":false,"url":"https://api.github.com/repos/jekyll/github-metadata","forks_url":"https://api.github.com/repos/jekyll/github-metadata/forks","keys_url":"https://api.github.com/repos/jekyll/github-metadata/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jekyll/github-metadata/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jekyll/github-metadata/teams","hooks_url":"https://api.github.com/repos/jekyll/github-metadata/hooks","issue_events_url":"https://api.github.com/repos/jekyll/github-metadata/issues/events{/number}","events_url":"https://api.github.com/repos/jekyll/github-metadata/events","assignees_url":"https://api.github.com/repos/jekyll/github-metadata/assignees{/user}","branches_url":"https://api.github.com/repos/jekyll/github-metadata/branches{/branch}","tags_url":"https://api.github.com/repos/jekyll/github-metadata/tags","blobs_url":"https://api.github.com/repos/jekyll/github-metadata/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jekyll/github-metadata/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jekyll/github-metadata/git/refs{/sha}","trees_url":"https://api.github.com/repos/jekyll/github-metadata/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jekyll/github-metadata/statuses/{sha}","languages_url":"https://api.github.com/repos/jekyll/github-metadata/languages","stargazers_url":"https://api.github.com/repos/jekyll/github-metadata/stargazers","contributors_url":"https://api.github.com/repos/jekyll/github-metadata/contributors","subscribers_url":"https://api.github.com/repos/jekyll/github-metadata/subscribers","subscription_url":"https://api.github.com/repos/jekyll/github-metadata/subscription","commits_url":"https://api.github.com/repos/jekyll/github-metadata/commits{/sha}","git_commits_url":"https://api.github.com/repos/jekyll/github-metadata/git/commits{/sha}","comments_url":"https://api.github.com/repos/jekyll/github-metadata/comments{/number}","issue_comment_url":"https://api.github.com/repos/jekyll/github-metadata/issues/comments{/number}","contents_url":"https://api.github.com/repos/jekyll/github-metadata/contents/{+path}","compare_url":"https://api.github.com/repos/jekyll/github-metadata/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jekyll/github-metadata/merges","archive_url":"https://api.github.com/repos/jekyll/github-metadata/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jekyll/github-metadata/downloads","issues_url":"https://api.github.com/repos/jekyll/github-metadata/issues{/number}","pulls_url":"https://api.github.com/repos/jekyll/github-metadata/pulls{/number}","milestones_url":"https://api.github.com/repos/jekyll/github-metadata/milestones{/number}","notifications_url":"https://api.github.com/repos/jekyll/github-metadata/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jekyll/github-metadata/labels{/name}","releases_url":"https://api.github.com/repos/jekyll/github-metadata/releases{/id}","deployments_url":"https://api.github.com/repos/jekyll/github-metadata/deployments","created_at":"2014-09-16T06:32:03Z","updated_at":"2016-01-30T15:32:29Z","pushed_at":"2016-02-05T20:28:20Z","git_url":"git://github.com/jekyll/github-metadata.git","ssh_url":"[email protected]:jekyll/github-metadata.git","clone_url":"https://github.com/jekyll/github-metadata.git","svn_url":"https://github.com/jekyll/github-metadata","homepage":"https://help.github.com/articles/repository-metadata-on-github-pages","size":67,"stargazers_count":22,"watchers_count":22,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":5,"forks":4,"open_issues":5,"watchers":22,"default_branch":"master","permissions":{"admin":true,"push":true,"pull":true},"organization":{"login":"jekyll","id":3083652,"avatar_url":"https://avatars.githubusercontent.com/u/3083652?v=3","gravatar_id":"","url":"https://api.github.com/users/jekyll","html_url":"https://github.com/jekyll","followers_url":"https://api.github.com/users/jekyll/followers","following_url":"https://api.github.com/users/jekyll/following{/other_user}","gists_url":"https://api.github.com/users/jekyll/gists{/gist_id}","starred_url":"https://api.github.com/users/jekyll/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jekyll/subscriptions","organizations_url":"https://api.github.com/users/jekyll/orgs","repos_url":"https://api.github.com/users/jekyll/repos","events_url":"https://api.github.com/users/jekyll/events{/privacy}","received_events_url":"https://api.github.com/users/jekyll/received_events","type":"Organization","site_admin":false},"network_count":4,"subscribers_count":5,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"}}