@@ -62,6 +62,7 @@ def sync_website_content(
6262 translations_ref : str ,
6363 name : str ,
6464 email : str ,
65+ run_local : bool = False ,
6566) -> None :
6667 """Sync content from source repository to translations repository.
6768
@@ -159,6 +160,7 @@ def sync_website_content(
159160 src = str (source_path )
160161
161162 run (["git" , "checkout" , "-b" , branch_name ], cwd = base_translations_path )
163+ os .makedirs (dest , exist_ok = True )
162164 run (["rsync" , "-avr" , "--delete" , src , dest ])
163165 run (["git" , "status" ], cwd = base_translations_path )
164166 run (["git" , "add" , "." ], cwd = base_translations_path )
@@ -169,10 +171,17 @@ def sync_website_content(
169171 pr_title = "Update content"
170172 github_token = os .environ .get ("GITHUB_TOKEN" , "" )
171173 if rc :
172- run (
173- ["git" , "commit" , "-S" , "-m" , "Update content." ],
174- cwd = base_translations_path ,
175- )
174+ if run_local :
175+ run (
176+ ["git" , "commit" , "-m" , "Update content." ],
177+ cwd = base_translations_path ,
178+ )
179+ else :
180+ run (
181+ ["git" , "commit" , "-S" , "-m" , "Update content." ],
182+ cwd = base_translations_path ,
183+ )
184+
176185 run (["git" , "remote" , "-v" ], cwd = base_translations_path )
177186 run (["git" , "push" , "-u" , "origin" , branch_name ], cwd = base_translations_path )
178187
@@ -195,57 +204,58 @@ def sync_website_content(
195204 )
196205 os .environ ["GITHUB_TOKEN" ] = github_token
197206
198- auth = Auth .Token (token )
199- g = Github (auth = auth )
200- repo = g .get_repo (translations_repo )
201- pulls = repo .get_pulls (state = "open" , sort = "created" , direction = "desc" )
202- pr_branch = None
203- signed_by = f"{ name } <{ email } >"
204-
205- for pr in pulls :
206- pr_branch = pr .head .ref
207- if pr .title == pr_title and pr_branch == branch_name :
208- print ("\n \n Found PR try to merge it!" )
209-
210- # Check if commits are signed
211- checks = []
212- for commit in pr .get_commits ():
213- print (
214- [
215- commit .commit .verification .verified , # type: ignore
216- signed_by ,
217- commit .commit .verification .payload , # type: ignore
218- ]
219- )
220- checks .append (
221- commit .commit .verification .verified # type: ignore
222- and signed_by in commit .commit .verification .payload # type: ignore
223- )
224- # TODO: REMOVE
225- break
226-
227- if all (checks ):
228- print ("\n \n All commits are signed, auto-merging!" )
229- # https://cli.github.com/manual/gh_pr_merge
230- os .environ ["GITHUB_TOKEN" ] = token
231- run (
232- [
233- "gh" ,
234- "pr" ,
235- "merge" ,
236- branch_name ,
237- "--auto" ,
238- "--squash" ,
239- "--delete-branch" ,
240- ],
241- cwd = base_translations_path ,
242- )
243- else :
244- print ("\n \n Not all commits are signed, abort merge!" )
245-
246- break
247-
248- g .close ()
207+ if not run_local :
208+ auth = Auth .Token (token )
209+ g = Github (auth = auth )
210+ repo = g .get_repo (translations_repo )
211+ pulls = repo .get_pulls (state = "open" , sort = "created" , direction = "desc" )
212+ pr_branch = None
213+ signed_by = f"{ name } <{ email } >"
214+
215+ for pr in pulls :
216+ pr_branch = pr .head .ref
217+ if pr .title == pr_title and pr_branch == branch_name :
218+ print ("\n \n Found PR try to merge it!" )
219+
220+ # Check if commits are signed
221+ checks = []
222+ for commit in pr .get_commits ():
223+ print (
224+ [
225+ commit .commit .verification .verified , # type: ignore
226+ signed_by ,
227+ commit .commit .verification .payload , # type: ignore
228+ ]
229+ )
230+ checks .append (
231+ commit .commit .verification .verified # type: ignore
232+ and signed_by in commit .commit .verification .payload # type: ignore
233+ )
234+ # TODO: REMOVE
235+ break
236+
237+ if all (checks ):
238+ print ("\n \n All commits are signed, auto-merging!" )
239+ # https://cli.github.com/manual/gh_pr_merge
240+ os .environ ["GITHUB_TOKEN" ] = token
241+ run (
242+ [
243+ "gh" ,
244+ "pr" ,
245+ "merge" ,
246+ branch_name ,
247+ "--auto" ,
248+ "--squash" ,
249+ "--delete-branch" ,
250+ ],
251+ cwd = base_translations_path ,
252+ )
253+ else :
254+ print ("\n \n Not all commits are signed, abort merge!" )
255+
256+ break
257+
258+ g .close ()
249259 else :
250260 print ("\n \n No changes to commit." )
251261
@@ -266,6 +276,7 @@ def parse_input() -> dict:
266276 # Provided by gpg action based on organization secrets
267277 "name" : os .environ ["GPG_NAME" ],
268278 "email" : os .environ ["GPG_EMAIL" ],
279+ "run_local" : os .environ ["RUN_LOCAL" ].lower () == "true" ,
269280 }
270281 return gh_input
271282
0 commit comments