Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions codecov_auth/commands/owner/interactors/set_yaml_on_owner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
)
Expand All @@ -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
Loading