Skip to content

Commit

Permalink
In-Game github Issue Reporter (#491)
Browse files Browse the repository at this point in the history
* In-Game github Issue Reporter

* fuck

* You can now ban people from bug reports
And it checks the interview control flag

* Issue reports are now logged

* Removes dev config from gitignore

* Clarified developer configuration
  • Loading branch information
francinum authored Aug 20, 2023
1 parent b164130 commit e562fdf
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 40 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,6 @@ libprof.so
#Ignore everything but the example config in the media jsons directory, For easy testing.
/config/media/jsons/*
!/config/media/jsons/__EXAMPLE.json

#This file contains developer-specific config overrides. These shouldn't be committed.
config/_config_nogit.txt
8 changes: 8 additions & 0 deletions code/controllers/configuration/entries/comms.dm
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
/datum/config_entry/string/comms_key
protection = CONFIG_ENTRY_HIDDEN

//API key for Github Issues.
/datum/config_entry/string/issue_key
protection = CONFIG_ENTRY_HIDDEN

//Endpoint for Github Issues, the `owner/repo` part.
/datum/config_entry/string/issue_slug
protection = CONFIG_ENTRY_LOCKED

/datum/config_entry/string/comms_key/ValidateAndSet(str_val)
return str_val != "default_pwd" && length(str_val) > 6 && ..()

Expand Down
2 changes: 1 addition & 1 deletion code/modules/admin/sql_ban_system.dm
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@
break_counter = 0

var/list/other_job_lists = list(
"Abstract" = list("Appearance", "Emote", "Deadchat", "OOC", "Urgent Adminhelp"),
"Abstract" = list("Appearance", "Emote", "Deadchat", "OOC", "Urgent Adminhelp", "Bug Report"),
)
for(var/department in other_job_lists)
output += "<div class='column'><label class='rolegroup [ckey(department)]'>[tgui_fancy ? "<input type='checkbox' name='[department]' class='hidden' onClick='header_click_all_checkboxes(this)'>" : ""][department]</label><div class='content'>"
Expand Down
6 changes: 6 additions & 0 deletions config/comms.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
## Must be set to something other than 'default_pwd' and at least 7 characters long to be valid.
#COMMS_KEY default_pwd

## Github Fine-Grained API Key with AT LEAST `issue.write` scope for the target repository.
#ISSUE_KEY github_pat_EXAMPLE

##Github API 'slug' for issue reporting, format owner/repo
ISSUE_SLUG daedalusdock/daedalusdock

## World address and port for server receiving cross server messages
## Use '+' to denote spaces in ServerName
## Repeat this entry to add more servers
Expand Down
4 changes: 4 additions & 0 deletions config/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -627,3 +627,7 @@ PR_ANNOUNCEMENTS_PER_ROUND 5

## Uncomment to block granting profiling privileges to users with R_DEBUG, for performance purposes
#FORBID_ADMIN_PROFILING

#Included last to allow developers have stable test configs
#this file is gitignored.
$include _config_nogit.txt
128 changes: 89 additions & 39 deletions interface/interface.dm
Original file line number Diff line number Diff line change
Expand Up @@ -58,45 +58,95 @@
set desc = "Report an issue"
set hidden = TRUE
var/githuburl = CONFIG_GET(string/githuburl)
if(githuburl)
var/message = "This will open the Github issue reporter in your browser. Are you sure?"
if(GLOB.revdata.testmerge.len)
message += "<br>The following experimental changes are active and are probably the cause of any new or sudden issues you may experience. If possible, please try to find a specific thread for your issue instead of posting to the general issue tracker:<br>"
message += GLOB.revdata.GetTestMergeInfo(FALSE)
// We still use tgalert here because some people were concerned that if someone wanted to report that tgui wasn't working
// then the report issue button being tgui-based would be problematic.
if(tgalert(src, message, "Report Issue","Yes","No")!="Yes")
return

// Keep a static version of the template to avoid reading file
var/static/issue_template = file2text(".github/ISSUE_TEMPLATE/bug_report.md")

// Get a local copy of the template for modification
var/local_template = issue_template

// Remove comment header
var/content_start = findtext(local_template, "<")
if(content_start)
local_template = copytext(local_template, content_start)

// Insert round
if(GLOB.round_id)
local_template = replacetext(local_template, "## Round ID:\n", "## Round ID:\n[GLOB.round_id]")

// Insert testmerges
if(GLOB.revdata.testmerge.len)
var/list/all_tms = list()
for(var/entry in GLOB.revdata.testmerge)
var/datum/tgs_revision_information/test_merge/tm = entry
all_tms += "- \[[tm.title]\]([githuburl]/pull/[tm.number])"
var/all_tms_joined = all_tms.Join("\n") // for some reason this can't go in the []
local_template = replacetext(local_template, "## Testmerges:\n", "## Testmerges:\n[all_tms_joined]")

var/url_params = "Reporting client version: [byond_version].[byond_build]\n\n[local_template]"
DIRECT_OUTPUT(src, link("[githuburl]/issues/new?body=[url_encode(url_params)]"))
else
to_chat(src, span_danger("The Github URL is not set in the server configuration."))
return
var/issue_key = CONFIG_GET(string/issue_key)
if(!issue_key)
to_chat(src, span_danger("Issue Reporting is not properly configured."))
return
//Are we pre-interview or otherwise not allowed to do this?
if(restricted_mode || is_banned_from(ckey, "Bug Report"))
to_chat(src, span_warning("You are not currently allowed to make a bug report through this system."))
return
var/message = "This will start reporting an issue, gathering some information from the server and your client, before submitting it to github."
if(GLOB.revdata.testmerge.len)
message += "<br>The following experimental changes are active and may be the cause of any new or sudden issues:<br>"
message += GLOB.revdata.GetTestMergeInfo(FALSE)
// We still use tgalert here because some people were concerned that if someone wanted to report that tgui wasn't working
// then the report issue button being tgui-based would be problematic.
if(tgalert(src, message, "Report Issue","Yes","No")!="Yes")
return

// Keep a static version of the template to avoid reading file
var/static/issue_template = file2text(".github/ISSUE_TEMPLATE/bug_report.md")

// Get a local copy of the template for modification
var/local_template = issue_template

// Remove comment header
var/content_start = findtext(local_template, "<")
if(content_start)
local_template = copytext(local_template, content_start)

// Insert round
if(GLOB.round_id)
local_template = replacetext(local_template, "## Round ID:\n", "## Round ID:\n[GLOB.round_id]")

// Insert testmerges
if(GLOB.revdata.testmerge.len)
var/list/all_tms = list()
for(var/entry in GLOB.revdata.testmerge)
var/datum/tgs_revision_information/test_merge/tm = entry
all_tms += "- \[[tm.title]\]([githuburl]/pull/[tm.number])"
var/all_tms_joined = all_tms.Join("\n") // for some reason this can't go in the []
local_template = replacetext(local_template, "## Testmerges:\n", "## Testmerges:\n[all_tms_joined]")

//Collect client info:
var/issue_title = input(src, "Please give the issue a title:","Issue Title") as text|null
if(!issue_title)
return //Consider it aborted
var/user_description = input(src, "Please describe the issue you are reporting:","Issue Body") as message|null
if(!user_description)
return

local_template = replacetext(local_template, "## Reproduction:\n", "## Reproduction:\n[user_description]")

var/client_info = "\
Client Information:\n\
BYOND:[byond_version].[byond_build]\n\
Key:[ckey]\n\
\
"
var/issue_body = "Reporting client info: [client_info]\n\n[local_template]"
var/list/body_structure = list(
"title" = issue_title,
"body" = issue_body
)
var/datum/http_request/issue_report = new
rustg_file_write(issue_body, "[GLOB.log_directory]/issue_reports/[ckey]-[world.time]-[SANITIZE_FILENAME(issue_title)].txt")
message_admins("BUGREPORT: Bug report filed by [ADMIN_LOOKUPFLW(src)], Title: [strip_html(issue_title)]")
issue_report.prepare(
RUSTG_HTTP_METHOD_POST,
"https://api.github.com/repos/[CONFIG_GET(string/issue_slug)]/issues",
json_encode(body_structure), //this is slow slow slow but no other options buckaroo
list(
"Accept"="application/vnd.github+json",
"Authorization"="Bearer [issue_key]",
"X-GitHub-Api-Version"="2022-11-28"
)
)
to_chat(src, span_notice("Sending issue report..."))
SEND_SOUND(src, 'sound/misc/compiler-stage1.ogg')
issue_report.begin_async()
UNTIL(issue_report.is_complete() || !src) //Client fuckery.
var/datum/http_response/issue_response = issue_report.into_response()
if(issue_response.errored || issue_response.status_code != 201)
SEND_SOUND(src, 'sound/misc/compiler-failure.ogg')
to_chat(src, "[span_alertwarning("Bug report FAILED!")]\n\
[span_warning("Please adminhelp immediately!")]\n\
[span_notice("Code:[issue_response.status_code || "9001 CATASTROPHIC ERROR"]")]")

return
SEND_SOUND(src, 'sound/misc/compiler-stage2.ogg')
to_chat(src, span_notice("Bug submitted successfully."))

/client/verb/changelog()
set name = "Changelog"
Expand Down

0 comments on commit e562fdf

Please sign in to comment.