简体   繁体   English

如何使用 Google Cloud Functions 从 JIRA 转发 webhook 数据?

[英]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.

相关问题 如何在谷歌云功能上使用电报网络钩子? - How to use telegram webhook on google cloud functions? 如何使用python从谷歌云读取mp3数据 - how to read mp3 data from google cloud using python 如何使用适用于 Cloud Functions 的 Google Python 客户端获取 Google Cloud Functions 的列表? - How can I get a list of Google Cloud Functions using Google Python Client for Cloud Functions? 使用 Google Cloud Functions 在两个 BigQuery 项目之间传输数据 - Data Transfer between two BigQuery Projects using Google Cloud Functions 如何构建一个 function(在 Python 中)调用来自 Google Cloud Functions 中不同(hubspot)API 密钥的数据? - How to build a function (in Python) that calls the data from different (hubspot) API-keys in Google Cloud Functions? 如何将数据从Google存储云读取到Google云数据板 - How to read data from Google storage cloud to Google cloud datalab 如何使用python和REST编写查询以从JIRA检索数据 - how to write queries using python and REST to retrieve data from JIRA 如何使用自定义容器镜像部署谷歌云功能 - How to deploy google cloud functions using custom container image 如何在 Google Cloud 中设置 webhook,使代码以自动化方式运行 - How to setup a webhook in Google Cloud that make the code runs in automation way 使用 Google Cloud Functions 时如何为 Google Cloud Datastore 实体设置日期属性? - How to set date property for Google Cloud Datastore entity when using Google Cloud Functions?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM