11from __future__ import annotations
22
33import datetime
4+ from enum import Enum
45from typing import Any
5- from typing import Literal
66
77from asgiref .sync import async_to_sync
88from 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+
116121class 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