Skip to content

Commit 4cd376f

Browse files
author
Lucas Nussbaum
committed
[dev/wiki] do not update if no changes to make
1 parent 0e2d3ef commit 4cd376f

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

generators/wiki/lib/wiki_generator.rb

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,13 @@ def generated_date_string
5454

5555
#Actually edit the mediawiki page with the new generated content
5656
def update_page
57-
@mw_client.edit({"title" => @page_name, "text" => @generated_content })
57+
wiki_content = remove_page_creation_date(@mw_client.get_page_content(@page_name)).strip # .strip removes potential '\n' at end of file
58+
generated_content = remove_page_creation_date(@generated_content).strip
59+
if wiki_content == generated_content
60+
puts "No modification on #{@page_name}, skipping update"
61+
else
62+
@mw_client.edit({"title" => @page_name, "text" => @generated_content })
63+
end
5864
end
5965

6066
#Get the given page content and print a diff if any
@@ -75,9 +81,15 @@ def diff_page()
7581
end
7682

7783
def update_files
78-
@files.each { |file|
79-
@mw_client.update_file(file['filename'], file['path'], file['content_type'], file['comment'], true)
80-
}
84+
@files.each do |file|
85+
file_content = @mw_client.get_file_content(file['filename'])
86+
generated_content = File.read(file['path'])
87+
if file_content == generated_content
88+
puts "No modification on #{file['filename']}, skipping update"
89+
else
90+
@mw_client.update_file(file['filename'], file['path'], file['content_type'], file['comment'], true)
91+
end
92+
end
8193
end
8294

8395
def diff_files

0 commit comments

Comments
 (0)