diff --git a/rake_tasks/doc_generator.rake b/rake_tasks/doc_generator.rake index 49a4e1937d..5d26cdb8d1 100644 --- a/rake_tasks/doc_generator.rake +++ b/rake_tasks/doc_generator.rake @@ -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 = { @@ -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 @@ -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}'" @@ -130,7 +138,7 @@ 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 @@ -138,11 +146,11 @@ namespace :docs do .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) @@ -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 #