forked from odoo/runbot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] runbot_merge: create controller to merge a commit
This used to be done in RPC but the goal is to be able to call this from another server and not rely on a user account.
- Loading branch information
Showing
2 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from odoo.http import Controller, request, route | ||
|
||
try: | ||
from odoo.addons.saas_worker.util import from_role | ||
except ImportError: | ||
def from_role(*_, **__): | ||
return lambda _: None | ||
|
||
class MergebotController(Controller): | ||
|
||
@from_role('tx', signed=True) | ||
@route('/i18n/merge_commit', type='json', auth='public') | ||
def merge_commit(self, commit_hash, repository, branch, project="RD"): | ||
repository_id = request.env["runbot_merge.repository"].sudo().search([ | ||
("name", "=", repository) | ||
]) | ||
if not repository_id: | ||
return {"error": "Repository %r not found" % repository} | ||
|
||
target = request.env["runbot_merge.branch"].sudo().search([ | ||
("name", "=", branch), | ||
("project_id", "=", project) | ||
]) | ||
if not target: | ||
return {"error": "Target branch %s:%s not found" % (branch, target)} | ||
|
||
patch = request.env["runbot_merge.patch"].sudo().create({ | ||
"repository": repository_id.id, | ||
"target": target.id, | ||
"commit": commit_hash | ||
}) | ||
return {"patch": patch.id} |