Skip to content

Commit ab6a823

Browse files
authored
JIRA bug hunter
1 parent 6d16eb4 commit ab6a823

File tree

1 file changed

+150
-0
lines changed

1 file changed

+150
-0
lines changed

JIRA_hackGPT.py

+150
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
from dotenv import load_dotenv
4+
import sys
5+
import fade
6+
from pathlib import Path
7+
import openai
8+
from time import sleep
9+
import os
10+
import fade
11+
from pathlib import Path
12+
import openai
13+
import requests
14+
import urllib.parse
15+
import urllib.request
16+
import openai
17+
from dotenv import load_dotenv
18+
import gradio as gr
19+
import pandas as pd
20+
import matplotlib.pyplot as plt
21+
import json
22+
import csv
23+
import datetime
24+
import argparse
25+
from prettytable.colortable import ColorTable, Themes
26+
from prettytable import from_csv
27+
from jira import JIRA
28+
# Load API key from an environment variable or secret management service
29+
30+
load_dotenv(".env")
31+
apiToken = os.environ.get('OPENAI_TOKEN')
32+
jira_token = os.environ.get('JIRA_TOKEN')
33+
openai.api_key = apiToken
34+
35+
36+
if 'OPENAI_TOKEN' in os.environ:
37+
openai_token = os.environ['OPENAI_TOKEN']
38+
39+
elif 'JIRA_USER' in os.environ:
40+
41+
jira_pass = os.environ['JIRA_TOKEN']
42+
else:
43+
error='''
44+
* ) ) (
45+
`( ( /(( ( ( )\
46+
)\( )\())\ ( )\))( ((((_)
47+
((_)\ (_))((_) )\ ) (( ))\ )\)
48+
8"""" 8"""8 8"""8 8"""88 8"""8
49+
8 8 8 8 8 8 8 8 8
50+
8eeee 8eee8e 8eee8e 8 8 8eee8e
51+
88 88 8 88 8 8 8 88 8
52+
88 88 8 88 8 8 8 88 8
53+
88eee 88 8 88 8 8eeee8 88 8
54+
55+
\033[1;33mAttempting to Set OpenAI and JIRA system variable with API key.'''
56+
fadederror = fade.fire(error)
57+
print(fadederror)
58+
Path(".env").touch()
59+
setting_token = open(".env", "a")
60+
userkey = input('Enter OpenAI API Key: ').replace(" ","")
61+
setting_token.write("OPENAI_TOKEN="+'"'+userkey+'"\n')
62+
#https://id.atlassian.com/manage-profile/security/api-tokens
63+
jiratoken = input('Enter JIRA Token: ').replace(" ","")
64+
setting_token.write("JIRA_TOKEN="+'"'+jiratoken+'"\n')
65+
66+
67+
date_string = datetime.datetime.now()
68+
69+
load_dotenv()
70+
apiToken = os.environ.get("OPENAI_TOKEN")
71+
headers = {
72+
"Accept": "application/json; charset=utf-8",
73+
"Authorization": "Token" + str(apiToken)
74+
}
75+
76+
77+
78+
if 'OPENAI_TOKEN' in os.environ:
79+
pass
80+
else:
81+
os.environ['OPENAI_TOKEN'] = input('Enter API Key: ').replace(" ","")
82+
token = os.environ.get("OPENAI_TOKEN")
83+
hack= "\n"*7 + r"""
84+
85+
86+
87+
|¯¯¯¯| |¯¯¯¯| '/¯¯¯/.\¯¯¯\‚ '/¯¯¯¯/\¯¯¯¯\ |¯¯¯¯| |¯¯¯¯|
88+
|:·.·|_|:·.·| |:·.·|_|:·.·| |:·.·| |____| |:·.·|./____/
89+
|:·.·|¯|:·.·| |:·.·|¯|:·.·| |:·.·|__|¯¯¯¯| |:·.·|.\¯¯¯¯\
90+
|____| |____| |____|:|____| \__ _\/____/ |____| |_____|
91+
92+
93+
""" + "\n"*12
94+
95+
gpt = "\n"*4 +r"""
96+
97+
______ _______ ________
98+
/ \| \| \
99+
| ▓▓▓▓▓▓\ ▓▓▓▓▓▓▓\\▓▓▓▓▓▓▓▓
100+
| ▓▓ __\▓▓ ▓▓__/ ▓▓ | ▓▓
101+
| ▓▓| \ ▓▓ ▓▓ | ▓▓
102+
| ▓▓ \▓▓▓▓ ▓▓▓▓▓▓▓ | ▓▓
103+
| ▓▓__| ▓▓ ▓▓ | ▓▓
104+
\▓▓ ▓▓ ▓▓ | ▓▓
105+
\▓▓▓▓▓▓ \▓▓ \▓▓
106+
"""
107+
108+
fadedhack = fade.water(hack)
109+
fadedgpt = fade.random(gpt)
110+
111+
112+
for pair in zip(*map(str.splitlines, (fadedhack, fadedgpt))):
113+
print(*pair)
114+
115+
# Authenticate with JIRA
116+
#jira_url = input("Enter JIRA URL: ")
117+
jira_options = {'server': 'YOUR_JIRA_URL'}
118+
jira = JIRA(options=jira_options, basic_auth=('YOUR_JIRA_EMAIL', 'YOUR_JIRA_TOKEN'))
119+
120+
121+
issues = jira.search_issues('type = bug ')
122+
for issue in issues:
123+
ticket = fade.brazil("JIRA Ticket Summary: ")
124+
summary = fade.water(issue.fields.summary)
125+
description = fade.water(issue.fields.description)
126+
des_summary = fade.brazil("Issue description: ")
127+
print(ticket.rstrip('\n') + summary)
128+
print(des_summary.rstrip('\n'))
129+
print(description)
130+
prompt = f"Fix the following issue: {issue.fields.description}"
131+
model_engine = "davinci"
132+
completions = openai.Completion.create(
133+
engine=model_engine,
134+
prompt=prompt,
135+
max_tokens=1024,
136+
n=1,
137+
stop=None,
138+
temperature=0.7,
139+
)
140+
solution = fade.brazil("Genrating solution and adding to : ")
141+
print (solution)
142+
print("Sample: " + completions.choices[0].text[:40])
143+
response = completions.choices[0].text
144+
jira.add_comment(issue.key, response)
145+
146+
#with open('output/JIRA_hackGPT_log.csv', 'a+', encoding='UTF8', newline='') as f:
147+
# w = csv.writer(f, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
148+
# w.writerow([date_string, {issue.fields.description}, str(response).lstrip('\n')])
149+
# f.close()
150+

0 commit comments

Comments
 (0)