bx-gitea-integration/app/main.py

39 lines
951 B
Python

import requests
import json
from fastapi import FastAPI, Request
from app.constants import *
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.post("/integration")
async def intgr(request: Request):
body = await request.json()
ref = body["ref"]
branch = ref.split("/")[-1]
[tag, number, *args] = branch.split("-")
logger.info(f"input tag {tag} number {number} args {args}")
logger.info(body)
bx_comment = (
f"Сообщение от GITEA для задачи {number} (ветка {body['ref']} в репозитории {body['repository']['full_name']})"
"\n\n"
f"{body['head_commit']['message']}"
)
bx_res = requests.get(
f"{WEBHOOK}/task.commentitem.add.json?"
f"taskId={number}"
f"&fields[POST_MESSAGE]={bx_comment}"
)
logger.info(f"result {json.loads(bx_res.text)}")
return {"status": "success"}