flake8 compliant
This commit is contained in:
+5
-2
@@ -3,7 +3,6 @@ from fastapi import FastAPI, Request, HTTPException
|
|||||||
from fastapi.responses import HTMLResponse
|
from fastapi.responses import HTMLResponse
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
import logging
|
import logging
|
||||||
from typing import List
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from utils import clone_repository, load_runner_script
|
from utils import clone_repository, load_runner_script
|
||||||
@@ -12,6 +11,7 @@ from gitea_request import GiteaRequest
|
|||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
|
|
||||||
@app.get('/', response_class=HTMLResponse)
|
@app.get('/', response_class=HTMLResponse)
|
||||||
async def root():
|
async def root():
|
||||||
content_str = """
|
content_str = """
|
||||||
@@ -27,6 +27,7 @@ async def root():
|
|||||||
"""
|
"""
|
||||||
return HTMLResponse(content=content_str, status_code=200)
|
return HTMLResponse(content=content_str, status_code=200)
|
||||||
|
|
||||||
|
|
||||||
@app.post('/test')
|
@app.post('/test')
|
||||||
async def test(request: Request):
|
async def test(request: Request):
|
||||||
""" Test connection to server. """
|
""" Test connection to server. """
|
||||||
@@ -36,6 +37,7 @@ async def test(request: Request):
|
|||||||
detail='test completed'
|
detail='test completed'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@app.post('/event')
|
@app.post('/event')
|
||||||
def handle_event(request: GiteaRequest):
|
def handle_event(request: GiteaRequest):
|
||||||
""" Handle event from webhook. """
|
""" Handle event from webhook. """
|
||||||
@@ -94,6 +96,7 @@ def handle_event(request: GiteaRequest):
|
|||||||
)
|
)
|
||||||
# consider to include link to page that show progress
|
# consider to include link to page that show progress
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
load_dotenv('dev.env')
|
load_dotenv('dev.env')
|
||||||
setup_logging()
|
setup_logging()
|
||||||
@@ -104,4 +107,4 @@ if __name__ == '__main__':
|
|||||||
app=app,
|
app=app,
|
||||||
host=listen_ip,
|
host=listen_ip,
|
||||||
port=listen_port
|
port=listen_port
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
|
|
||||||
class GiteaRequest(BaseModel):
|
class GiteaRequest(BaseModel):
|
||||||
ref: str
|
ref: str
|
||||||
before: str
|
before: str
|
||||||
@@ -11,4 +12,4 @@ class GiteaRequest(BaseModel):
|
|||||||
head_commit: dict
|
head_commit: dict
|
||||||
repository: dict
|
repository: dict
|
||||||
pusher: dict
|
pusher: dict
|
||||||
sender: dict
|
sender: dict
|
||||||
|
|||||||
+1
-1
@@ -26,4 +26,4 @@ if __name__ == '__main__':
|
|||||||
app=app,
|
app=app,
|
||||||
host=listen_ip,
|
host=listen_ip,
|
||||||
port=listen_port
|
port=listen_port
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -21,4 +21,4 @@ class RunnerScript(BaseModel):
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
path = Path(__file__).parent.parent / 'runner_script.yml'
|
path = Path(__file__).parent.parent / 'runner_script.yml'
|
||||||
rs = RunnerScript.from_file(path)
|
rs = RunnerScript.from_file(path)
|
||||||
print(rs)
|
print(rs)
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
import logging
|
import logging
|
||||||
import os
|
|
||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Literal
|
from typing import Literal
|
||||||
@@ -15,12 +14,19 @@ LOGGER_LEVEL = config.get('main', 'logger_level')
|
|||||||
def setup_logging(
|
def setup_logging(
|
||||||
logger_level: Literal['debug', 'info', 'warning', 'error'] = LOGGER_LEVEL
|
logger_level: Literal['debug', 'info', 'warning', 'error'] = LOGGER_LEVEL
|
||||||
):
|
):
|
||||||
fmt = '%(asctime)s | %(levelname)s | %(filename)s | %(funcName)s | %(message)s'
|
fmt = (
|
||||||
|
'%(asctime)s | '
|
||||||
|
'%(levelname)s | '
|
||||||
|
'%(filename)s | '
|
||||||
|
'%(funcName)s | '
|
||||||
|
'%(message)s'
|
||||||
|
)
|
||||||
datefmt = '%Y-%m-%d %H:%M:%S'
|
datefmt = '%Y-%m-%d %H:%M:%S'
|
||||||
level = getattr(logging, logger_level.upper())
|
level = getattr(logging, logger_level.upper())
|
||||||
logging.basicConfig(format=fmt, datefmt=datefmt, level=level)
|
logging.basicConfig(format=fmt, datefmt=datefmt, level=level)
|
||||||
logging.debug('finished')
|
logging.debug('finished')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
load_dotenv('dev.env')
|
load_dotenv('dev.env')
|
||||||
setup_logging()
|
setup_logging()
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,4 @@
|
|||||||
from pydantic import AnyHttpUrl
|
from pydantic import AnyHttpUrl
|
||||||
from typing import List
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from git import Repo
|
from git import Repo
|
||||||
import logging
|
import logging
|
||||||
@@ -8,6 +7,7 @@ import os
|
|||||||
import yaml
|
import yaml
|
||||||
from runner_script import RunnerScript
|
from runner_script import RunnerScript
|
||||||
|
|
||||||
|
|
||||||
def clone_repository(repo_url: AnyHttpUrl) -> Path:
|
def clone_repository(repo_url: AnyHttpUrl) -> Path:
|
||||||
# extract repo name
|
# extract repo name
|
||||||
repo_name = repo_url.split('/')[-1].replace('.git', '')
|
repo_name = repo_url.split('/')[-1].replace('.git', '')
|
||||||
@@ -23,6 +23,7 @@ def clone_repository(repo_url: AnyHttpUrl) -> Path:
|
|||||||
logging.debug('finished')
|
logging.debug('finished')
|
||||||
return dst_dir
|
return dst_dir
|
||||||
|
|
||||||
|
|
||||||
def load_runner_script(path: Path) -> RunnerScript:
|
def load_runner_script(path: Path) -> RunnerScript:
|
||||||
assert path.exists()
|
assert path.exists()
|
||||||
with open(path, 'r') as fh:
|
with open(path, 'r') as fh:
|
||||||
@@ -30,4 +31,3 @@ def load_runner_script(path: Path) -> RunnerScript:
|
|||||||
runner_script = RunnerScript.parse_obj(script)
|
runner_script = RunnerScript.parse_obj(script)
|
||||||
logging.debug('finished')
|
logging.debug('finished')
|
||||||
return runner_script
|
return runner_script
|
||||||
|
|
||||||
Reference in New Issue
Block a user