Added a set of BugbotServerAPI classes, which can currently pull a list of bugs from Gitea.

This commit is contained in:
Jamie Greunbaum 2024-05-18 03:35:44 -04:00
parent f4a2695cc1
commit c536a89d9f
3 changed files with 115 additions and 6 deletions

37
Scripts/server_api.gd Normal file
View File

@ -0,0 +1,37 @@
class_name BugbotServerAPI
extends Object
enum BugbotServerError { OK, THREAD_NULL, THREAD_BUSY }
static var __bugbot_server_thread : Thread
func _init():
__bugbot_server_thread = Thread.new()
static func _return_list_of_bugs(callback:Callable) -> int:
print("Insert list of ", _current_server_api(), " bugs here.")
return BugbotServerError.OK
static func _prepare_form() -> int:
print("Prepare ", _current_server_api(), " form here.")
return BugbotServerError.OK
static func _send_form_data() -> int:
print("Send ", _current_server_api(), " form data here.")
return BugbotServerError.OK
static func _current_server_api() -> String:
return ""
static func _build_url_string() -> String:
return ""
static func _create_header_data(mime_type:String, api_key:String) -> Array:
return []
func __return_list_of_bugs_thread(callback:Callable) -> void:
pass

View File

@ -0,0 +1,74 @@
class_name BugbotServerGiteaAPI
extends "res://addons/Bugbot/Scripts/server_api.gd"
static func _return_list_of_bugs(callback:Callable) -> int:
if not __bugbot_server_thread:
printerr("Server thread is null.")
return BugbotServerError.THREAD_NULL
if __bugbot_server_thread.is_started():
printerr("Server thread is currently busy.")
return BugbotServerError.THREAD_BUSY;
__bugbot_server_thread = Thread.new()
__bugbot_server_thread.start(__return_list_of_bugs_thread.bind(callback))
return BugbotServerError.OK
#func _prepare_form() -> void:
#print("Prepare ", _current_server_api(), " form here.")
#
#func _send_form_data() -> void:
#print("Send ", _current_server_api(), " form data here.")
func __return_list_of_bugs_thread(callback:Callable) -> void:
var http_client : HTTPClient = HTTPClient.new()
var server : String = ProjectSettings.get_setting("bugbot/reporting/gitea/server")
var error : int = http_client.connect_to_host(server, 443)
assert(error == Error.OK)
while http_client.get_status() == HTTPClient.STATUS_CONNECTING or http_client.get_status() == HTTPClient.STATUS_RESOLVING:
http_client.poll()
assert(http_client.get_status() == HTTPClient.STATUS_CONNECTED)
var api_url : String = _build_url_string()
var header_data : Array = _create_header_data("application/json", ProjectSettings.get_setting("bugbot/reporting/gitea/API_key",""))
error = http_client.request(HTTPClient.METHOD_GET, api_url, header_data)
assert(error == Error.OK)
while http_client.get_status() == HTTPClient.STATUS_REQUESTING:
http_client.poll()
assert(http_client.get_status() == HTTPClient.STATUS_BODY or http_client.get_status() == HTTPClient.STATUS_CONNECTED)
var response_string : String = ""
if http_client.has_response():
var response_body : PackedByteArray = PackedByteArray()
while http_client.get_status() == HTTPClient.STATUS_BODY:
http_client.poll()
var chunk : PackedByteArray = http_client.read_response_body_chunk()
if chunk.size() > 0:
response_body = response_body + chunk
response_string = response_body.get_string_from_utf8()
callback.call_deferred(JSON.parse_string(response_string) as Array)
__bugbot_server_thread.call_deferred("wait_to_finish")
static func _current_server_api() -> String:
return "Gitea"
static func _build_url_string() -> String:
return "/" + \
ProjectSettings.get_setting("bugbot/reporting/gitea/base_URL", "api/v1/") + \
"/repos/" + \
ProjectSettings.get_setting("bugbot/reporting/gitea/owner_name") + \
"/" + \
ProjectSettings.get_setting("bugbot/reporting/gitea/repo_name") + \
"/issues"
static func _create_header_data(mime_type:String, api_key:String) -> Array:
return [
"User-Agent: Pirulo/1.0 (Godot)",
"Accept: " + mime_type,
"Content-Type: " + mime_type,
"Authorization: token " + api_key,
]

View File

@ -25,9 +25,6 @@ func _enter_tree() -> void:
bugbot_menu.add_item("Show Bug Markers", BugbotMenuItems.SHOW_BUG_MARKERS) bugbot_menu.add_item("Show Bug Markers", BugbotMenuItems.SHOW_BUG_MARKERS)
bugbot_menu.add_item("Hide Bug Markers", BugbotMenuItems.HIDE_BUG_MARKERS) bugbot_menu.add_item("Hide Bug Markers", BugbotMenuItems.HIDE_BUG_MARKERS)
bugbot_menu.id_pressed.connect(__on_bugbot_menu_item_pressed) bugbot_menu.id_pressed.connect(__on_bugbot_menu_item_pressed)
# This is where we should initialise options for showing bug markers
pass
func _exit_tree() -> void: func _exit_tree() -> void:
@ -35,7 +32,6 @@ func _exit_tree() -> void:
__bugbot_menu_button.queue_free() __bugbot_menu_button.queue_free()
# This is where we should remove any visible bug markers # This is where we should remove any visible bug markers
pass
func __initialise_project_settings(): func __initialise_project_settings():
@ -49,7 +45,7 @@ func __initialise_project_settings():
__add_project_setting("bugbot/reporting/bug_report_widget_depth", TYPE_INT, 10000) __add_project_setting("bugbot/reporting/bug_report_widget_depth", TYPE_INT, 10000)
#region Bugzilla #region Bugzilla
__add_project_setting("bugbot/reporting/bugzilla/server", TYPE_STRING, "https://127.0.0.1:4433") __add_project_setting("bugbot/reporting/bugzilla/server", TYPE_STRING, "https://gitea.example.com")
__add_project_setting("bugbot/reporting/bugzilla/REST_URI", TYPE_STRING, "rest/") __add_project_setting("bugbot/reporting/bugzilla/REST_URI", TYPE_STRING, "rest/")
__add_project_setting("bugbot/reporting/bugzilla/product_name", TYPE_STRING, "") __add_project_setting("bugbot/reporting/bugzilla/product_name", TYPE_STRING, "")
__add_project_setting("bugbot/reporting/bugzilla/API_key", TYPE_STRING, "") __add_project_setting("bugbot/reporting/bugzilla/API_key", TYPE_STRING, "")
@ -102,7 +98,9 @@ func __initialise_project_settings():
func __on_bugbot_menu_item_pressed(id:int): func __on_bugbot_menu_item_pressed(id:int):
match id: match id:
BugbotMenuItems.SHOW_BUG_MARKERS: BugbotMenuItems.SHOW_BUG_MARKERS:
print("Show Bug Markers is happening.") print(EditorInterface.get_edited_scene_root().scene_file_path)
var server_api : BugbotServerGiteaAPI = BugbotServerGiteaAPI.new()
server_api._return_list_of_bugs(func(a:Array):print(a))
BugbotMenuItems.HIDE_BUG_MARKERS: BugbotMenuItems.HIDE_BUG_MARKERS:
print("Show Bug Markers is not happening. In fact, the opposite of that.") print("Show Bug Markers is not happening. In fact, the opposite of that.")