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

Add owner to eraseRepository mutation #1156

Merged
merged 1 commit into from
Feb 14, 2025
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
32 changes: 32 additions & 0 deletions graphql_api/tests/mutation/test_erase_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
class EraseRepositoryTests(GraphQLTestHelper, TransactionTestCase):
def setUp(self):
self.org = OwnerFactory(username="codecov", service="github")
self.non_admin_user = OwnerFactory(organizations=[self.org.ownerid])
self.admin_user = OwnerFactory(organizations=[self.org.ownerid])
self.org.add_admin(self.admin_user)

self.repo = RepositoryFactory(author=self.org, name="gazebo", active=True)

def test_when_authenticated(self):
Expand Down Expand Up @@ -92,3 +96,31 @@ def test_when_self_hosted_admin(self, is_admin_owner):
)

assert data == {"eraseRepository": None}

def test_when_other_admin(self):
data = self.gql_request(
query,
owner=self.admin_user,
variables={
"input": {
"owner": "codecov",
"repoName": "gazebo",
}
},
)

assert data == {"eraseRepository": None}

def test_when_not_other_admin(self):
data = self.gql_request(
query,
owner=self.non_admin_user,
variables={
"input": {
"owner": "codecov",
"repoName": "gazebo",
}
},
)

assert data["eraseRepository"]["error"]["__typename"] == "UnauthorizedError"
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ type EraseRepositoryPayload {
}

input EraseRepositoryInput {
owner: String
repoName: String!
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict
from typing import Any

from ariadne import UnionType
from graphql import GraphQLResolveInfo
Expand All @@ -13,13 +13,14 @@
@wrap_error_handling_mutation
@require_authenticated
async def resolve_erase_repository(
_: Any, info: GraphQLResolveInfo, input: Dict[str, Any]
_: Any, info: GraphQLResolveInfo, input: dict[str, Any]
) -> None:
command = info.context["executor"].get_command("repository")
current_owner = info.context["request"].current_owner

owner_username = input.get("owner") or current_owner.username
repo_name = input.get("repo_name")
# TODO: change the graphql mutation to allow working on other owners
owner_username = current_owner.username

await command.erase_repository(owner_username, repo_name)
return None

Expand Down
Loading