每一个review 按钮 对应一个提交详情 文件差异 点击即可查看
一个push中的多次提交会合并到一个panel里
{
"WEB_HOOK":"https://open.feishu.cn/open-apis/bot/v2/hook/2c26ff64-6a70-4b09-96f2-aa036cfe8832",
"SECRET":"G9rWIBOKysswilBqKREjoc",
"GITLAB_HOME":"http://192.168.2.50:8090/",
"GITLAB_TOKEN":"WBUrYRUySkWV2qj418U5",
"LISTEN_PROJ":"Makeover-Client"
}
进入到你的项目仓库里 将网页地址中 ip+端口号 的copy下来
例如 http://192.168.2.50:8090/31/helloworld-client
那么 Home地址就是 http://192.168.2.50:8090/
点击生成后 上方后出现Token码 Copy到机器人 conf.json配置中
https://download.csdn.net/download/qq_39162566/87447917
https://download.csdn.net/download/qq_39162566/87447917
运行环境 python 3.x
import base64
import hmac
import json
import os
import time
from hashlib import sha256
import requests
envDict = json.load(open("./bin/conf.json"))
def SendMsg( text,user="",proj="",branch="",web_urls = [] ):
timestamp = str(round(time.time()))
secret = envDict["SECRET"]
url = envDict["WEB_HOOK"]
key = f'{timestamp}\n{secret}'
key_enc = key.encode('utf-8')
msg = ""
msg_enc = msg.encode('utf-8')
hmac_code = hmac.new(key_enc, msg_enc, digestmod=sha256).digest()
sign = base64.b64encode(hmac_code).decode('utf-8')
# text content
# payload_message = {
# "timestamp": timestamp,
# "sign": sign,
# "msg_type": "text",
# "content": {
# "text": text
# }
# }
# review window
patchset_msg = '**Subject :** ' + text + '\n' +\
'**Owner :** ' + user + '\n' +\
'**Project :** ' + proj + '\n' +\
'**Branch :** ' + branch
payload_message = {
"msg_type": "interactive",
"timestamp": timestamp,
"sign": sign,
"card": {
"config": {
"wide_screen_mode": True
},
"elements": [
{
"tag": "div",
"text": {
"content": patchset_msg,
"tag": "lark_md"
}
},
{
"tag": "hr"
},
{
"actions": [
{
"tag": "button",
"text": {
"content": "Review " + web_urls[0][1],
"tag": "plain_text"
},
"type": "primary",
"url": web_urls[0][0]
}
],
"tag": "action"
}
],
"header": {
"template": "blue",
"title": {
"content": "GitLab Commit",
"tag": "plain_text"
}
}
}
}
#补充额外的提交review按钮
if len( web_urls ) > 1:
actions = payload_message['card']['elements'][2]['actions']
for i in range(1,len(web_urls),1):
action = {
"tag": "button",
"text": {
"content": "Review " + web_urls[i][1],
"tag": "plain_text"
},
"type": "primary",
"url": web_urls[i][0]
}
actions.append(action)
headers = {
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=json.dumps(payload_message))
print(response.text)
每一个review 按钮 对应一个提交详情 文件差异 点击即可查看
patchset_msg = '**Subject :** ' + text + '\n' +\
'**Owner :** ' + user + '\n' +\
'**Project :** ' + proj + '\n' +\
'**Branch :** ' + branch
payload_message = {
"msg_type": "interactive",
"timestamp": timestamp,
"sign": sign,
"card": {
"config": {
"wide_screen_mode": True
},
"elements": [
{
"tag": "div",
"text": {
"content": patchset_msg,
"tag": "lark_md"
}
},
{
"tag": "hr"
},
{
"actions": [
{
"tag": "button",
"text": {
"content": "Review " + web_urls[0][1],
"tag": "plain_text"
},
"type": "primary",
"url": web_urls[0][0]
}
],
"tag": "action"
}
],
"header": {
"template": "blue",
"title": {
"content": "GitLab Commit",
"tag": "plain_text"
}
}
}
}