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

Commit 04c5c56

Browse files
committed
Add owner to eraseRepository mutation
Adding this as an optional input field, meaning it is backwards compatible, and falls back to the existing logic of using the currently logged in user as the target owner. When specified, it will erase the repository belonging to the given `owner`.
1 parent 7c058c9 commit 04c5c56

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

graphql_api/tests/mutation/test_erase_repository.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
class EraseRepositoryTests(GraphQLTestHelper, TransactionTestCase):
2323
def setUp(self):
2424
self.org = OwnerFactory(username="codecov", service="github")
25+
self.non_admin_user = OwnerFactory(organizations=[self.org.ownerid])
26+
self.admin_user = OwnerFactory(organizations=[self.org.ownerid])
27+
self.org.add_admin(self.admin_user)
28+
2529
self.repo = RepositoryFactory(author=self.org, name="gazebo", active=True)
2630

2731
def test_when_authenticated(self):
@@ -92,3 +96,31 @@ def test_when_self_hosted_admin(self, is_admin_owner):
9296
)
9397

9498
assert data == {"eraseRepository": None}
99+
100+
def test_when_other_admin(self):
101+
data = self.gql_request(
102+
query,
103+
owner=self.admin_user,
104+
variables={
105+
"input": {
106+
"owner": "codecov",
107+
"repoName": "gazebo",
108+
}
109+
},
110+
)
111+
112+
assert data == {"eraseRepository": None}
113+
114+
def test_when_not_other_admin(self):
115+
data = self.gql_request(
116+
query,
117+
owner=self.non_admin_user,
118+
variables={
119+
"input": {
120+
"owner": "codecov",
121+
"repoName": "gazebo",
122+
}
123+
},
124+
)
125+
126+
assert data["eraseRepository"]["error"]["__typename"] == "UnauthorizedError"

graphql_api/types/mutation/erase_repository/erase_repository.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ type EraseRepositoryPayload {
55
}
66

77
input EraseRepositoryInput {
8+
owner: String
89
repoName: String!
910
}

graphql_api/types/mutation/erase_repository/erase_repository.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict
1+
from typing import Any
22

33
from ariadne import UnionType
44
from graphql import GraphQLResolveInfo
@@ -13,13 +13,14 @@
1313
@wrap_error_handling_mutation
1414
@require_authenticated
1515
async def resolve_erase_repository(
16-
_: Any, info: GraphQLResolveInfo, input: Dict[str, Any]
16+
_: Any, info: GraphQLResolveInfo, input: dict[str, Any]
1717
) -> None:
1818
command = info.context["executor"].get_command("repository")
1919
current_owner = info.context["request"].current_owner
20+
21+
owner_username = input.get("owner") or current_owner.username
2022
repo_name = input.get("repo_name")
21-
# TODO: change the graphql mutation to allow working on other owners
22-
owner_username = current_owner.username
23+
2324
await command.erase_repository(owner_username, repo_name)
2425
return None
2526

0 commit comments

Comments
 (0)