From 40e7a590848e91a7faef4839707a4800e55bbfc8 Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Mon, 10 Jun 2019 15:32:57 +0200 Subject: [PATCH] [GithubIssueBridge] Add support for detect action References #1100 --- bridges/GithubIssueBridge.php | 59 +++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/bridges/GithubIssueBridge.php b/bridges/GithubIssueBridge.php index bbb599bd75a..9a2b7ec17f2 100644 --- a/bridges/GithubIssueBridge.php +++ b/bridges/GithubIssueBridge.php @@ -239,4 +239,63 @@ public function collectData(){ $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, + ); + + } }