mirror of
https://github.com/odoo/runbot.git
synced 2025-03-16 16:05:42 +07:00

Probably should create a mixin for this: when a model is used as a task queue for a cron, the cron should automatically be triggered on creation. Requiring an explicit trigger after a creation is error prone and increase the risks that some of the triggers will be forgotten/missed.
27 lines
845 B
Python
27 lines
845 B
Python
import logging
|
|
|
|
from odoo import models, fields, api
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
class BranchCleanup(models.Model):
|
|
_name = 'runbot_merge.issues_closer'
|
|
_description = "closes issues linked to PRs"
|
|
|
|
repository_id = fields.Many2one('runbot_merge.repository', required=True)
|
|
number = fields.Integer(required=True)
|
|
|
|
@api.model_create_multi
|
|
def create(self, vals_list):
|
|
self.env.ref('runbot_merge.issues_closer_cron')._trigger()
|
|
return super().create(vals_list)
|
|
|
|
def _run(self):
|
|
ghs = {}
|
|
while t := self.search([], limit=1):
|
|
gh = ghs.get(t.repository_id.id)
|
|
if not gh:
|
|
gh = ghs[t.repository_id.id] = t.repository_id.github()
|
|
|
|
r = gh('PATCH', f'issues/{t.number}', json={'state': 'closed'}, check=False)
|
|
t.unlink()
|