feat: 增加 linear webhook 接口和 discord 通知
All checks were successful
continuous-integration/drone Build is passing
All checks were successful
continuous-integration/drone Build is passing
This commit is contained in:
parent
1284a009e8
commit
8e100f7170
73
.drone.yml
Normal file
73
.drone.yml
Normal file
@ -0,0 +1,73 @@
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: default
|
||||
|
||||
steps:
|
||||
- name: build-and-push
|
||||
image: plugins/docker
|
||||
settings:
|
||||
username:
|
||||
from_secret: docker_username
|
||||
password:
|
||||
from_secret: docker_password
|
||||
repo: git.tunpok.com/ching/linear-discord-webhook
|
||||
registry: git.tunpok.com
|
||||
tags: latest
|
||||
|
||||
# - name: notify
|
||||
# image: plugins/webhook
|
||||
# settings:
|
||||
# urls: http://bark.tunpok.com/UZ6zC82bKRjQaXiVkosVWh/
|
||||
# content_type: application/json
|
||||
# template: |
|
||||
# {
|
||||
# "title": "{{#success build.status}}🟢{{else}}🔴{{/success}} Drone Build #{{ build.number }} {{ build.status }} {{#success build.status}}🟢{{else}}🔴{{/success}}",
|
||||
# "body": "Project: {{ repo.name }}\nBranch: {{ build.branch }}\nCommit: {{ truncate build.commit 8 }}",
|
||||
# "group": "drone",
|
||||
# "url": "{{ build.link }}",
|
||||
# "icon": "https://static-00.iconduck.com/assets.00/drone-icon-2048x2048-6zua2vkz.png"
|
||||
# }
|
||||
# when:
|
||||
# status: [success, failure]
|
||||
# https://discord.com/api/webhooks/1213409068559900683/szl0AICZwA1V82dg8Vrc_xqOCl1WwnxktlQdf4cdILswR-xZBI5-JOdqGSD8dVUNcUlH
|
||||
- name: deploy
|
||||
image: appleboy/drone-ssh
|
||||
settings:
|
||||
host:
|
||||
- 148.135.109.242
|
||||
username: root
|
||||
key:
|
||||
from_secret: ssh_key
|
||||
passphrase:
|
||||
from_secret: ssh_passphrase
|
||||
port: 22
|
||||
command_timeout: 2m
|
||||
script:
|
||||
- echo "Pull new image"
|
||||
- docker pull git.tunpok.com/ching/linear-discord-webhook:latest
|
||||
- echo "Go to the project directory"
|
||||
- cd /root/develop/linear-discord-webhook
|
||||
- echo "Restart the container"
|
||||
- docker-compose down && docker-compose up -d
|
||||
|
||||
- name: discord notification
|
||||
image: appleboy/drone-discord
|
||||
settings:
|
||||
webhook_id:
|
||||
from_secret: discord_webhook_id
|
||||
webhook_token:
|
||||
from_secret: discord_webhook_token
|
||||
# message: |
|
||||
# Drone Build #${DRONE_BUILD_NUMBER} ${DRONE_BUILD_STATUS}
|
||||
# Project: ${DRONE_REPO_NAME}
|
||||
# Branch: ${DRONE_BRANCH}
|
||||
# Commit: ${DRONE_COMMIT_SHA:0:8}
|
||||
# [Build Log](${DRONE_BUILD_LINK})
|
||||
when:
|
||||
status: [success, failure]
|
||||
|
||||
|
||||
volumes:
|
||||
- name: dockersock
|
||||
host:
|
||||
path: /var/run/docker.sock
|
||||
14
Dockerfile
Normal file
14
Dockerfile
Normal file
@ -0,0 +1,14 @@
|
||||
# 使用自定义 Docker Registry 中的官方 Python 镜像作为基础镜像
|
||||
FROM git.tunpok.com/ching/python-env:latest
|
||||
|
||||
# 设置工作目录
|
||||
WORKDIR /app
|
||||
|
||||
# 将当前目录下的所有文件复制到容器中
|
||||
COPY . .
|
||||
|
||||
# port number
|
||||
EXPOSE 5000
|
||||
|
||||
# run flask app
|
||||
CMD ["python", "app.py"]
|
||||
43
app.py
Normal file
43
app.py
Normal file
@ -0,0 +1,43 @@
|
||||
from flask import Flask, request, jsonify
|
||||
import apprise
|
||||
import os
|
||||
from loguru import logger
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
DISCORD_WEBHOOK_URL = os.environ.get('DISCORD_WEBHOOK_URL')
|
||||
DISCORD_WEBHOOK_ID = DISCORD_WEBHOOK_URL.split('/')[-2]
|
||||
DISCORD_WEBHOOK_TOKEN = DISCORD_WEBHOOK_URL.split('/')[-1]
|
||||
|
||||
@app.route('/linear/issue', methods=['POST'])
|
||||
def linear_issue():
|
||||
""" https://developers.linear.app/docs/graphql/webhooks#the-webhook-payload
|
||||
"""
|
||||
if request.headers.get('Linear-Event') != 'issue':
|
||||
logger.error('Invalid event type: %s', request.headers.get('Linear-Event'))
|
||||
return jsonify({'message': 'Invalid event type'}), 400
|
||||
data = request.json
|
||||
logger.info('Received issue webhook: %s', data)
|
||||
if data['action'] != 'update':
|
||||
logger.warning('Ignoring issue action: %s', data['action'])
|
||||
return jsonify({'message': 'Ignoring issue action'}), 200
|
||||
# Send Discord message
|
||||
apobj = apprise.Apprise()
|
||||
apobj.add(f'discord://{DISCORD_WEBHOOK_ID}/{DISCORD_WEBHOOK_TOKEN}/?avatar=No&format=markdown')
|
||||
apobj.asset.app_id = None
|
||||
apobj.notify(body='Issue status changed')
|
||||
|
||||
# if data['updatedFrom'].get('statusId') != data['issue']['statusId']:
|
||||
# logger.info('Issue status changed: %s', data['issue']['status']['name'])
|
||||
# # Send Discord message with embeded content
|
||||
# # set apprise format to markdown
|
||||
# apobj.notify(
|
||||
# body=f'Issue status changed: **{data["issue"]["status"]["name"]}**',
|
||||
# title=data['issue']['title'],
|
||||
# body_format=apprise.AppriseFormat.MARKDOWN
|
||||
# )
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host="0.0.0.0", port=5000)
|
||||
10
docker-compose.yml
Normal file
10
docker-compose.yml
Normal file
@ -0,0 +1,10 @@
|
||||
version: '3'
|
||||
services:
|
||||
barcode-helper:
|
||||
image: git.tunpok.com/ching/linear-discord-webhook:latest
|
||||
container_name: linear-discord-webhook
|
||||
restart: always
|
||||
environment:
|
||||
- DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/1234567890/ABCDEFGHIJKLMN
|
||||
ports:
|
||||
- 9289:5000
|
||||
Loading…
x
Reference in New Issue
Block a user