[英]How to forward webhook data from JIRA using Google Cloud Functions?
I want to make a simple middle-man script which receives data from a JIRA webhook and then parses it and sends it over (to Discord, but that's not important).我想制作一个简单的中间人脚本,它从 JIRA webhook 接收数据,然后解析它并将其发送过去(到 Discord,但这并不重要)。
From the looks of it, Cloud Functions was a perfect match, so I made a short script which just forwards the request json to a message on Discord to see what data it sends.从外观上看,Cloud Functions 是完美的匹配,所以我制作了一个简短的脚本,它只是将请求 json 转发到 Discord 上的一条消息,以查看它发送的数据。
import requests
import json
def forward(request):
data = request.json
#tried:
#data = request.get_json()
#data = request.data
#data = request.values
url = 'discord webhook receiver url'
myobj = {'content': str(data)}
requests.post(url, data = myobj)
return '', 200
Set up the webhook on the JIRA side and it kinda works, but not really.在 JIRA 端设置 webhook,它有点工作,但不是真的。 First of all it doesn't trigger on some events, like adding a comment or editing a task, only for important(?) events, like adding a new task.首先,它不会触发某些事件,例如添加评论或编辑任务,仅针对重要(?)事件,例如添加新任务。 And secondly, it doesn't even send the right looking data for it.其次,它甚至没有为它发送正确的数据。 This is all i'm getting这就是我得到的全部
{'timestamp': 1609851709546, 'webhookEvent': 'issuelink_created', 'issueLink': {'id': 10016, 'sourceIssueId': 10007, 'destinationIssueId': 10022, 'issueLinkType': {'id': 10004, 'name': 'jira_subtask_link', 'outwardName': 'jira_subtask_outward', 'inwardName': 'jira_subtask_inward', 'style': 'jira_subtask', 'isSubTaskLinkType': True, 'isSystemLinkType': True}, 'sequence': 12, 'systemLink': True}}
And I know those 2 things are wrong because while testing it I've also set up another webhook for Pipedream, where it reacts to all changes, and the data contains names of issues, avatars, links.而且我知道这两件事是错误的,因为在测试它时,我还为 Pipedream 设置了另一个 webhook,它对所有更改做出反应,并且数据包含问题名称、头像、链接。 Everything that's needed for what I'm trying to do.我正在尝试做的一切所需的一切。 And there aren't any differences between those 2 webhook settings, I have them both with all events selected.这两个 webhook 设置之间没有任何区别,我将它们都选中了所有事件。
So I've been at it for 2 days now with no breakthrough.所以我已经做了2天了,没有任何突破。 Maybe I'm misunderstanding how webhooks work, or maybe cloud functions isn't the service to use for this.也许我误解了 webhook 的工作原理,或者云功能不是用于此的服务。 So while the question is how to do it in cloud functions, I'm also open to alternatives.因此,虽然问题是如何在云功能中做到这一点,但我也对替代方案持开放态度。 (not the ones which do the formatting for you, as that's why I started making this in the first place) (不是那些为你做格式化的,因为这就是我开始做这个的原因)
Apparently Jira sends 2 requests on webhook trigger and the one containing all the useful info was just over the limit to be put into a Discord message so it never sent it.显然,Jira 在 webhook 触发器上发送了 2 个请求,其中一个包含所有有用信息的请求刚刚超过了要放入 Discord 消息的限制,因此它从未发送过它。 That's what I get for using it for logging.这就是我使用它进行日志记录的结果。
If anyone is also on the same dumbass path, then what I did to find that out is to save all the request data into a hastebin and send the link to it, like so.如果有人也在同一个笨蛋路径上,那么我所做的就是将所有请求数据保存到一个 hastebin 并将链接发送到它,就像这样。
#pack it all into a hastebin
everything = str(request.headers) + "\n" + str(request.data) + "\n" + str(request.args) + "\n" + str(request.form) + "\n" + str(request.method) + "\n" + str(request.remote_addr)
req = requests.post('https://hastebin.com/documents', data=everything)
#send the link id to discord
myobj = {'content': req.text}
x = requests.post(url, data = myobj)
All that's left is to parse and format the json.剩下的就是解析和格式化 json。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.