[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.
This commit is contained in:
logmanoriginal 2019-06-08 17:01:38 +02:00
parent 17f587fcbe
commit 5a9519967b

View file

@ -11,6 +11,15 @@
* @link https://github.com/rss-bridge/rss-bridge * @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 * Returns an URL that automatically populates a new issue on GitHub based
* on the information provided * on the information provided
@ -84,6 +93,7 @@ function buildBridgeException($e, $bridge){
$body_html = nl2br($body); $body_html = nl2br($body);
$link = buildGitHubIssueQuery($title, $body, 'Bridge-Broken', $bridge->getMaintainer()); $link = buildGitHubIssueQuery($title, $body, 'Bridge-Broken', $bridge->getMaintainer());
$searchQuery = buildGitHubSearchQuery($bridge::NAME);
$header = buildHeader($e, $bridge); $header = buildHeader($e, $bridge);
$message = <<<EOD $message = <<<EOD
@ -91,7 +101,7 @@ function buildBridgeException($e, $bridge){
remote website's content!<br> remote website's content!<br>
{$body_html} {$body_html}
EOD; EOD;
$section = buildSection($e, $bridge, $message, $link); $section = buildSection($e, $bridge, $message, $link, $searchQuery);
return $section; return $section;
} }
@ -120,10 +130,11 @@ function buildTransformException($e, $bridge){
. '`'; . '`';
$link = buildGitHubIssueQuery($title, $body, 'Bridge-Broken', $bridge->getMaintainer()); $link = buildGitHubIssueQuery($title, $body, 'Bridge-Broken', $bridge->getMaintainer());
$searchQuery = buildGitHubSearchQuery($bridge::NAME);
$header = buildHeader($e, $bridge); $header = buildHeader($e, $bridge);
$message = "RSS-Bridge was unable to transform the contents returned by $message = "RSS-Bridge was unable to transform the contents returned by
<strong>{$bridge->getName()}</strong>!"; <strong>{$bridge->getName()}</strong>!";
$section = buildSection($e, $bridge, $message, $link); $section = buildSection($e, $bridge, $message, $link, $searchQuery);
return buildPage($title, $header, $section); return buildPage($title, $header, $section);
} }
@ -154,11 +165,12 @@ EOD;
* @param object $bridge The bridge object * @param object $bridge The bridge object
* @param string $message The message to display * @param string $message The message to display
* @param string $link The link to include in the anchor * @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 * @return string The HTML section
* *
* @todo This function belongs inside a class * @todo This function belongs inside a class
*/ */
function buildSection($e, $bridge, $message, $link){ function buildSection($e, $bridge, $message, $link, $searchQuery){
return <<<EOD return <<<EOD
<section> <section>
<p class="exception-message">{$message}</p> <p class="exception-message">{$message}</p>
@ -166,9 +178,13 @@ function buildSection($e, $bridge, $message, $link){
<ul class="advice"> <ul class="advice">
<li>Press Return to check your input parameters</li> <li>Press Return to check your input parameters</li>
<li>Press F5 to retry</li> <li>Press F5 to retry</li>
<li>Check if this issue was already reported on <a href="{$searchQuery}">GitHub</a> (give it a thumbs-up)</li>
<li>Open a <a href="{$link}">GitHub Issue</a> if this error persists</li> <li>Open a <a href="{$link}">GitHub Issue</a> if this error persists</li>
</ul> </ul>
</div> </div>
<a href="{$searchQuery}" title="Opens GitHub to search for similar issues">
<button>Search GitHub Issues</button>
</a>
<a href="{$link}" title="After clicking this button you can review <a href="{$link}" title="After clicking this button you can review
the issue before submitting it"><button>Open GitHub Issue</button></a> the issue before submitting it"><button>Open GitHub Issue</button></a>
<p class="maintainer">{$bridge->getMaintainer()}</p> <p class="maintainer">{$bridge->getMaintainer()}</p>