Commit 7d3c464f authored by Florent Didier's avatar Florent Didier
Browse files

[dev] wiki_generator.rb: add diff_files method

parent febfda55
......@@ -28,6 +28,23 @@ module MediawikiApi
res = get_conn.send(:get, '', params)
res.body
end
def get_file_content(file_name)
get_conn = Faraday.new(url: MW::BASE_URL + "images/#{file_name}") do |faraday|
faraday.request :multipart
faraday.request :url_encoded
faraday.use :cookie_jar, jar: @cookies
faraday.use FaradayMiddleware::FollowRedirects
faraday.adapter Faraday.default_adapter
end
params = {
:token_type => false,
:action => 'raw'
}
params[:token] = get_token(:csrf)
res = get_conn.send(:get, '', params)
res.body
end
def update_file(filename, path, content_type, comment, ignorewarnings, text = nil)
file = Faraday::UploadIO.new(path, content_type)
......
......@@ -53,6 +53,28 @@ class WikiGenerator
}
end
def diff_files
ret = true
@files.each { |file|
if file['content-type'] == 'text/plain'
file_content = @mw_client.get_file_content(file['filename'])
generated_content = File.read(file['path'])
diff = Diffy::Diff.new(file_content, generated_content, :context => 0)
if (diff.to_s.empty?)
puts "No differences found between generated and current content for file #{file['filename']}."
ret &= true
else
puts "Differences between generated and current content for file #{file['filename']}:"
puts '------------ FILE DIFF BEGIN ------------'
puts "#{diff.to_s(:text)}"
puts '------------- FILE DIFF END -------------'
ret &= false
end
end
}
return ret
end
#print generator content to stdout
def print()
puts @generated_content
......@@ -117,7 +139,8 @@ class WikiGenerator
generator.login(options)
end
if (options[:diff])
generator.diff_page
generator.diff_page if generator.instance_variable_get('@generated_content')
generator.diff_files if generator.instance_variable_get('@files')
end
if (options[:print])
generator.print
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment