From ef710ed148abaf4a27a0bbbc689d99c1caa2f15e Mon Sep 17 00:00:00 2001 From: Akshai183 <109257185+Akshai183@users.noreply.github.com> Date: Sat, 9 Mar 2024 22:29:22 +0530 Subject: [PATCH 1/2] Create issues --- Day-17/issues | 1 + 1 file changed, 1 insertion(+) create mode 100644 Day-17/issues diff --git a/Day-17/issues b/Day-17/issues new file mode 100644 index 00000000..0ba4b825 --- /dev/null +++ b/Day-17/issues @@ -0,0 +1 @@ +This is my project for python flask app, using this I am going automate creating issues using Jira From 21786297f3b014a7241b63c8d5d7665883462585 Mon Sep 17 00:00:00 2001 From: Akshai183 <109257185+Akshai183@users.noreply.github.com> Date: Sun, 10 Mar 2024 12:13:17 +0530 Subject: [PATCH 2/2] Create createifjiraiscommented.py --- Day-15/createifjiraiscommented.py | 79 +++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 Day-15/createifjiraiscommented.py diff --git a/Day-15/createifjiraiscommented.py b/Day-15/createifjiraiscommented.py new file mode 100644 index 00000000..33f872f6 --- /dev/null +++ b/Day-15/createifjiraiscommented.py @@ -0,0 +1,79 @@ +from flask import Flask, request, jsonify +from requests.auth import HTTPBasicAuth +import requests +import json + +app = Flask(__name__) + +def createJIRA(): + #please enter your url - change the url to your jira url + url = "https://akshay05pakhanati.atlassian.net/rest/api/3/issue" +#please enter your API_Token + API_TOKEN = "*provide your API_TOKEN here" + #*change to your gmail id under auth section.* + auth = HTTPBasicAuth("akshay05pakhanati@gmail.com", API_TOKEN) + headers = { + "Accept": "application/json", + "Content-Type": "application/json" + } + payload = json.dumps({ + "fields": { + "description": { + "content": [ + { + "content": [ + { + "text": "My first jira ticket", + "type": "text" + } + ], + "type": "paragraph" + } + ], + "type": "doc", + "version": 1 + }, + "project": { + #*please provide your jira project key value I have given mine* + "key": "AK" + }, + "issuetype": { + "id": "10007" + }, + "summary": "First JIRA Ticket" + }, + "update": {} + }) + + response = requests.request( + "POST", + url, + data=payload, + headers=headers, + auth=auth + ) + + return response + +@app.route('/createJira', methods=['POST']) +def handle_webhook(): + # Verify that the request is from GitHub + if request.headers.get('X-GitHub-Event') == 'issue_comment': + payload = request.json + comment = payload['comment']['body'] + + # Check if the comment contains "/jira" + if "/jira" in comment: + response = createJIRA() + if response.status_code == 201: + return jsonify({'message': 'Jira issue created successfully'}), 200 + else: + return jsonify({'message': 'Failed to create Jira issue', 'status_code': response.status_code}), 500 + else: + return jsonify({'message': 'No action required'}), 200 + else: + return jsonify({'message': 'Invalid webhook event'}), 400 + +if __name__ == '__main__': + app.run(debug=True, host='0.0.0.0', port=5002) +