This commit is contained in:
Fabian 2021-11-30 20:55:40 +01:00
parent dc43db69a3
commit 0a01146227

View File

@ -3,9 +3,8 @@ import sys
import threading import threading
import traceback import traceback
from enum import Enum, auto from enum import Enum, auto
from functools import reduce from functools import reduce, partial
from queue import Queue, Empty from queue import Queue, Empty
from urllib.parse import urlparse, parse_qs
try: try:
from PySide6 import QtCore, QtWidgets from PySide6 import QtCore, QtWidgets
@ -90,20 +89,18 @@ class TaskCompleter(QtWidgets.QCompleter):
) )
with self.rif_counter_lock: with self.rif_counter_lock:
self.rif_counter += 1 self.rif_counter += 1
future.add_done_callback(self.picker_response_callback) future.add_done_callback(partial(self.picker_response_callback, self.text))
def picker_response_callback(self, future): def picker_response_callback(self, text, future):
with self.rif_counter_lock: with self.rif_counter_lock:
self.rif_counter -= 1 self.rif_counter -= 1
try: try:
result = future.result() result = future.result()
parsed = urlparse(result.request.url)
response_text = parse_qs(parsed.query)["query"][0]
issues = reduce(lambda x, y: x + (y["issues"]), result.json()["sections"], []) issues = reduce(lambda x, y: x + (y["issues"]), result.json()["sections"], [])
extracted = list(map(lambda x: f"{x['key']} {x['summaryText']}", issues)) extracted = list(map(lambda x: f"{x['key']} {x['summaryText']}", issues))
if extracted: if extracted:
self.queue.put({ self.queue.put({
"response_text": response_text, "response_text": text,
"result": extracted, "result": extracted,
}) })
else: else:
@ -132,20 +129,18 @@ class TaskCompleter(QtWidgets.QCompleter):
) )
with self.rif_counter_lock: with self.rif_counter_lock:
self.rif_counter += 1 self.rif_counter += 1
future.add_done_callback(self.search_response_callback) future.add_done_callback(partial(self.search_response_callback, self.text))
def search_response_callback(self, future): def search_response_callback(self, text, future):
with self.rif_counter_lock: with self.rif_counter_lock:
self.rif_counter -= 1 self.rif_counter -= 1
try: try:
result = future.result() result = future.result()
json_result = result.json() json_result = result.json()
parsed = urlparse(result.request.url)
response_text = parse_qs(parsed.query)["jql"][0].split()[2]
if "issues" in json_result: if "issues" in json_result:
extracted = list(map(lambda x: f"{x['key']} {x['fields']['summary']}", json_result["issues"])) extracted = list(map(lambda x: f"{x['key']} {x['fields']['summary']}", json_result["issues"]))
self.queue.put({ self.queue.put({
"response_text": response_text, "response_text": text,
"result": extracted, "result": extracted,
}) })
except Exception: except Exception: