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
7474 end
7575 end
7676
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+
7793 def self.generate_page(name, version, page_id)
7894 find(name, version).store_page(store, page_id)
7995 end
lib/tasks/docs.thor+15−2
@@ -158,8 +158,14 @@ class DocsCLI < Thor · 157 unmodified lines
158158 option :packaged, type: :boolean
159159 def upload(*names)
160160 require 'net/sftp'
161− names = Dir[File.join(Docs.store_path, '*.tar.gz')].map { |f| File.basename(f, '.tar.gz') } if options[:packaged]
162− docs = find_docs(names)
161+
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+
163169 assert_docs(docs)
164170
165171 # Sync files with S3 (used by the web app)
@@ -251,6 +257,13 @@ class DocsCLI < Thor · 85 unmodified lines
251257 end
252258 end
253259
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+
254267 def assert_docs(docs)
255268 if docs.empty?
256269 puts 'ERROR: called with no arguments.'