88from fastapi .middleware .cors import CORSMiddleware
99from loguru import logger
1010from src .config import get_settings
11- from src .constants import GH_REPOSITORIES
11+ from src .constants import GH_REPOSITORIES , USER_DATA
1212
1313app = FastAPI ()
1414app .add_middleware (
2020)
2121
2222
23- @app .get ("/{username}/{information}" )
24- async def data (username : str , information : str ):
25- gh_repositories = await get_paginated_data (username )
23+ @app .get ("/{username}" )
24+ async def user_data (username : str ):
25+ if get_settings ().ENVIRONMENT == "DEV" :
26+ logger .debug ("DEV MODE" )
27+ await asyncio .sleep (random () * 5 )
28+ return USER_DATA
29+ return requests .get (
30+ f"https://api.github.com/users/{ username } " ,
31+ headers = {
32+ "Accept" : "application/vnd.github+json" ,
33+ "X-GitHub-Api-Version" : "2022-11-28" ,
34+ },
35+ ).json ()
36+
37+
38+ @app .get ("/{username}/repos/{amount}" )
39+ async def repository_data (username : str , amount : int ):
40+ return (await get_paginated_repository_data (username ))[:amount ]
41+
42+
43+ @app .get ("/{username}/repos/plot/{information}" )
44+ async def repository_plot_data (username : str , information : str ):
45+ gh_repositories = await get_paginated_repository_data (username )
2646 return calc_repo_info_for_plotly (gh_repositories , information )
2747
2848
@@ -47,7 +67,7 @@ def calc_repo_info_for_plotly(gh_repositories, information: str):
4767 ]
4868
4969
50- async def get_paginated_data (username : str ):
70+ async def get_paginated_repository_data (username : str ):
5171 def parse_data (data ):
5272 if data is None :
5373 return []
@@ -58,7 +78,7 @@ def parse_data(data):
5878 await asyncio .sleep (random () * 5 )
5979 return GH_REPOSITORIES
6080
61- url = f"https://api.github.com/users/{ username } /repos"
81+ url = f"https://api.github.com/users/{ username } /repos?sort=updated "
6282 next_pattern = re .compile (r'<([^>]+)>; rel="next"' )
6383 pages_remaining = True
6484 data = []
0 commit comments