@@ -16,6 +16,7 @@ class RunbotBranch(models.Model):
1616 _inherit = "runbot.branch"
1717
1818 transifex_project_id = fields .Many2one ('transifex.project' )
19+ last_sync_date = fields .Datetime ()
1920 next_sync_date = fields .Datetime ()
2021 repo_id = fields .Many2one (related = 'remote_id.repo_id' )
2122
@@ -25,18 +26,13 @@ def _cron_sync_translations_to_github(self):
2526 branch = self .search ([('transifex_project_id.active' , '=' , True ), '|' , ('next_sync_date' , '<' , now ), ('next_sync_date' , '=' , False )], limit = 1 )
2627 if branch :
2728 try :
28- last_sync_date = branch .next_sync_date
29- # we first change date so that in case theres is a new translantion between we're syncking,
30- # that change syncked on next run
29+ branch .sync_translations_to_github (last_sync_date = branch .last_sync_date )
3130 branch .next_sync_date = fields .Datetime .add (now , days = branch .transifex_project_id .periodicity )
32- branch .sync_translations_to_github (last_sync_date = last_sync_date )
3331 except Exception as e :
3432 _logger .warning ('Error al sincronizar transifex a github: %s' , e )
3533 branch .transifex_project_id .message_post (
3634 body = 'Error al sincronizar branch %s, en transifex project %s a github. Esto es lo que obtuvimos: %s' % (
3735 branch .display_name , branch .transifex_project_id .slug , e ))
38- # restore sync date if we've a failure
39- branch .next_sync_date = last_sync_date
4036
4137 def get_push_data (self ):
4238 self .ensure_one ()
@@ -80,6 +76,8 @@ def sync_translations_to_github(self, last_sync_date=False):
8076 y ejemplos acá: https://pygithub.readthedocs.io/en/latest/examples.html
8177 """
8278 for rec in self .filtered ('transifex_project_id' ):
79+ # We save the date to ensure any new translations made during syncing are captured in the next run.
80+ start_sync_date = fields .Datetime .now ()
8381 gh = github .Github (rec .transifex_project_id .github_token )
8482 transifex_api .setup (auth = rec .transifex_project_id .api_token )
8583
@@ -144,3 +142,4 @@ def sync_translations_to_github(self, last_sync_date=False):
144142 _logger .info ("Pushing to GitHub" )
145143 master_refs = gh_repo .get_git_ref ('heads/%s' % rec .name )
146144 master_refs .edit (sha = commit .sha )
145+ rec .last_sync_date = start_sync_date
0 commit comments