jekyll-theme-open-project-helpers 2.1.2 → 2.1.7

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
  SHA256:
3
- metadata.gz: ff8126d52bf314ac4b6a39f232dce02bce77a121b22063fc5fb1b62333481c9a
4
- data.tar.gz: 965b43ee7edce41c4901dd7ab92a57a3f2d8ea586f319eaa26d4a38d1aa6e73f
3
+ metadata.gz: e4a49b1b98f4b6a8903466391a01dd42cccc0a80d477614b24bafea89d7af97c
4
+ data.tar.gz: ff35d3b2783bfa70cd8f72fb2336357a2f1e9a8d15ac48f958d5a1a15f4ac2eb
5
5
  SHA512:
6
- metadata.gz: 01f428993882c421af571725613e52e1ab7c4a0ccdc9b4e0a715b3b9efa4a1d963afbf267ee65e48ae45d6223efcafbb324770e9335237841e03cb31d53d8d32
7
- data.tar.gz: c764bbac19e62eb28bd0b42a2196b786cf70a0e2e865ef313b3b843e4266eec850e3c6586bc93ca8fd3d75464fcdb7240c2fd6b555efe4b8c641652617b694db
6
+ metadata.gz: 845c40b2a93ab03c99fff74050da48d099329a430625929e1630625be95c55b1321882ba120dbf5670b53b9769be41ad4d9a9c70ce19b24337af756d785fb9b8
7
+ data.tar.gz: 715deb4ae224a58c8084f9eb8f538bc0217b7be91601c0a77b7f934dbf52fc8d5c58455c073bd281a1fc1c736783f469bbbe10df23b013af8b6ae99610388e54
data/README.md CHANGED
@@ -12,7 +12,7 @@ fetching open project/software/specification data from their repos.
12
12
  ## Releasing
13
13
 
14
14
  **Release this helpers gem and theme gem in tandem with matching versions.**
15
- See [https://github.com/riboseinc/jekyll-theme-open-project-helpers](theme gem docs) for more.
15
+ See [Theme gem docs](https://github.com/riboseinc/jekyll-theme-open-project) for more.
16
16
 
17
17
 
18
18
  1. Inside .gemspec within this repo’s root, update main gem version to the one being released.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'jekyll-theme-open-project-helpers'
5
- s.version = '2.1.2'
5
+ s.version = '2.1.7'
6
6
  s.authors = ['Ribose Inc.']
7
7
  s.email = ['open.source@ribose.com']
8
8
 
@@ -6,7 +6,9 @@ module Jekyll
6
6
  DEFAULT_DOCS_SUBTREE = 'docs'
7
7
 
8
8
  DEFAULT_REPO_REMOTE_NAME = 'origin'
9
- DEFAULT_REPO_BRANCH = 'master'
9
+ DEFAULT_REPO_BRANCH = 'main'
10
+ # Can be overridden by default_repo_branch in site config.
11
+ # Used by shallow_git_checkout.
10
12
 
11
13
  class NonLiquidDocument < Jekyll::Document
12
14
  def render_with_liquid?
@@ -42,12 +44,14 @@ module Jekyll
42
44
  doc.read
43
45
 
44
46
  # Add document to Jekyll document database if it refers to software or spec
45
- # (as opposed to be some nested document like README)
46
- if (doc.url.split('/').size == 4) or (doc.url.split('/').size == 5 and collection.label === 'projects')
47
+ # (as opposed to be some random nested document within repository source, like a README)
48
+ doc_url_parts = doc.url.split('/')
49
+ Jekyll.logger.debug("OPF:", "Reading document in collection #{collection.label} with URL #{doc.url} (#{doc_url_parts.size} parts)")
50
+ if collection.label != 'projects' or doc_url_parts.size == 5
47
51
  Jekyll.logger.debug("OPF:", "Adding document with URL: #{doc.url}")
48
52
  collection.docs << doc
49
53
  else
50
- Jekyll.logger.debug("OPF:", "Did NOT add document with URL (nesting level doesn’t match): #{doc.url}")
54
+ Jekyll.logger.debug("OPF:", "Did NOT add document with URL (possibly nesting level doesn’t match): #{doc.url}")
51
55
  end
52
56
  else
53
57
  Jekyll.logger.debug("OPF:", "Adding static file: #{path}")
@@ -93,7 +97,8 @@ module Jekyll
93
97
  git_shallow_checkout(
94
98
  File.join(@site.source, 'parent-hub'),
95
99
  @site.config['parent_hub']['git_repo_url'],
96
- ['assets', 'title.html'])
100
+ ['assets', 'title.html'],
101
+ @site.config['parent_hub']['git_repo_branch'])
97
102
  end
98
103
  end
99
104
 
@@ -108,7 +113,8 @@ module Jekyll
108
113
  git_shallow_checkout(
109
114
  project_path,
110
115
  project['site']['git_repo_url'],
111
- ['assets', '_posts', '_software', '_specs'])
116
+ ['assets', '_posts', '_software', '_specs'],
117
+ project['site']['git_repo_branch'])
112
118
 
113
119
 
114
120
  Jekyll.logger.debug("OPF:", "Reading files in project #{project_path}")
@@ -129,6 +135,7 @@ module Jekyll
129
135
  src = index_doc.data['spec_source']
130
136
  repo_url = src['git_repo_url']
131
137
  repo_subtree = src['git_repo_subtree']
138
+ repo_branch = src['git_repo_branch']
132
139
  build = src['build']
133
140
  engine = build['engine']
134
141
  engine_opts = build['options'] || {}
@@ -140,13 +147,9 @@ module Jekyll
140
147
  spec_checkout_path
141
148
  end
142
149
 
143
- repo_checkout = nil
144
- begin
145
- repo_checkout = git_shallow_checkout(spec_checkout_path, repo_url, [repo_subtree])
146
- rescue
147
- end
150
+ repo_checkout = git_shallow_checkout(spec_checkout_path, repo_url, [repo_subtree], repo_branch)
148
151
 
149
- if repo_checkout
152
+ if repo_checkout[:success]
150
153
  if build_pages
151
154
  builder = Jekyll::OpenProjectHelpers::SpecBuilder::new(
152
155
  @site,
@@ -217,19 +220,17 @@ module Jekyll
217
220
 
218
221
  docs = index_doc.data['docs']
219
222
  main_repo = index_doc.data['repo_url']
223
+ main_repo_branch = index_doc.data['repo_branch']
220
224
 
221
225
  sw_docs_repo = (if docs then docs['git_repo_url'] end) || main_repo
222
226
  sw_docs_subtree = (if docs then docs['git_repo_subtree'] end) || DEFAULT_DOCS_SUBTREE
227
+ sw_docs_branch = (if docs then docs['git_repo_branch'] end) || main_repo_branch
223
228
 
224
229
  docs_path = "#{index_doc.path.split('/')[0..-2].join('/')}/#{item_name}"
225
230
 
226
- sw_docs_checkout = nil
227
- begin
228
- sw_docs_checkout = git_shallow_checkout(docs_path, sw_docs_repo, [sw_docs_subtree])
229
- rescue
230
- end
231
+ sw_docs_checkout = git_shallow_checkout(docs_path, sw_docs_repo, [sw_docs_subtree], sw_docs_branch)
231
232
 
232
- if sw_docs_checkout
233
+ if sw_docs_checkout[:success]
233
234
  CollectionDocReader.new(site).read(
234
235
  docs_path,
235
236
  @site.collections[collection_name])
@@ -238,9 +239,9 @@ module Jekyll
238
239
  # Get last repository modification timestamp.
239
240
  # Fetch the repository for that purpose,
240
241
  # unless it’s the same as the repo where docs are.
241
- if sw_docs_checkout == nil or sw_docs_repo != main_repo
242
+ if !sw_docs_checkout[:success] or sw_docs_repo != main_repo
242
243
  repo_path = "#{index_doc.path.split('/')[0..-2].join('/')}/_#{item_name}_repo"
243
- repo_checkout = git_shallow_checkout(repo_path, main_repo)
244
+ repo_checkout = git_shallow_checkout(repo_path, main_repo, [], main_repo_branch)
244
245
  index_doc.merge_data!({ 'last_update' => repo_checkout[:modified_at] })
245
246
  else
246
247
  index_doc.merge_data!({ 'last_update' => sw_docs_checkout[:modified_at] })
@@ -248,7 +249,7 @@ module Jekyll
248
249
  end
249
250
  end
250
251
 
251
- def git_shallow_checkout(repo_path, remote_url, sparse_subtrees=[])
252
+ def git_shallow_checkout(repo_path, remote_url, sparse_subtrees, branch_name)
252
253
  # Returns hash with timestamp of latest repo commit
253
254
  # and boolean signifying whether new repo has been initialized
254
255
  # in the process of pulling the data.
@@ -285,6 +286,7 @@ module Jekyll
285
286
  end
286
287
 
287
288
  refresh_condition = @@siteconfig['refresh_remote_data'] || 'last-resort'
289
+ repo_branch = branch_name || @@siteconfig['default_repo_branch'] || DEFAULT_REPO_BRANCH
288
290
 
289
291
  unless ['always', 'last-resort', 'skip'].include?(refresh_condition)
290
292
  raise RuntimeError.new('Invalid refresh_remote_data value in site’s _config.yml!')
@@ -293,23 +295,42 @@ module Jekyll
293
295
  if refresh_condition == 'always'
294
296
  repo.fetch(DEFAULT_REPO_REMOTE_NAME, { :depth => 1 })
295
297
  repo.reset_hard
296
- repo.checkout("#{DEFAULT_REPO_REMOTE_NAME}/#{DEFAULT_REPO_BRANCH}", { :f => true })
298
+ repo.checkout("#{DEFAULT_REPO_REMOTE_NAME}/#{repo_branch}", { :f => true })
297
299
 
298
300
  elsif refresh_condition == 'last-resort'
301
+ # This is the default case.
302
+
299
303
  begin
300
- repo.checkout("#{DEFAULT_REPO_REMOTE_NAME}/#{DEFAULT_REPO_BRANCH}", { :f => true })
304
+ # Let’s try in case this repo has been fetched before (this would never be the case on CI though)
305
+ repo.checkout("#{DEFAULT_REPO_REMOTE_NAME}/#{repo_branch}", { :f => true })
301
306
  rescue Exception => e
302
- if e.message.include? "Sparse checkout leaves no entry on working directory"
303
- # Supposedly, software docs are missing! No big deal.
307
+ if is_sparse_checkout_error(e, sparse_subtrees)
308
+ # Silence errors caused by nonexistent sparse checkout directories
304
309
  return {
305
310
  :success => false,
306
311
  :newly_initialized => nil,
307
312
  :modified_at => nil,
308
313
  }
309
314
  else
315
+ # In case of any other error, presume repo has not been fetched and do that now.
310
316
  Jekyll.logger.debug("OPF:", "Fetching & checking out #{remote_url} for #{repo_path}")
311
317
  repo.fetch(DEFAULT_REPO_REMOTE_NAME, { :depth => 1 })
312
- repo.checkout("#{DEFAULT_REPO_REMOTE_NAME}/#{DEFAULT_REPO_BRANCH}", { :f => true })
318
+ begin
319
+ # Try checkout again
320
+ repo.checkout("#{DEFAULT_REPO_REMOTE_NAME}/#{repo_branch}", { :f => true })
321
+ rescue Exception => e
322
+ if is_sparse_checkout_error(e, sparse_subtrees)
323
+ # Again, silence an error caused by nonexistent sparse checkout directories…
324
+ return {
325
+ :success => false,
326
+ :newly_initialized => nil,
327
+ :modified_at => nil,
328
+ }
329
+ else
330
+ # but this time throw any other error.
331
+ raise e
332
+ end
333
+ end
313
334
  end
314
335
  end
315
336
  end
@@ -327,6 +348,15 @@ module Jekyll
327
348
  end
328
349
  end
329
350
 
351
+ def is_sparse_checkout_error(err, subtrees)
352
+ if err.message.include? "Sparse checkout leaves no entry on working directory"
353
+ Jekyll.logger.debug("OPF: It looks like sparse checkout of these directories failed:", subtrees.to_s)
354
+ true
355
+ else
356
+ false
357
+ end
358
+ end
359
+
330
360
  Jekyll::Hooks.register :site, :after_init do |site|
331
361
  if site.theme # TODO: Check theme name
332
362
  site.reader = Jekyll::OpenProjectHelpers::OpenProjectReader::new(site)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-theme-open-project-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-05 00:00:00.000000000 Z
11
+ date: 2021-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -80,7 +80,7 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0.50'
83
- description:
83
+ description:
84
84
  email:
85
85
  - open.source@ribose.com
86
86
  executables: []
@@ -104,7 +104,7 @@ homepage: https://github.com/riboseinc/jekyll-theme-open-project-helpers/
104
104
  licenses:
105
105
  - MIT
106
106
  metadata: {}
107
- post_install_message:
107
+ post_install_message:
108
108
  rdoc_options: []
109
109
  require_paths:
110
110
  - lib
@@ -119,8 +119,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
119
  - !ruby/object:Gem::Version
120
120
  version: '0'
121
121
  requirements: []
122
- rubygems_version: 3.0.3
123
- signing_key:
122
+ rubygems_version: 3.0.6
123
+ signing_key:
124
124
  specification_version: 4
125
125
  summary: Helpers for the Open Project Jekyll theme
126
126
  test_files: []