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

Conversation

@Swatinem
Copy link
Contributor

This changes the EraseRepositoryInteractor to allow erasing repositories belonging to other owners the current_owner has admin access to.

While doing so, this also extracts some duplicated code related to resolving Owners and Repositorys by name, and validating admin access.

The main part to allow this functionality (changing the GraphQL query) is left to a followup PR.

This changes the `EraseRepositoryInteractor` to allow erasing repositories belonging to other owners the `current_owner` has admin access to.

While doing so, this also extracts some duplicated code related to resolving `Owner`s and `Repository`s by name, and validating admin access.

The main part to allow this functionality (changing the GraphQL query) is left to a followup PR.
@Swatinem Swatinem requested review from a team and rohitvinnakota-codecov January 29, 2025 10:38
@Swatinem Swatinem self-assigned this Jan 29, 2025
@codecov-notifications
Copy link

codecov-notifications bot commented Jan 29, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@codecov-qa
Copy link

codecov-qa bot commented Jan 29, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.99%. Comparing base (e06c5d8) to head (4eb5539).
Report is 2 commits behind head on main.

✅ All tests successful. No failed tests found.

@codecov-public-qa
Copy link

❌ 8 Tests Failed:

Tests completed Failed Passed Skipped
2711 8 2703 6
View the top 3 failed tests by shortest run time
core/commands/component/tests/test_component.py::ComponentCommandsTest::test_delete_component_measurements_repo_not_found
Stack Traces | 0.314s run time
self = <core.commands.component.tests.test_component.ComponentCommandsTest testMethod=test_delete_component_measurements_repo_not_found>

    def test_delete_component_measurements_repo_not_found(self):
        with self.assertRaises(ValidationError):
>           self.command.delete_component_measurements(
                owner_username=self.org.username,
                repo_name="nonexistent",
                component_id="component1",
            )

.../component/tests/test_component.py:53: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
.../commands/component/component.py:10: in delete_component_measurements
    return self.get_interactor(DeleteComponentMeasurementsInteractor).execute(
.../component/interactors/delete_component_measurements.py:7: in execute
    _owner, repo = self.resolve_owner_and_repo(
codecov/commands/base.py:99: in resolve_owner_and_repo
    self.ensure_is_admin(owner)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

    def ensure_is_admin(self, owner: Owner) -> None:
        """
        Ensures that the `current_owner` is an admin of `owner`,
        or raise `Unauthorized` otherwise.
        """
    
        if not current_user_part_of_org(self.current_owner, owner):
>           raise Unauthorized()
E           codecov.commands.exceptions.Unauthorized

codecov/commands/base.py:64: Unauthorized
core/commands/component/tests/test_component.py::ComponentCommandsTest::test_delete_component_measurements
Stack Traces | 0.323s run time
self = <core.commands.component.tests.test_component.ComponentCommandsTest testMethod=test_delete_component_measurements>
mocked_delete_timeseries = <MagicMock name='delete_component_measurements' id='139897623973712'>

    @patch("services.task.TaskService.delete_component_measurements")
    def test_delete_component_measurements(self, mocked_delete_timeseries):
>       self.command.delete_component_measurements(
            owner_username=self.org.username,
            repo_name=self.repo.name,
            component_id="component1",
        )

.../component/tests/test_component.py:25: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
.../commands/component/component.py:10: in delete_component_measurements
    return self.get_interactor(DeleteComponentMeasurementsInteractor).execute(
.../component/interactors/delete_component_measurements.py:7: in execute
    _owner, repo = self.resolve_owner_and_repo(
codecov/commands/base.py:99: in resolve_owner_and_repo
    self.ensure_is_admin(owner)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <core.commands.component.interactors.delete_component_measurements.DeleteComponentMeasurementsInteractor object at 0x7f3bec7dd850>
owner = <Owner: Owner<github/test-org>>

    def ensure_is_admin(self, owner: Owner) -> None:
        """
        Ensures that the `current_owner` is an admin of `owner`,
        or raise `Unauthorized` otherwise.
        """
    
        if not current_user_part_of_org(self.current_owner, owner):
>           raise Unauthorized()
E           codecov.commands.exceptions.Unauthorized

codecov/commands/base.py:64: Unauthorized
core/commands/component/tests/test_component.py::ComponentCommandsTest::test_delete_component_measurements_signature_created
Stack Traces | 0.326s run time
self = <core.commands.component.tests.test_component.ComponentCommandsTest testMethod=test_delete_component_measurements_signature_created>
mocked_create_signature = <MagicMock name='_create_signature' id='139897628236864'>

    @patch("services.task.TaskService._create_signature")
    def test_delete_component_measurements_signature_created(
        self, mocked_create_signature
    ):
>       self.command.delete_component_measurements(
            owner_username=self.org.username,
            repo_name=self.repo.name,
            component_id="component1",
        )

.../component/tests/test_component.py:106: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
.../commands/component/component.py:10: in delete_component_measurements
    return self.get_interactor(DeleteComponentMeasurementsInteractor).execute(
.../component/interactors/delete_component_measurements.py:7: in execute
    _owner, repo = self.resolve_owner_and_repo(
codecov/commands/base.py:99: in resolve_owner_and_repo
    self.ensure_is_admin(owner)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <core.commands.component.interactors.delete_component_measurements.DeleteComponentMeasurementsInteractor object at 0x7f3c6fdb2c00>
owner = <Owner: Owner<github/test-org>>

    def ensure_is_admin(self, owner: Owner) -> None:
        """
        Ensures that the `current_owner` is an admin of `owner`,
        or raise `Unauthorized` otherwise.
        """
    
        if not current_user_part_of_org(self.current_owner, owner):
>           raise Unauthorized()
E           codecov.commands.exceptions.Unauthorized

codecov/commands/base.py:64: Unauthorized

To view more test analytics, go to the Test Analytics Dashboard
📢 Thoughts on this report? Let us know!

@github-actions
Copy link
Contributor

github-actions bot commented Jan 29, 2025

✅ All tests successful. No failed tests were found.

📣 Thoughts on this report? Let Codecov know! | Powered by Codecov

@rohitvinnakota-codecov
Copy link
Contributor

We will need UI changes as well if we update the resolver. Feel free to ping me before merging those changes.

@Swatinem Swatinem added this pull request to the merge queue Jan 30, 2025
Merged via the queue into main with commit d80087a Jan 30, 2025
15 of 17 checks passed
@Swatinem Swatinem deleted the swatinem/erase-foreign-repo branch January 30, 2025 10:31
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants