-
Notifications
You must be signed in to change notification settings - Fork 158
Expand file tree
/
Copy pathrepository.rb
More file actions
193 lines (161 loc) · 4.83 KB
/
repository.rb
File metadata and controls
193 lines (161 loc) · 4.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
module Jekyll
module GitHubMetadata
class Repository
attr_reader :nwo, :owner, :name
def initialize(name_with_owner)
@nwo = name_with_owner
@owner = nwo.split("/").first
@name = nwo.split("/").last
end
def git_ref
user_page? ? 'master' : 'gh-pages'
end
def repo_info
@repo_info ||= (Value.new(proc { |c| c.repository(nwo) }).render || Hash.new)
end
def language
repo_info["language"]
end
def tagline
repo_info["description"]
end
def owner_url
"#{Pages.github_url}/#{owner}"
end
def owner_gravatar_url
"#{owner_url}.png"
end
def repo_clone_url
"#{repository_url}.git"
end
def repository_url
"#{owner_url}/#{name}"
end
def zip_url
"#{repository_url}/zipball/#{git_ref}"
end
def tar_url
"#{repository_url}/tarball/#{git_ref}"
end
def releases_url
"#{repository_url}/releases"
end
def issues_url
"#{repository_url}/issues" if repo_info["has_issues"]
end
def wiki_url
"#{repository_url}/wiki" if repo_info["has_wiki"]
end
def show_downloads?
!!repo_info["has_downloads"]
end
def organization_repository?
memoize_value :@is_organization_repository, Value.new(proc { |c| !!c.organization(owner) })
end
def owner_public_repositories
memoize_value :@owner_public_repositories, Value.new(proc { |c| c.list_repos(owner) })
end
def organization_public_members
memoize_value :@organization_public_members, Value.new(proc { |c|
c.organization_public_members(owner) if organization_repository?
})
end
def contributors
memoize_value :@contributors, Value.new(proc { |c| c.contributors(nwo) })
end
def releases
memoize_value :@releases, Value.new(proc { |c| c.releases(nwo) })
end
def user_page?
primary?
end
def project_page?
!user_page?
end
def github_repo?
!Pages.enterprise? && owner.eql?('github')
end
def primary?
if Pages.enterprise?
name.downcase == "#{owner.to_s.downcase}.#{Pages.github_hostname}"
else
user_page_domains.include? name.downcase
end
end
# In enterprise, the site's scheme will be the same as the instance's
# In dotcom, this will be `https` for GitHub-owned sites that end with
# `.github.com` and will be `http` for all other sites.
# Note: This is not the same as *instance*'s scheme, which may differ
def url_scheme
if Pages.enterprise?
Pages.scheme
elsif owner == 'github' && domain.end_with?('.github.com')
'https'
else
'http'
end
end
def default_user_domain
if github_repo?
"#{owner}.#{Pages.github_hostname}".downcase
elsif Pages.enterprise?
Pages.pages_hostname.downcase
else
"#{owner}.#{Pages.pages_hostname}".downcase
end
end
def user_page_domains
domains = [default_user_domain]
domains.push "#{owner}.github.com".downcase unless Pages.enterprise?
domains
end
def user_domain
domain = default_user_domain
user_page_domains.each do |user_repo|
candidate_nwo = "#{owner}/#{user_repo}"
next unless Value.new(proc { |client| client.repository? candidate_nwo }).render
domain = self.class.new(candidate_nwo).domain
end
domain
end
def pages_url
if !Pages.custom_domains_enabled?
path = user_page? ? owner : nwo
if Pages.subdomain_isolation?
URI.join("#{Pages.scheme}://#{Pages.pages_hostname}/", path).to_s
else
URI.join("#{Pages.github_url}/pages/", path).to_s
end
elsif cname || primary?
"#{url_scheme}://#{domain}"
else
URI.join("#{url_scheme}://#{domain}", name).to_s
end
end
def cname
memoize_value :@cname, Value.new(proc { |c|
if Pages.custom_domains_enabled?
(c.pages(nwo) || {'cname' => nil})['cname']
end
})
end
def domain
@domain ||=
if !Pages.custom_domains_enabled?
Pages.github_hostname
elsif cname # explicit CNAME
cname
elsif primary? # user/org repo
default_user_domain
else # project repo
user_domain
end
end
private
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
end
end