Merge pull request 'Markers can now be loaded and unloaded in the editor. Currently not fully implemented, but getting there.' (#2) from making-slow-and-annoying-progress into main

Reviewed-on: BattyBovine/Bugbot#2
This commit is contained in:
Jamie Greunbaum 2024-05-19 18:18:41 -04:00
commit 39d5834eb9
7 changed files with 141 additions and 36 deletions

View File

@ -1,3 +1,4 @@
@tool
class_name BugMarker
extends Node3D
@ -30,6 +31,7 @@ func set_rotation_to_normal(_normal:Vector3) -> void:
func set_info_enabled(_enable:bool):
if __info_collider:
__info_collider.collision_layer = 0xFFFFFFFF if _enable else 0x00000000
enable_info = _enable
func __set_marker_status(_status:BugStatus) -> void:

View File

@ -0,0 +1,16 @@
class_name BugbotBugData
extends Resource
var id : int = -1
var title : String
var body : String
var component : String
var map_name : String
var marker_location : String
var platform : String
var operating_system : String
var is_open : bool
var severity : String
var status : String
var resolution : String
var duplicate_of : int = -1

View File

@ -0,0 +1,6 @@
class_name BugbotErrorData
extends Resource
var code : int = -1
var message : String
var url : String

View File

@ -0,0 +1,6 @@
class_name BugReportPlatform
enum {
BUGZILLA,
GITEA,
JIRA
}

View File

@ -1,5 +1,5 @@
class_name BugbotServerAPI
extends Object
extends Resource
enum BugbotServerError { OK, THREAD_NULL, THREAD_BUSY }
@ -23,6 +23,13 @@ static func _send_form_data() -> int:
return BugbotServerError.OK
static func _create_new_server_api() -> BugbotServerAPI:
match ProjectSettings.get_setting("bugbot/reporting/bug_report_platform", -1):
BugReportPlatform.BUGZILLA: return BugbotServerAPI.new()
BugReportPlatform.GITEA: return BugbotServerGiteaAPI.new()
BugReportPlatform.JIRA: return BugbotServerAPI.new()
return BugbotServerAPI.new()
static func _current_server_api() -> String:
return ""

View File

@ -1,6 +1,16 @@
class_name BugbotServerGiteaAPI
extends "res://addons/Bugbot/Scripts/server_api.gd"
#region Consts
const DEFAULT_SERVER : String = "https://gitea.example.com"
const DEFAULT_BASE_URL : String = "api/v1/"
const DEFAULT_OWNER_NAME : String = "ProjectOwner"
const DEFAULT_REPO_NAME : String = "ProjectName"
const DEFAULT_API_KEY : String = "0123456789abcdef0123456789abcdef01234567"
const DEFAULT_LABEL : String = "Kind/Bug"
const DEFAULT_STATUS : String = "Status/Need More Info"
#endregion
static func _return_list_of_bugs(callback:Callable) -> int:
if not __bugbot_server_thread:
@ -13,16 +23,16 @@ static func _return_list_of_bugs(callback:Callable) -> int:
__bugbot_server_thread.start(__return_list_of_bugs_thread.bind(callback))
return BugbotServerError.OK
#func _prepare_form() -> void:
#static func _prepare_form() -> void:
#print("Prepare ", _current_server_api(), " form here.")
#
#func _send_form_data() -> void:
#static 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 server : String = ProjectSettings.get_setting("bugbot/reporting/gitea/server", DEFAULT_SERVER)
var error : int = http_client.connect_to_host(server, 443)
assert(error == Error.OK)
@ -31,7 +41,7 @@ func __return_list_of_bugs_thread(callback:Callable) -> void:
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",""))
var header_data : Array = _create_header_data("application/json", ProjectSettings.get_setting("bugbot/reporting/gitea/API_key", DEFAULT_API_KEY))
error = http_client.request(HTTPClient.METHOD_GET, api_url, header_data)
assert(error == Error.OK)
@ -49,7 +59,41 @@ func __return_list_of_bugs_thread(callback:Callable) -> void:
response_body = response_body + chunk
response_string = response_body.get_string_from_utf8()
callback.call_deferred(JSON.parse_string(response_string) as Array)
var response_array : Array
var response_data := JSON.parse_string(response_string)
if response_data is Array:
# If the response is an array, we can make the assumption that this is
# a list of returned bugs.
for bug_in:Dictionary in response_data:
var bug : BugbotBugData = BugbotBugData.new()
bug.id = bug_in["id"]
bug.title = bug_in["title"]
bug.body = bug_in["body"]
bug.component = &"Unused"
bug.platform = &"Unused"
bug.operating_system = &"Unused"
bug.is_open = (bug_in["state"] == "open")
bug.severity = "Severity will go here."
bug.status = "Status will go here."
bug.resolution = "Resolution will go here."
bug.duplicate_of = -1
bug.map_name = "Map name will go here."
bug.marker_location = "Marker location will go here."
response_array.append(bug)
elif response_data is Dictionary:
# If the response is a dictionary and not an array, make the assumption
# that this is because the response was an error code.
var error_data : BugbotErrorData = BugbotErrorData.new()
error_data.code = 1
error_data.message = response_data["message"]
error_data.url = response_data["url"]
response_array.append(error_data)
printerr(error_data.message)
callback.call_deferred(response_array)
__bugbot_server_thread.call_deferred("wait_to_finish")
@ -57,18 +101,19 @@ 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") + \
return "/" + \
ProjectSettings.get_setting("bugbot/reporting/gitea/base_URL", DEFAULT_BASE_URL) + \
"/repos/" + \
ProjectSettings.get_setting("bugbot/reporting/gitea/owner_name", DEFAULT_OWNER_NAME) + \
"/" + \
ProjectSettings.get_setting("bugbot/reporting/gitea/repo_name", DEFAULT_REPO_NAME) + \
"/issues"
static func _create_header_data(mime_type:String, api_key:String) -> Array:
return [
var header : Array = [
"User-Agent: Pirulo/1.0 (Godot)",
"Accept: " + mime_type,
"Content-Type: " + mime_type,
"Authorization: token " + api_key,
]
if api_key: header.append("Authorization: token " + api_key)
return header

View File

@ -6,13 +6,9 @@ enum BugbotMenuItems {
HIDE_BUG_MARKERS
}
enum BugReportPlatform {
BUGZILLA,
GITEA,
JIRA
}
var __bugbot_menu_button : BugbotMenuButton
var __bugbot_marker_containers : Dictionary
var __editor_server_api : BugbotServerAPI
func _enter_tree() -> void:
__initialise_project_settings()
@ -45,23 +41,23 @@ func __initialise_project_settings():
__add_project_setting("bugbot/reporting/bug_report_widget_depth", TYPE_INT, 10000)
#region Bugzilla
__add_project_setting("bugbot/reporting/bugzilla/server", TYPE_STRING, "https://gitea.example.com")
__add_project_setting("bugbot/reporting/bugzilla/server", TYPE_STRING, "https://bugzilla.example.com")
__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/API_key", TYPE_STRING, "")
__add_project_setting("bugbot/reporting/bugzilla/default_status", TYPE_STRING, "UNCONFIRMED")
#endregion
#region Gitea
__add_project_setting("bugbot/reporting/gitea/server", TYPE_STRING, "https://127.0.0.1:4433")
__add_project_setting("bugbot/reporting/gitea/base_URL", TYPE_STRING, "api/v1/")
__add_project_setting("bugbot/reporting/gitea/owner_name", TYPE_STRING, "ProjectOwner")
__add_project_setting("bugbot/reporting/gitea/repo_name", TYPE_STRING, "ProjectName")
__add_project_setting("bugbot/reporting/gitea/API_key", TYPE_STRING, "")
__add_project_setting("bugbot/reporting/gitea/default_label", TYPE_STRING, "Kind/Bug")
__add_project_setting("bugbot/reporting/gitea/default_status", TYPE_STRING, "Status/Need More Info")
__add_project_setting("bugbot/reporting/gitea/server", TYPE_STRING, BugbotServerGiteaAPI.DEFAULT_SERVER)
__add_project_setting("bugbot/reporting/gitea/base_URL", TYPE_STRING, BugbotServerGiteaAPI.DEFAULT_BASE_URL)
__add_project_setting("bugbot/reporting/gitea/owner_name", TYPE_STRING, BugbotServerGiteaAPI.DEFAULT_OWNER_NAME)
__add_project_setting("bugbot/reporting/gitea/repo_name", TYPE_STRING, BugbotServerGiteaAPI.DEFAULT_REPO_NAME)
__add_project_setting("bugbot/reporting/gitea/API_key", TYPE_STRING, BugbotServerGiteaAPI.DEFAULT_API_KEY)
__add_project_setting("bugbot/reporting/gitea/default_label", TYPE_STRING, BugbotServerGiteaAPI.DEFAULT_LABEL)
__add_project_setting("bugbot/reporting/gitea/default_status", TYPE_STRING, BugbotServerGiteaAPI.DEFAULT_STATUS)
#endregion
#region Jira
__add_project_setting("bugbot/reporting/jira/server", TYPE_STRING, "https://127.0.0.1:4433")
__add_project_setting("bugbot/reporting/jira/server", TYPE_STRING, "https://jira.example.com")
__add_project_setting("bugbot/reporting/jira/REST_URI", TYPE_STRING, "rest/")
__add_project_setting("bugbot/reporting/jira/project_name", TYPE_STRING, "ProjectName")
__add_project_setting("bugbot/reporting/jira/email", TYPE_STRING, "")
@ -79,15 +75,15 @@ func __initialise_project_settings():
#region Bug Markers
__add_project_setting("bugbot/markers/unresolved/show_unresolved_bugs", TYPE_BOOL, true)
__add_project_setting("bugbot/markers/unresolved/tint", TYPE_COLOR, Color(0.1,0.0,0.0))
__add_project_setting("bugbot/markers/unresolved/unresolved_statuses", TYPE_ARRAY, Array(), PROPERTY_HINT_ARRAY_TYPE, "String")
__add_project_setting("bugbot/markers/unresolved/unresolved_statuses", TYPE_ARRAY, Array(), PROPERTY_HINT_ARRAY_TYPE, &"21/:")
__add_project_setting("bugbot/markers/in_progress/show_in_progress_bugs", TYPE_BOOL, true)
__add_project_setting("bugbot/markers/in_progress/tint", TYPE_COLOR, Color(0.5,0.5,0.0))
__add_project_setting("bugbot/markers/in_progress/in_progress_statuses", TYPE_ARRAY, Array(), PROPERTY_HINT_ARRAY_TYPE, "String")
__add_project_setting("bugbot/markers/in_progress/in_progress_statuses", TYPE_ARRAY, Array(), PROPERTY_HINT_ARRAY_TYPE, &"21/:")
__add_project_setting("bugbot/markers/resolved/show_resolved_bugs", TYPE_BOOL, false)
__add_project_setting("bugbot/markers/resolved/tint", TYPE_COLOR, Color(0.0,1.0,0.0))
__add_project_setting("bugbot/markers/resolved/resolved_statuses", TYPE_ARRAY, Array(), PROPERTY_HINT_ARRAY_TYPE, "String")
__add_project_setting("bugbot/markers/resolved/resolved_statuses", TYPE_ARRAY, Array(), PROPERTY_HINT_ARRAY_TYPE, &"21/:")
#endregion
#region Batch Loading
@ -98,11 +94,38 @@ func __initialise_project_settings():
func __on_bugbot_menu_item_pressed(id:int):
match id:
BugbotMenuItems.SHOW_BUG_MARKERS:
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))
var scene : String = EditorInterface.get_edited_scene_root().scene_file_path
if __bugbot_marker_containers.has(scene):
__bugbot_marker_containers[scene].queue_free()
__editor_server_api = BugbotServerAPI._create_new_server_api()
__editor_server_api._return_list_of_bugs(__show_bug_markers_response)
BugbotMenuItems.HIDE_BUG_MARKERS:
print("Show Bug Markers is not happening. In fact, the opposite of that.")
var marker_container : Node3D = __bugbot_marker_containers[EditorInterface.get_edited_scene_root().scene_file_path]
var markers : Array = marker_container.get_children()
for marker:Node3D in markers:
marker.queue_free()
func __show_bug_markers_response(bug_list:Array):
var scene_path : String = EditorInterface.get_edited_scene_root().scene_file_path
var marker_container : Node3D = __fill_marker_container(EditorInterface.get_edited_scene_root(), bug_list)
__bugbot_marker_containers[scene_path] = marker_container
func __fill_marker_container(scene_root:Node, response_resources:Array) -> Node3D:
var marker_container : Node3D = Node3D.new()
for bugbot_data:Resource in response_resources:
if bugbot_data is BugbotBugData:
var bug_status : BugMarker.BugStatus = BugMarker.BugStatus.NEUTRAL
var data_resource : BugbotBugData = bugbot_data as BugbotBugData
if data_resource.is_open:
bug_status = BugMarker.BugStatus.UNRESOLVED
else:
if ProjectSettings.get_setting("bugbot/markers/resolved/show_resolved_bugs"):
bug_status = BugMarker.BugStatus.RESOLVED
if bug_status == BugMarker.BugStatus.NEUTRAL:
var bug_marker : BugMarker = load("res://addons/Bugbot/Scenes/bug_marker.tscn").instantiate()
marker_container.add_child(bug_marker)
bug_marker.marker_status = bug_status
scene_root.add_child(marker_container)
return marker_container
func __add_project_setting(_setting:String, _type:int, _default_value:Variant, _hint:int = PropertyHint.PROPERTY_HINT_NONE, _hint_string:String = ""):
var setting_info: Dictionary = {