diff --git a/codecov_auth/commands/owner/interactors/set_yaml_on_owner.py b/codecov_auth/commands/owner/interactors/set_yaml_on_owner.py index 566d003936..12a131e21f 100644 --- a/codecov_auth/commands/owner/interactors/set_yaml_on_owner.py +++ b/codecov_auth/commands/owner/interactors/set_yaml_on_owner.py @@ -68,9 +68,9 @@ def yaml_side_effects(self, old_yaml: dict | None, new_yaml: dict | None) -> Non old_yaml_bot = old_yaml and old_yaml.get("codecov", {}).get("bot") new_yaml_bot = new_yaml and new_yaml.get("codecov", {}).get("bot") - # Update owner's bot column if bot is updated in yaml - if new_yaml_bot != old_yaml_bot: - new_bot = ( + # Update owner's bot column if bot is updated in yaml or if bot is not configured. + if new_yaml_bot != old_yaml_bot or self.owner.bot is None: + new_bot_id = ( get_ownerid_if_member( service=self.owner.service, owner_username=new_yaml_bot, @@ -79,7 +79,7 @@ def yaml_side_effects(self, old_yaml: dict | None, new_yaml: dict | None) -> Non or old_yaml_bot or None ) - self.owner.bot = new_bot + self.owner.bot_id = new_bot_id self.owner.save() @sync_to_async diff --git a/codecov_auth/commands/owner/interactors/tests/test_set_yaml_on_owner.py b/codecov_auth/commands/owner/interactors/tests/test_set_yaml_on_owner.py index e0e35a6083..5c03f955f4 100644 --- a/codecov_auth/commands/owner/interactors/tests/test_set_yaml_on_owner.py +++ b/codecov_auth/commands/owner/interactors/tests/test_set_yaml_on_owner.py @@ -66,6 +66,16 @@ def setUp(self): organizations=[self.org.ownerid], service=self.org.service ) self.random_owner = OwnerFactory(service=self.org.service) + self.codecov_bot = OwnerFactory( + username="codecov", + organizations=[self.org.ownerid], + private_access=True, + ) + self.codecov2_bot = OwnerFactory( + username="codecov-2", + organizations=[self.org.ownerid], + private_access=True, + ) # helper to execute the interactor def execute(self, owner, *args): @@ -159,6 +169,7 @@ async def test_yaml_has_comments(self): async def test_user_changes_yaml_bot_and_branch(self): await sync_to_async(RepositoryFactory)(author=self.org, branch="fake-branch") + assert self.current_owner.bot_id is None owner_updated = await self.execute( self.current_owner, self.org.username, yaml_with_changed_branch_and_bot ) @@ -168,3 +179,4 @@ async def test_user_changes_yaml_bot_and_branch(self): "codecov": {"branch": "test-2", "bot": "codecov-2"}, "to_string": "\ncodecov:\n branch: 'test-2'\n bot: 'codecov-2'\n", } + assert owner_updated.bot_id == self.codecov2_bot.ownerid