Skip to content
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

Updates docs generation tooling #2276

Merged
merged 3 commits into from
Jan 5, 2024
Merged
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
25 changes: 20 additions & 5 deletions rake_tasks/doc_generator.rake
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ namespace :docs do
generate_docs(entry)
end
puts "Finished generating #{entries.length} files in #{Time.now.to_i - start_time} seconds"
delete_first_log_line
end

desc 'Update report'
task :update do
task :update, [:branch] do |_, args|
require 'elastic-transport'
github_token = File.read(File.expand_path("~/.elastic/github.token"))
transport_options = {
Expand All @@ -60,9 +61,16 @@ namespace :docs do
transport_options:transport_options
)
path = '/repos/elastic/clients-flight-recorder/contents/recordings/docs/parsed-alternative-report.json'
path = "#{path}?ref=#{args[:branch]}" if args[:branch]
params = {}
response = client.perform_request('GET', path, params)
File.write(File.expand_path('./docs/parsed_alternative_report.json', __dir__), response.body)
puts "Downloaded report for #{args[:branch] ? args[:branch] : 'main' } branch"
end

desc 'Add files from 200-ok log'
task :add_files do
`cat log/200-ok.log | xargs git add`
end

def json_data
Expand Down Expand Up @@ -121,7 +129,7 @@ namespace :docs do
template.gsub(/\s+$/, '')
end

def self.show_parameters(params)
def show_parameters(params)
param_string = []
params.each do |k, v|
value = (is_number?(v) || is_boolean?(v)) ? v : "'#{v}'"
Expand All @@ -130,19 +138,19 @@ namespace :docs do
param_string.join(",\n\s\s")
end

def self.show_body(body)
def show_body(body)
'body: ' +
JSON.pretty_generate(body)
.gsub(/\"([a-z_]+)\":/,'\\1: ') # Use Ruby 2 hash syntax
.gsub(/"([a-z_.]+\.[a-z_]+)+":/, '"\\1" =>')
.gsub('aggs', 'aggregations') # Replace 'aggs' with 'aggregations' for consistency
end

def self.is_number?(value)
def is_number?(value)
Float(value) || Integer(value) rescue false
end

def self.is_boolean?(value)
def is_boolean?(value)
(['false', 'true'].include? value) ||
value.is_a?(TrueClass) ||
value.is_a?(FalseClass)
Expand All @@ -158,6 +166,13 @@ namespace :docs do
SRC
end
end

def delete_first_log_line
logfile = File.expand_path(__dir__ + '/../log/200-ok.log')
content = IO.readlines(logfile, chomp: true)
puts content.shift
File.write(logfile, content.first)
end
end

#
Expand Down
Loading