Bugbot/bugbot.gd

150 lines
8.1 KiB
GDScript

@tool
extends EditorPlugin
enum BugbotMenuItems {
SHOW_BUG_MARKERS,
HIDE_BUG_MARKERS
}
var __bugbot_menu_button : BugbotMenuButton
var __bugbot_marker_containers : Dictionary
var __editor_server_api : BugbotServerAPI
func _enter_tree() -> void:
__initialise_project_settings()
__bugbot_menu_button = preload("res://addons/Bugbot/bugbot_menu_button.tscn").instantiate() as BugbotMenuButton
add_control_to_container(CustomControlContainer.CONTAINER_SPATIAL_EDITOR_MENU, __bugbot_menu_button)
# Setup popup menu
var bugbot_menu : PopupMenu = __bugbot_menu_button.get_popup()
bugbot_menu.add_item("Show Bug Markers", BugbotMenuItems.SHOW_BUG_MARKERS)
bugbot_menu.add_item("Hide Bug Markers", BugbotMenuItems.HIDE_BUG_MARKERS)
bugbot_menu.id_pressed.connect(__on_bugbot_menu_item_pressed)
func _exit_tree() -> void:
remove_control_from_container(CustomControlContainer.CONTAINER_SPATIAL_EDITOR_MENU, __bugbot_menu_button)
__bugbot_menu_button.queue_free()
# This is where we should remove any visible bug markers
func __initialise_project_settings():
#region Placement
__add_project_setting("bugbot/bug_placement/precise_placement_distance", TYPE_FLOAT, 15.0, PROPERTY_HINT_RANGE, "0.0,100.0,0.1,or_greater")
__add_project_setting("bugbot/bug_placement/arbitrary_placement_distance", TYPE_FLOAT, 2.5, PROPERTY_HINT_RANGE, "0.0,100.0,0.1,or_greater")
#endregion
#region Reporting
__add_project_setting("bugbot/reporting/bug_report_platform", TYPE_INT, BugReportPlatform.BUGZILLA, PROPERTY_HINT_ENUM, "Bugzilla,Gitea,Jira")
__add_project_setting("bugbot/reporting/bug_report_widget_depth", TYPE_INT, 10000)
#region Bugzilla
__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, 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/bug_label", TYPE_STRING, BugbotServerGiteaAPI.DEFAULT_BUG_LABEL)
__add_project_setting("bugbot/reporting/gitea/default_status_label", TYPE_STRING, BugbotServerGiteaAPI.DEFAULT_STATUS_LABEL)
__add_project_setting("bugbot/reporting/gitea/status_labels/unresolved_statuses", TYPE_ARRAY, Array(), PROPERTY_HINT_ARRAY_TYPE, &"21/:")
__add_project_setting("bugbot/reporting/gitea/status_labels/in_progress_statuses", TYPE_ARRAY, Array(), PROPERTY_HINT_ARRAY_TYPE, &"21/:")
__add_project_setting("bugbot/reporting/gitea/status_labels/resolved_statuses", TYPE_ARRAY, Array(), PROPERTY_HINT_ARRAY_TYPE, &"21/:")
__add_project_setting("bugbot/reporting/gitea/status_labels/version_label_prefix", TYPE_STRING, BugbotServerGiteaAPI.DEFAULT_VERSION_LABEL_PREFIX)
__add_project_setting("bugbot/reporting/gitea/status_labels/hardware_label_prefix", TYPE_STRING, BugbotServerGiteaAPI.DEFAULT_HARDWARE_LABEL_PREFIX)
__add_project_setting("bugbot/reporting/gitea/status_labels/os_label_prefix", TYPE_STRING, BugbotServerGiteaAPI.DEFAULT_OS_LABEL_PREFIX)
__add_project_setting("bugbot/reporting/gitea/status_labels/component_label_prefix", TYPE_STRING, BugbotServerGiteaAPI.DEFAULT_COMPONENT_LABEL_PREFIX)
__add_project_setting("bugbot/reporting/gitea/status_labels/priority_label_prefix", TYPE_STRING, BugbotServerGiteaAPI.DEFAULT_PRIORITY_LABEL_PREFIX)
#endregion
#region Jira
__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, "")
__add_project_setting("bugbot/reporting/jira/API_key", TYPE_STRING, "")
__add_project_setting("bugbot/reporting/jira/bug_issue_type", TYPE_STRING, "Bug")
__add_project_setting("bugbot/reporting/jira/map_name_field", TYPE_STRING, "")
__add_project_setting("bugbot/reporting/jira/marker_location_field", TYPE_STRING, "")
__add_project_setting("bugbot/reporting/jira/optional_fields/department_field", TYPE_STRING, "")
__add_project_setting("bugbot/reporting/jira/optional_fields/severity_field", TYPE_STRING, "")
__add_project_setting("bugbot/reporting/jira/optional_fields/platform_field", TYPE_STRING, "")
__add_project_setting("bugbot/reporting/jira/optional_fields/version_field", TYPE_STRING, "")
#endregion
#endregion
#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/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/resolved/show_resolved_bugs", TYPE_BOOL, false)
__add_project_setting("bugbot/markers/resolved/tint", TYPE_COLOR, Color(0.0,1.0,0.0))
#endregion
#region Batch Loading
__add_project_setting("bugbot/markers/display/load_markers_batch", TYPE_INT, 10)
__add_project_setting("bugbot/markers/display/unload_markers_batch", TYPE_INT, 25)
#endregion
func __on_bugbot_menu_item_pressed(id:int):
match id:
BugbotMenuItems.SHOW_BUG_MARKERS:
var scene_root : Node = EditorInterface.get_edited_scene_root()
var scene : String = scene_root.scene_file_path
if not __bugbot_marker_containers.has(scene):
var marker_container : Node3D = Node3D.new()
marker_container.name = "BugMarkerContainer"
__bugbot_marker_containers[scene] = marker_container
scene_root.add_child(marker_container)
__editor_server_api = BugbotServerAPI._create_new_server_api()
__editor_server_api._return_list_of_bugs(__show_bug_markers_response)
BugbotMenuItems.HIDE_BUG_MARKERS:
var scene_root : Node = EditorInterface.get_edited_scene_root()
var scene_path : String = scene_root.scene_file_path
if __bugbot_marker_containers.has(scene_path):
var marker_container : Node3D = __bugbot_marker_containers[scene_path]
BugbotServerAPI._hide_markers(marker_container)
func __show_bug_markers_response(bug_list:Array) -> void:
var scene_root : Node = EditorInterface.get_edited_scene_root()
var marker_container : Node3D = __bugbot_marker_containers[scene_root.scene_file_path]
for bugbot_data:Resource in bug_list:
if bugbot_data is BugbotBugData:
var bug_status : BugMarker.BugStatus = BugMarker.BugStatus.NEUTRAL
var bug_data : BugbotBugData = bugbot_data as BugbotBugData
if bug_data.resolution == BugbotServerGiteaAPI.RESOLVED_TAG:
bug_status = BugMarker.BugStatus.RESOLVED
elif bug_data.resolution == BugbotServerGiteaAPI.IN_PROGRESS_TAG:
bug_status = BugMarker.BugStatus.IN_PROGRESS
elif bug_data.resolution == BugbotServerGiteaAPI.UNRESOLVED_TAG:
bug_status = BugMarker.BugStatus.UNRESOLVED
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
bug_marker.bug_data = bugbot_data
func __add_project_setting(_setting:String, _type:int, _default_value:Variant, _hint:int = PropertyHint.PROPERTY_HINT_NONE, _hint_string:String = ""):
var setting_info: Dictionary = {
"name": _setting,
"type": _type,
"hint": _hint,
"hint_string": _hint_string
}
if not ProjectSettings.has_setting(_setting):
ProjectSettings.set_setting(_setting, _default_value)
ProjectSettings.add_property_info(setting_info)
ProjectSettings.set_initial_value(_setting, _default_value)