Skip to content

Commit 4e6144d

Browse files
committed
fog-updater: Print diff of changes in debug or dry-run mode
1 parent b647b37 commit 4e6144d

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

fog-updater/src/fog_update.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from github import Github, GithubException, InputGitAuthor, enable_console_debug_logging
88
import datetime
9+
import difflib
910
import io
1011
import os
1112
import requests
@@ -116,7 +117,7 @@ def get_latest_metrics_index():
116117
return r.text
117118

118119

119-
def _rewrite_repositories_yaml(repo, branch, data):
120+
def _rewrite_repositories_yaml(repo, branch, data, debug=False):
120121
contents = repo.get_contents("repositories.yaml", ref=branch)
121122
content = contents.decoded_content.decode("utf-8")
122123

@@ -132,6 +133,15 @@ def _rewrite_repositories_yaml(repo, branch, data):
132133
"Update to repositories.yaml resulted in no changes: maybe the file was already up to date?" # noqa
133134
)
134135

136+
if debug:
137+
diff = difflib.unified_diff(
138+
content.splitlines(keepends=True),
139+
new_content.splitlines(keepends=True),
140+
fromfile="old/repositories.yaml",
141+
tofile="new/repositories.yaml",
142+
)
143+
sys.stdout.writelines(diff)
144+
135145
return new_content
136146

137147

@@ -193,7 +203,9 @@ def main(argv, repo, author, debug=False, dry_run=False):
193203

194204
print(f"{ts()} Updating repositories.yaml")
195205
try:
196-
new_content = _rewrite_repositories_yaml(repo, release_branch_name, data)
206+
new_content = _rewrite_repositories_yaml(
207+
repo, release_branch_name, data, debug=dry_run or debug
208+
)
197209
except UnmodifiedException as e:
198210
print(f"{ts()} {e}")
199211
return

0 commit comments

Comments
 (0)