Skip to content

Commit

Permalink
update alifunction yuque webhook
Browse files Browse the repository at this point in the history
  • Loading branch information
Flionay committed Sep 19, 2024
1 parent 96336bc commit 630c5f6
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ halo 站点访问没问题直接提交所有文件到 Github 仓库即可

在语雀仓库中设置webhook之后,当在知识库中改动文档后,就会自动触发 Github Actions流水线,会重新从语雀增量拉取文档,并自动部署到 Halo 站点,如此就实现了自动化部署博客。

按照这个文档,配置语雀webhook触发器:[**ServerlessAPI**](https://github.com/elog-x/serverless-api),按照文档配置好 URL 参数并浏览器访问即可触发流水线
按照阿里云云函数文档,配置语雀webhook云函数,详情在`yuque_webhook.py`,将Github的token配置在云函数的环境变量里,其余参数通过query传递,然后配置在语雀知识库的webhook中,检测发送消息成功即可

```text
https://serverless-api-elog.vercel.app/api/github?user=xxx&repo=xxx&event_type=deploy&token=xxx
https://yuque-webhook-xxxxx.cn-beijing.xxxxx.run/yuque/webhook?user=Flionay&repo=yuque_halo&event_type=deploy
```

感谢作者:https://github.com/elog-x/notion-halo
Expand Down
48 changes: 48 additions & 0 deletions yuque_webhook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from flask import Flask, request, jsonify
import os
import requests


REQUEST_ID_HEADER = 'x-fc-request-id'

app = Flask(__name__)

GITHUB_TOKEN = os.environ.get('GITHUB_TOKEN')

@app.route('/yuque/webhook', methods=['GET', 'POST'])
def yuque_webhook():
if request.method == 'GET':
user = request.args.get('user')
repo = request.args.get('repo')
event_type = request.args.get('event_type')
else:
user = request.args.get('user')
repo = request.args.get('repo')
event_type = request.args.get('event_type')
token = GITHUB_TOKEN
print(user, repo, event_type)

if not all([user, repo, event_type]):
return jsonify({"message": "Missing required parameters"}), 400

headers = {
"User-Agent": "@elog/serverless-api",
"Accept": "*/*",
"Authorization": f"token {token}"
}

try:
response = requests.post(
f"https://api.github.com/repos/{user}/{repo}/dispatches",
json={"event_type": event_type},
headers=headers
)

return jsonify({"message": 'Success!'}), 200
except Exception as e:
print(e)
return jsonify({"message": str(e)}), 401
return jsonify({"message": "Success!"}), 200

if __name__ == '__main__':
app.run(host='0.0.0.0',port=9000)

0 comments on commit 630c5f6

Please sign in to comment.