History

Fix "thor docs:upload --packaged" not finding docs whose slug is different than name

Thibaut Courouble committed 7 years ago

Commit 3b39fa71 parent 817dac12 files · +31 −2Browse files

Unified · Split

2 files
  1. lib/docs.rb +16 −0
  2. lib/tasks/docs.thor +15 −2
lib/docs.rb+16−0
@@ -74,6 +74,22 @@ module Docs · 73 unmodified lines
74 end74 end
75 end75 end
76 76
77 def self.find_by_slug(slug, version = nil)
78 doc = all.find { |klass| klass.slug == slug }
79
80 unless doc
81 raise DocNotFound.new(%(could not find doc with "#{slug}"), slug)
82 end
83
84 if version.present?
85 version = doc.versions.find { |klass| klass.version == version || klass.version_slug == version }
86 raise DocNotFound.new(%(could not find version "#{version}" for doc "#{doc.name}"), doc.name) unless version
87 doc = version
88 end
89
90 doc
91 end
92
77 def self.generate_page(name, version, page_id)93 def self.generate_page(name, version, page_id)
78 find(name, version).store_page(store, page_id)94 find(name, version).store_page(store, page_id)
79 end95 end
lib/tasks/docs.thor+15−2
@@ -158,8 +158,14 @@ class DocsCLI < Thor · 157 unmodified lines
158 option :packaged, type: :boolean158 option :packaged, type: :boolean
159 def upload(*names)159 def upload(*names)
160 require 'net/sftp'160 require 'net/sftp'
161 names = Dir[File.join(Docs.store_path, '*.tar.gz')].map { |f| File.basename(f, '.tar.gz') } if options[:packaged]161
162 docs = find_docs(names)162 if options[:packaged]
163 slugs = Dir[File.join(Docs.store_path, '*.tar.gz')].map { |f| File.basename(f, '.tar.gz') }
164 docs = find_docs_by_slugs(slugs)
165 else
166 docs = find_docs(names)
167 end
168
163 assert_docs(docs)169 assert_docs(docs)
164 170
165 # Sync files with S3 (used by the web app)171 # Sync files with S3 (used by the web app)
@@ -251,6 +257,13 @@ class DocsCLI < Thor · 85 unmodified lines
251 end257 end
252 end258 end
253 259
260 def find_docs_by_slugs(slugs)
261 slugs.flat_map do |slug|
262 slug, version = slug.split(/~/)
263 Docs.find_by_slug(slug, version)
264 end
265 end
266
254 def assert_docs(docs)267 def assert_docs(docs)
255 if docs.empty?268 if docs.empty?
256 puts 'ERROR: called with no arguments.'269 puts 'ERROR: called with no arguments.'