mybot/bot/bot_excute.py

47 lines
1.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- coding: utf-8 -*-
# @Time : 2023/4/8 0:07
# @Author : Flora.Chen
# @File : bot_excute.py
# @Software: PyCharm
# @Desc:
from api.gitlink_api import GitLinkApi
from config.config import GLOBAL_VAR
from bot.generate_jwt import generate_jwt_token
from bot.mybot import MyBot
from loguru import logger
from datetime import datetime
now_time = datetime.now().strftime("%Y-%m-%d@%H-%M-%S")
def create_version(host, bot):
logger.debug("开始进入create_version方法")
logger.debug(f"create_version全局变量-{type(GLOBAL_VAR)}|| {GLOBAL_VAR}")
if GLOBAL_VAR:
global_var_copy = GLOBAL_VAR
# 通过bot的私钥获取jwt_token
jwt_token = generate_jwt_token(bot)
logger.debug(f"jwt_token{jwt_token}")
# 通过jwt_token生成bot的access_token
my_bot = MyBot(host)
for key, value in GLOBAL_VAR.items():
logger.debug(f"value={value}")
bot_installer_id = value.get("bot_installer_id")
access_token = my_bot.get_access_token(bot_installer_id, jwt_token)
logger.debug(
f"bot_id:{bot.get('bot_id')}, project: {key}, access_token{access_token}")
# 利用bot去请求创建发行版接口
gitlink = GitLinkApi(host)
req_data = {
"tag_name": f"{now_time}",
"name": f"{now_time}: bot触发创建",
"body": f"bot检测到过去24小时仓库有推送触发发行版的自动创建\n{value.get('commits_info')}",
"target_commitish": value.get('branch')
}
logger.debug(f"请求接口的参数:{req_data}")
# 调用接口创建发行版
res = gitlink.create_version(project=key, token=access_token, req_data=req_data)
logger.debug(f"创建发行版的响应数据::{res}")
GLOBAL_VAR.clear()