基于gitee 的webhook 的python 處理

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è)信息。
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀(guān)點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容