Skip to content

Commit

Permalink
[GithubIssueBridge] Add support for detect action
Browse files Browse the repository at this point in the history
References RSS-Bridge#1100
  • Loading branch information
logmanoriginal committed Jun 10, 2019
1 parent 27a4cc2 commit 40e7a59
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions bridges/GithubIssueBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,63 @@ public function collectData(){
$item['title'] = preg_replace('/\s+/', ' ', $item['title']);
});
}

public function detectParameters($url) {

$help = <<<EOD
Usage:
For project issues the URL must include /<user>/<project>
For issue comments the URL must include /<user>/<project>/issues/<issue-number>
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,
);

}
}

0 comments on commit 40e7a59

Please sign in to comment.