Skip to content

Commit cf384c1

Browse files
“Virginiajjscarafia
authored andcommitted
[FIX] runbot_transifex: fix sync from Transifex to Github
1 parent 81e25a3 commit cf384c1

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

runbot_transifex/models/runbot_branch.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

runbot_transifex/views/runbot_branch_views.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<field name="arch" type="xml">
66
<field name="remote_id" position="after">
77
<field name="transifex_project_id"/>
8+
<field name="last_sync_date"/>
89
<field name="next_sync_date"/>
910
</field>
1011
</field>

runbot_transifex/views/transifex_project_views.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717
<field name="repo_id"/>
1818
<field name="remote_id"/>
1919
<field name="name"/>
20+
<field name="last_sync_date"/>
2021
<field name="next_sync_date"/>
2122
<button name="sync_translations_to_github" type="object" icon="fa-refresh"
2223
help="Sincroniza traducciones desde transifex a github sin verificar fecha"
2324
confirm="Sicroniza traducciones desde transifex a github sin verificar fecha.
2425
El timeout del httpworker puede hacer que el proceso no se complete.
25-
Se sugiere borrar Next Sync Date y esperar a que el cron lo ejecute. ¿Desea continuar igualmente?"/>
26+
Se sugiere borrar Last Sync Date y esperar a que el cron lo ejecute. ¿Desea continuar igualmente?"/>
2627
<button name="get_push_data" type="object" help="Get push data" icon="fa-arrow-up" groups="base.group_no_one"/>
2728
</tree>
2829
</field>

0 commit comments

Comments
 (0)