diff --git a/bridges/GithubIssueBridge.php b/bridges/GithubIssueBridge.php index bbb599bd..9a2b7ec1 100644 --- a/bridges/GithubIssueBridge.php +++ b/bridges/GithubIssueBridge.php @@ -239,4 +239,63 @@ class GithubIssueBridge extends BridgeAbstract { $item['title'] = preg_replace('/\s+/', ' ', $item['title']); }); } + + public function detectParameters($url) { + + $help = <</ +For issue comments the URL must include ///issues/ + +Examples: +- https://github.com/rss-bridge/rss-bridge +- https://github.com/rss-bridge/rss-bridge/issues/1 + +Issue comments for project issues are enabled if the URL points to issues +https://github.com/rss-bridge/rss-bridge/issues +EOD; + + if(filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED) === false + || strpos($url, self::URI) !== 0) { + returnClientError('Invalid URL' . $help); + return null; + } + + $url_components = parse_url($url); + $path_segments = array_values(array_filter(explode('/', $url_components['path']))); + + switch(count($path_segments)) { + case 2: { // Project issues + list($user, $project) = $path_segments; + $show_comments = 'off'; + } break; + case 3: { // Project issues with issue comments + if($path_segments[2] !== 'issues') { + returnClientError('Invalid path. Expected "/issues/", found "/' + . $path_segments[2] + . '/"' + . $help + ); + } + list($user, $project) = $path_segments; + $show_comments = 'on'; + } break; + case 4: { // Issue comments + list($user, $project, /* issues */, $issue) = $path_segments; + } break; + default: { + returnClientError('Invalid path.' . $help); + } + } + + return array( + 'u' => $user, + 'p' => $project, + 'c' => isset($show_comments) ? $show_comments : null, + 'i' => isset($issue) ? $issue : null, + ); + + } }