1. server.py
import flask
import json
from flask import request
app = flask.Flask(__name__)
# 啟用調(diào)試模式,進(jìn)行熱更新,或者export FLASK_ENV=development
app.debug = True
@app.route('/',methods=['GET','POST'])
def index():
# 從request中獲取請(qǐng)求體的數(shù)據(jù),類(lèi)型為string
data=request.get_data()
# 轉(zhuǎn)換為list 或 dict 類(lèi)型
xs=json.loads(data)
# 獲取最新提交的用戶(hù)名
print(xs['user_name'])
# 獲取提交的message
print(xs['head_commit']['message'])
# 獲取推送的分支名稱(chēng)
print(xs['ref']) # eg: refs/heads/master
return "success"
app.run(host='0.0.0.0',port='5000')
2. gitee 的 Push / Tag Hook 數(shù)據(jù)格式說(shuō)明:
具體查詢(xún): https://gitee.com/help/articles/4271#article-header1
{
hook_id: self.id, # 鉤子 id。
hook_url: hook_url, # 鉤子路由。
hook_name: String, # 鉤子名,固定為 push_hooks/tag_push_hooks。
password: String, # 鉤子密碼。eg:123456
timestamp: Number, # 觸發(fā)鉤子的時(shí)間戳。eg: 1576754827988
sign: String, # 鉤子根據(jù)密鑰計(jì)算的簽名。eg: "rLEHLuZRIQHuTPeXMib9Czoq9dVXO4TsQcmQQHtjXHA="
ref: String, # 推送的分支。eg:refs/heads/master
before: String, # 推送前分支的 commit id。eg:5221c062df39e9e477ab015df22890b7bf13fbbd
after: String, # 推送后分支的 commit id。eg:1cdcd819599cbb4099289dbbec762452f006cb40
[total_commits_count: Number], # 推送包含的 commit 總數(shù)。
[commits_more_than_ten: Boolean], # 推送包含的 commit 總數(shù)是否大于十二。
created: Boolean, # 推送的是否是新分支。
deleted: Boolean, # 推送的是否是刪除分支。
compare: String, # 推送的 commit 差異 url。eg:https://gitee.com/oschina/git-osc/compare/5221c062df39e9e477ab015df22890b7bf13fbbd...1cdcd819599cbb4099289dbbec762452f006cb40
commits: [*commit] || null, # 推送的全部 commit 信息。
head_commit: commit, # 推送最前面的 commit 信息。
repository: *project, # 推送的目標(biāo)倉(cāng)庫(kù)信息。
project: *project, # 推送的目標(biāo)倉(cāng)庫(kù)信息。
user_id: Number,
user_name: String, # 推送者的昵稱(chēng)。
user: *user, # 推送者的用戶(hù)信息。
pusher: *user, # 推送者的用戶(hù)信息。
sender: *user, # 推送者的用戶(hù)信息。
enterprise: *enterprise || ull # 推送的目標(biāo)倉(cāng)庫(kù)所在的企業(yè)信息。
}