Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit e31ddc2

Browse files
Set bot on owner even if bot name hasn't changed (#1193)
1 parent 0e67c05 commit e31ddc2

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

codecov_auth/commands/owner/interactors/set_yaml_on_owner.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ def yaml_side_effects(self, old_yaml: dict | None, new_yaml: dict | None) -> Non
6868
old_yaml_bot = old_yaml and old_yaml.get("codecov", {}).get("bot")
6969
new_yaml_bot = new_yaml and new_yaml.get("codecov", {}).get("bot")
7070

71-
# Update owner's bot column if bot is updated in yaml
72-
if new_yaml_bot != old_yaml_bot:
73-
new_bot = (
71+
# Update owner's bot column if bot is updated in yaml or if bot is not configured.
72+
if new_yaml_bot != old_yaml_bot or self.owner.bot is None:
73+
new_bot_id = (
7474
get_ownerid_if_member(
7575
service=self.owner.service,
7676
owner_username=new_yaml_bot,
@@ -79,7 +79,7 @@ def yaml_side_effects(self, old_yaml: dict | None, new_yaml: dict | None) -> Non
7979
or old_yaml_bot
8080
or None
8181
)
82-
self.owner.bot = new_bot
82+
self.owner.bot_id = new_bot_id
8383
self.owner.save()
8484

8585
@sync_to_async

codecov_auth/commands/owner/interactors/tests/test_set_yaml_on_owner.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ def setUp(self):
6666
organizations=[self.org.ownerid], service=self.org.service
6767
)
6868
self.random_owner = OwnerFactory(service=self.org.service)
69+
self.codecov_bot = OwnerFactory(
70+
username="codecov",
71+
organizations=[self.org.ownerid],
72+
private_access=True,
73+
)
74+
self.codecov2_bot = OwnerFactory(
75+
username="codecov-2",
76+
organizations=[self.org.ownerid],
77+
private_access=True,
78+
)
6979

7080
# helper to execute the interactor
7181
def execute(self, owner, *args):
@@ -159,6 +169,7 @@ async def test_yaml_has_comments(self):
159169

160170
async def test_user_changes_yaml_bot_and_branch(self):
161171
await sync_to_async(RepositoryFactory)(author=self.org, branch="fake-branch")
172+
assert self.current_owner.bot_id is None
162173
owner_updated = await self.execute(
163174
self.current_owner, self.org.username, yaml_with_changed_branch_and_bot
164175
)
@@ -168,3 +179,4 @@ async def test_user_changes_yaml_bot_and_branch(self):
168179
"codecov": {"branch": "test-2", "bot": "codecov-2"},
169180
"to_string": "\ncodecov:\n branch: 'test-2'\n bot: 'codecov-2'\n",
170181
}
182+
assert owner_updated.bot_id == self.codecov2_bot.ownerid

0 commit comments

Comments
 (0)