66
77from github import Github , GithubException , InputGitAuthor , enable_console_debug_logging
88import datetime
9+ import difflib
910import io
1011import os
1112import 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