From 5a9519967b0bb6b16e43e495c63d13c6fb41c021 Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Sat, 8 Jun 2019 17:01:38 +0200 Subject: [PATCH] [Exceptions] Add button to search for similar issues on GitHub Users currently only get one option: to open a new issue on GitHub. This can, however, result in duplicate issues, which is not desired. This commit adds a second button to the error message, which links to the GitHub issues tracker with the search query set to find errors for the current bridge. That way, users can collaborate on the same issue. --- lib/Exceptions.php | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/Exceptions.php b/lib/Exceptions.php index 112580de..c749780c 100644 --- a/lib/Exceptions.php +++ b/lib/Exceptions.php @@ -11,6 +11,15 @@ * @link https://github.com/rss-bridge/rss-bridge */ +/** + * Builds a GitHub search query to find open bugs for the current bridge + */ +function buildGitHubSearchQuery($bridgeName){ + return REPOSITORY + . 'issues?q=' + . urlencode('is:issue is:open ' . $bridgeName); +} + /** * Returns an URL that automatically populates a new issue on GitHub based * on the information provided @@ -84,6 +93,7 @@ function buildBridgeException($e, $bridge){ $body_html = nl2br($body); $link = buildGitHubIssueQuery($title, $body, 'Bridge-Broken', $bridge->getMaintainer()); + $searchQuery = buildGitHubSearchQuery($bridge::NAME); $header = buildHeader($e, $bridge); $message = << {$body_html} EOD; - $section = buildSection($e, $bridge, $message, $link); + $section = buildSection($e, $bridge, $message, $link, $searchQuery); return $section; } @@ -120,10 +130,11 @@ function buildTransformException($e, $bridge){ . '`'; $link = buildGitHubIssueQuery($title, $body, 'Bridge-Broken', $bridge->getMaintainer()); + $searchQuery = buildGitHubSearchQuery($bridge::NAME); $header = buildHeader($e, $bridge); $message = "RSS-Bridge was unable to transform the contents returned by {$bridge->getName()}!"; - $section = buildSection($e, $bridge, $message, $link); + $section = buildSection($e, $bridge, $message, $link, $searchQuery); return buildPage($title, $header, $section); } @@ -154,11 +165,12 @@ EOD; * @param object $bridge The bridge object * @param string $message The message to display * @param string $link The link to include in the anchor + * @param string $searchQuery A GitHub search query for the current bridge * @return string The HTML section * * @todo This function belongs inside a class */ -function buildSection($e, $bridge, $message, $link){ +function buildSection($e, $bridge, $message, $link, $searchQuery){ return <<

{$message}

@@ -166,9 +178,13 @@ function buildSection($e, $bridge, $message, $link){
  • Press Return to check your input parameters
  • Press F5 to retry
  • +
  • Check if this issue was already reported on GitHub (give it a thumbs-up)
  • Open a GitHub Issue if this error persists
+ + +

{$bridge->getMaintainer()}