Skip to content

Support stack versions in versioned plugin docs. #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
:plugin: <%= name %>
:type: <%= type %>
:branch: %BRANCH%
:ecs_version: %ECS_VERSION%

include::{include_path}/version-list-intro.asciidoc[]

Expand Down
46 changes: 42 additions & 4 deletions versioned_plugins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class VersionedPluginDocs < Clamp::Command
"logstash-codec-java_codec_example"
]

VERSIONS_URL = "https://raw.githubusercontent.com/elastic/docs/master/shared/versions/stack/master.asciidoc"

def logstash_docs_path
File.join(output_path, "logstash-docs")
end
Expand All @@ -44,14 +46,15 @@ def docs_path
File.join(output_path, "docs")
end

attr_reader :octo
attr_reader :octo, :logstash_version, :ecs_version

include LogstashDocket

def execute
setup_github_client
check_rate_limit!
clone_docs_repo
fetch_stack_versions
generate_docs
if new_versions?
unless dry_run?
Expand Down Expand Up @@ -374,7 +377,7 @@ def extract_doc(doc, plugin_full_name, release_tag, release_date, changelog_url)
end
end

content
write_stack_versions(content, type)
end

def versions_index_exists?(name, type)
Expand Down Expand Up @@ -405,8 +408,8 @@ def write_alias_index(type, alias_name, target)
File.write(output_asciidoc, content)
end

def lazy_create_output_folder(output_asciidoc)
directory = File.dirname(output_asciidoc)
def lazy_create_output_folder(file_name)
directory = File.dirname(file_name)
FileUtils.mkdir_p(directory) if !File.directory?(directory)
end

Expand All @@ -429,6 +432,41 @@ def load_alias_definitions_for_target_plugins(plugin_names_by_type)

aliases
end

def fetch_stack_versions
stack_versions = Net::HTTP.get(URI.parse(VERSIONS_URL))
@logstash_version = get_logstash_version(stack_versions)
puts "Logstash version: #{@logstash_version}\n"

@ecs_version = get_ecs_version(stack_versions)
puts "ECS version: #{@ecs_version}\n"
end

def get_logstash_version(stack_versions)
stack_versions[/\:logstash_version:\s+(.*?)\n/, 1]
end

def get_ecs_version(stack_versions)
stack_versions[/\:ecs_version:\s+(.*?)\n/, 1]
end

def write_stack_versions(content, type)
# BRANCH and ECS_VERSION are newly added, will be available when every plugin index docs are re-indexed.
# This is a backfill logic to add the fields after :type: entry
if content =~ /\[":branch: %BRANCH%"\]/
type_entry = ":type: #{type}\n"
logstash_version_entry = ":branch: %BRANCH%\n"
ecs_version_entry = ":ecs_version: %ECS_VERSION%\n"
index = content.index(type_entry)
index = index + type_entry.length
content.insert(index, logstash_version_entry)
content.insert(index + logstash_version_entry.length, ecs_version_entry)
end

content = content \
.gsub("%BRANCH%", @logstash_version) \
.gsub("%ECS_VERSION%", @ecs_version)
end
end

if __FILE__ == $0
Expand Down