Last active
February 16, 2024 15:35
-
-
Save grafuls/555b1d7238eeb9f8cc22b680c080cb99 to your computer and use it in GitHub Desktop.
Gitlab to Jira webhook translator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
from flask import Flask, request | |
import requests | |
import json | |
import os | |
JIRA_WEBHOOK_ID = os.getenv("JIRA_WEBHOOK_ID") | |
JIRA_WEBHOOK = f"https://issues.redhat.com/rest/cb-automation/latest/hooks/{JIRA_WEBHOOK_ID}" | |
app = Flask(__name__) | |
@app.route("/") | |
def hello(): | |
return "Webhooks Transformer is running!" | |
@app.route("/gitlabIssue", methods=["POST"]) | |
def githubIssue(): | |
data = request.json | |
print(f'Issue {data["object_attributes"]["title"]} {data["object_kind"]}') | |
print(f'{data["object_attributes"]["description"]}') | |
print(f'{data["object_attributes"]["url"]}') | |
headers = {"Content-type": "application/json"} | |
data = { | |
"data": { | |
"name": f'[{data["project"]["name"]}][{data["object_kind"]}] {data["object_attributes"]["title"]}', | |
"description": f'Description: {data["object_attributes"]["description"]}\nURL: {data["object_attributes"]["url"]}', | |
} | |
} | |
response = requests.post(JIRA_WEBHOOK, headers=headers, data=json.dumps(data)) | |
print(response.status_code) | |
print(response.text) | |
return data | |
if __name__ == "__main__": | |
app.run(debug=True, host="0.0.0.0", port=5005) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment