mirror of
https://github.com/odoo/runbot.git
synced 2025-03-27 13:25:47 +07:00

If a branch `foo` is disabled, then `tmp.foo` and `staging.foo` become unnecessary (with #247 fixed the tmp refs are not used for creating stagings anymore, but for now they're still used for the "safety dance" of merging a successful staging into the corresponding mainline). Fixes #605
33 lines
1.2 KiB
Python
33 lines
1.2 KiB
Python
import logging
|
|
|
|
from odoo import models
|
|
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
class BranchCleanup(models.TransientModel):
|
|
_name = 'runbot_merge.branch_cleanup'
|
|
_description = "cleans up scratch refs for deactivated branches"
|
|
|
|
def _run(self):
|
|
deactivated = self.env['runbot_merge.branch'].search([
|
|
('active', '=', False),
|
|
('write_date', '>=', self.env.context['lastcall']),
|
|
])
|
|
_logger.info(
|
|
"deleting scratch (tmp and staging) refs for branches %s",
|
|
', '.join(b.name for b in deactivated)
|
|
)
|
|
# loop around the repos first, so we can reuse the gh instance
|
|
for r in deactivated.mapped('project_id.repo_ids'):
|
|
gh = r.github()
|
|
for b in deactivated:
|
|
if b.project_id != r.project_id:
|
|
continue
|
|
|
|
res = gh('delete', f'git/refs/heads/tmp.{b.name}', check=False)
|
|
if res.status_code != 204:
|
|
_logger.info("no tmp branch found for %s:%s", r.name, b.name)
|
|
res = gh('delete', f'git/refs/heads/staging.{b.name}', check=False)
|
|
if res.status_code != 204:
|
|
_logger.info("no staging branch found for %s:%s", res.name, b.name)
|