Skip to content

Commit 02b6800

Browse files
fix types by switching account type to enum
1 parent 3649cdc commit 02b6800

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/django_github_app/management/commands/github.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from django_typer.management import Typer
77
from typer import Option
88

9+
from django_github_app.models import AccountType
910
from django_github_app.models import Installation
1011
from django_github_app.models import Repository
1112

@@ -19,7 +20,7 @@ def github(): ...
1920
@cli.command()
2021
def import_app(
2122
type: Annotated[
22-
str,
23+
AccountType,
2324
Option(help="The type of account the GitHub App is installed on"),
2425
],
2526
name: Annotated[

src/django_github_app/models.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from __future__ import annotations
22

33
import datetime
4+
from enum import Enum
45
from typing import Any
5-
from typing import Literal
66

77
from asgiref.sync import async_to_sync
88
from django.db import models
@@ -113,6 +113,11 @@ def from_event(cls, event: sansio.Event) -> InstallationStatus:
113113
raise ValueError(f"Unknown installation action: {action}")
114114

115115

116+
class AccountType(str, Enum):
117+
ORG = "org"
118+
USER = "user"
119+
120+
116121
class Installation(models.Model):
117122
id: int
118123
installation_id = models.PositiveBigIntegerField(unique=True)
@@ -145,14 +150,12 @@ async def aget_access_token(self, gh: abc.GitHubAPI): # pragma: no cover
145150
def get_access_token(self, gh: abc.GitHubAPI): # pragma: no cover
146151
return async_to_sync(self.aget_access_token)(gh)
147152

148-
async def arefresh_from_gh(
149-
self, account_type: Literal["org", "user"], account_name: str
150-
):
153+
async def arefresh_from_gh(self, account_type: AccountType, account_name: str):
151154
match account_type:
152-
case "org":
155+
case AccountType.ORG:
153156
endpoint = GitHubAPIEndpoint.ORG_APP_INSTALLATION
154157
url_var = "org"
155-
case "user":
158+
case AccountType.USER:
156159
endpoint = GitHubAPIEndpoint.USER_APP_INSTALLATION
157160
url_var = "username"
158161
case _:
@@ -168,7 +171,7 @@ async def arefresh_from_gh(
168171
self.data = data
169172
await self.asave()
170173

171-
def refresh_from_gh(self, account_type: Literal["org", "user"], account_name: str):
174+
def refresh_from_gh(self, account_type: AccountType, account_name: str):
172175
return async_to_sync(self.arefresh_from_gh)(account_type, account_name)
173176

174177
async def aget_repos(self, params: dict[str, Any] | None = None):

0 commit comments

Comments
 (0)