Skip to content

Commit 0623690

Browse files
committed
update-book2: optionally discover downloads even in local_genbook2
There used to be convenient download links for some of the ProGit book translations. In the transition to a Hugo-generated site, these links were lost for all except the original English version, where the downloads were hard-coded. The reason is that in the Hugo world, we want to avoid network-heavy roundtrips that would be necessary when using the `remote_genbook2` function, and we use `local_genbook2` instead, where the information about what downloadable assets there are (if any) is simply not there. Let's add a way to discover the downloadable assets, by using Octokit, but still use the local clone for the rest of the generation. The way to enable this is by providing a `GITHUB_API_TOKEN` environment variable. If that environment variable is not set, no dynamic discovery will be performed. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 4853ec5 commit 0623690

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

script/update-book2.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,11 @@ def local_genbook2(language_code, worktree_path)
305305
raise e
306306
end
307307
book.sha = `git -C "#{worktree_path}" rev-parse HEAD`.chomp
308-
if language_code == 'en'
308+
access_token = ENV.fetch("GITHUB_API_TOKEN", nil)
309+
if access_token && Book.all_books[language_code]
310+
@octokit = Octokit::Client.new(access_token:)
311+
update_downloads(book, Book.all_books[language_code], @octokit)
312+
elsif language_code == 'en'
309313
latest_tag = `git -C "#{worktree_path}" for-each-ref --format '%(refname:short)' --sort=-committerdate --count=1 refs/tags/`.chomp
310314
if latest_tag.empty?
311315
puts "No tag found in #{worktree_path}, trying to fetch tags"

0 commit comments

Comments
 (0)