Created
April 29, 2022 07:07
-
-
Save chrimaho/f874e19fe6d32f59982ce3997936d901 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Endpoint: Main Endpoint ---- | |
| @app.post \ | |
| ( path=API_ENDPOINT | |
| , summary="API Endpoint for Git to Call" | |
| , description= \ | |
| "Basically, it will:<br><br>" + | |
| f"1. `clone`/`pull` repo from: `{GIT_URL}`<br><br>" + | |
| f"2. Save repo to: `{REPO_DIR}`" | |
| , tags=["Main Process"] | |
| , response_class=JSONResponse | |
| , responses= \ | |
| { 200: {"model": Success} | |
| , 422: {"model": ValidationError, "description": "Validation Error"} | |
| , 500: {"model": InternalServerError} | |
| } | |
| ) | |
| def api_endpoint \ | |
| ( git_url:str=Query \ | |
| ( default=GIT_URL | |
| , title="Git URL" | |
| , description= \ | |
| "The URL from which the Repo will be cloned.<br>" + | |
| "This is set from the Environment (`.env`) variables." | |
| ) | |
| , repo_dir:str=Query \ | |
| ( default=REPO_DIR | |
| , title="Repo Dir" | |
| , description= \ | |
| "The DIR to which the Repo will be cloned.<br>" + | |
| "This is set from the Environment (`.env`) variables." | |
| ) | |
| ): | |
| try: | |
| remove_dir(repo_dir) | |
| Repo.clone_from(git_url, repo_dir) | |
| except: | |
| e = exc_info() | |
| return JSONResponse \ | |
| ( { "Failed": f"{git_url}" | |
| , "Error": f"{e[0].__name__}" | |
| , "Doc": f"{e[0].__doc__}" | |
| , "Message": f"{e[1]}" | |
| } | |
| , status_code=500 | |
| ) | |
| else: | |
| return JSONResponse \ | |
| ( {"Success": git_url} | |
| , status_code=200 | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment