diff --git a/src/runboat/api.py b/src/runboat/api.py index 2e98768..f6d2b19 100644 --- a/src/runboat/api.py +++ b/src/runboat/api.py @@ -115,7 +115,7 @@ async def undeploy_builds( async def trigger_branch(repo: str, branch: str) -> None: """Trigger build for a branch.""" commit_info = await github.get_branch_info(repo, branch) - await controller.deploy_or_start(commit_info) + await controller.deploy_commit(commit_info) @router.post( @@ -125,7 +125,7 @@ async def trigger_branch(repo: str, branch: str) -> None: async def trigger_pull(repo: str, pr: int) -> None: """Trigger build for a pull request.""" commit_info = await github.get_pull_info(repo, pr) - await controller.deploy_or_start(commit_info) + await controller.deploy_commit(commit_info) async def _build_by_name(name: str) -> models.Build: diff --git a/src/runboat/controller.py b/src/runboat/controller.py index 50f7ec0..18893ff 100644 --- a/src/runboat/controller.py +++ b/src/runboat/controller.py @@ -84,17 +84,16 @@ class Controller: def undeploying(self) -> int: return self.db.count_by_status(BuildStatus.undeploying) - async def deploy_or_start(self, commit_info: CommitInfo) -> None: + async def deploy_commit(self, commit_info: CommitInfo) -> None: + """Deploy build for a commit, or do nothing if biuld already exist.""" build = self.db.get_for_commit( repo=commit_info.repo, target_branch=commit_info.target_branch, pr=commit_info.pr, git_commit=commit_info.git_commit, ) - if build is not None: - await build.start() - return - await Build.deploy(commit_info) + if build is None: + await Build.deploy(commit_info) async def get_build(self, build_name: str, db_only: bool = True) -> Build | None: build = self.db.get(build_name) diff --git a/src/runboat/webhooks.py b/src/runboat/webhooks.py index ce74a67..c2b6b49 100644 --- a/src/runboat/webhooks.py +++ b/src/runboat/webhooks.py @@ -32,7 +32,7 @@ async def receive_payload( ) return background_tasks.add_task( - controller.deploy_or_start, + controller.deploy_commit, CommitInfo( repo=repo, target_branch=target_branch, @@ -52,7 +52,7 @@ async def receive_payload( ) return background_tasks.add_task( - controller.deploy_or_start, + controller.deploy_commit, CommitInfo( repo=repo, target_branch=target_branch, diff --git a/tests/test_webhook.py b/tests/test_webhook.py index f5ce19c..143b5cf 100644 --- a/tests/test_webhook.py +++ b/tests/test_webhook.py @@ -24,7 +24,7 @@ def test_webhook_github_push(mocker: MockerFixture) -> None: ) response.raise_for_status() mock.assert_called_with( - controller.deploy_or_start, + controller.deploy_commit, CommitInfo( repo="oca/mis-builder", target_branch="15.0", @@ -75,7 +75,7 @@ def test_webhook_github_pr(action: str, mocker: MockerFixture) -> None: ) response.raise_for_status() mock.assert_called_with( - controller.deploy_or_start, + controller.deploy_commit, CommitInfo( repo="oca/mis-builder", target_branch="15.0",