Skip to content

Commit 0e45cf4

Browse files
add methods to Repo too
1 parent ff38dd3 commit 0e45cf4

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/django_github_app/models.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,33 @@ def get_access_token(self, gh: abc.GitHubAPI): # pragma: no cover
139139

140140

141141
class RepositoryManager(models.Manager["Repository"]):
142+
async def acreate_from_gh_data(
143+
self, data: dict[str, str] | list[dict[str, str]], installation: Installation
144+
):
145+
if isinstance(data, list):
146+
repositories = [
147+
Repository(
148+
installation=installation,
149+
repository_id=repository["id"],
150+
repository_node_id=repository["node_id"],
151+
full_name=repository["full_name"],
152+
)
153+
for repository in data
154+
]
155+
return await Repository.objects.abulk_create(repositories)
156+
else:
157+
return await self.acreate(
158+
installation=installation,
159+
repository_id=data["id"],
160+
repository_node_id=data["node_id"],
161+
full_name=data["full_name"],
162+
)
163+
164+
def create_from_gh_data(
165+
self, data: dict[str, str] | list[dict[str, str]], installation: Installation
166+
):
167+
return async_to_sync(self.acreate_from_gh_data)(data, installation)
168+
142169
async def aget_from_event(self, event: sansio.Event):
143170
try:
144171
repository_id = event.data["repository"]["id"]

0 commit comments

Comments
 (0)