Add `action` as a parameter

main
drunkendog 2023-09-25 20:39:51 +01:00
parent 9ad46bc733
commit 4ae6a24702
1 changed files with 5 additions and 5 deletions

10
api.py
View File

@ -32,15 +32,15 @@ async def root():
@app.get("/set_badge/") @app.get("/set_badge/")
async def set_badge(repo: str, new_badge: str, branch: str=None, api_key: str = Security(get_api_key)): async def set_badge(repo: str, new_badge: str, branch: str=None, action: str=None, api_key: str = Security(get_api_key)):
if api_key.rsplit("-", 1)[0] != repo: if api_key.rsplit("-", 1)[0] != repo:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED, status_code=status.HTTP_401_UNAUTHORIZED,
detail="No permissions for repo", detail="No permissions for repo",
) )
if branch is not None: if branch is not None or action is not None:
badge_dict[repo, branch] = new_badge badge_dict[repo, branch, action] = new_badge
else: else:
badge_dict[repo] = new_badge badge_dict[repo] = new_badge
with open("badges.yaml", "w") as f: with open("badges.yaml", "w") as f:
@ -48,10 +48,10 @@ async def set_badge(repo: str, new_badge: str, branch: str=None, api_key: str =
@app.get("/get_badge/") @app.get("/get_badge/")
async def get_badge(repo: str, branch: str=None): async def get_badge(repo: str, branch: str=None, action: str=None):
if repo not in badge_dict.keys(): if repo not in badge_dict.keys():
raise HTTPException( raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND, status_code=status.HTTP_404_NOT_FOUND,
detail="Repo not found", detail="Repo not found",
) )
return RedirectResponse("https://img.shields.io/badge/" + badge_dict[repo, branch] if branch is not None else badge_dict[repo]) return RedirectResponse("https://img.shields.io/badge/" + badge_dict[repo, branch, action] if branch is not None or action is not None else badge_dict[repo])