Rewrite 'pull-os-versions' script in Javascript to add support for reporting os revis...
[WebKit.git] / Websites / perf.webkit.org / public / api / commits.php
1 <?php
2
3 require_once('../include/json-header.php');
4 require_once('../include/commit-log-fetcher.php');
5
6 function main($paths) {
7     if (count($paths) < 1 || count($paths) > 2)
8         exit_with_error('InvalidRequest');
9
10     $db = new Database;
11     if (!$db->connect())
12         exit_with_error('DatabaseConnectionFailure');
13
14     $fetcher = new CommitLogFetcher($db);
15
16     if (!is_numeric($paths[0])) {
17         $repository_id = $fetcher->repository_id_from_name($paths[0]);
18         if (!$repository_id)
19             exit_with_error('RepositoryNotFound', array('repositoryName' => $paths[0]));
20     } else
21         $repository_id = intval($paths[0]);
22
23     $filter = array_get($paths, 1);
24     $commits = array();
25     if (!$filter) {
26         $keyword = array_get($_GET, 'keyword'); // V2 UI compatibility.
27         $from = array_get($_GET, 'from');
28         $to = array_get($_GET, 'to');
29         $commits = $fetcher->fetch_between($repository_id, $from, $to, $keyword);
30     } else if ($filter == 'oldest') {
31         $commits = $fetcher->fetch_oldest($repository_id);
32     } else if ($filter == 'latest') {
33         $commits = $fetcher->fetch_latest($repository_id);
34     } else if ($filter == 'last-reported') {
35         $from = array_get($_GET, 'from');
36         $to = array_get($_GET, 'to');
37         if ($from && $to)
38             $commits = $fetcher->fetch_last_reported_between_orders($repository_id, $from, $to);
39         else
40             $commits = $fetcher->fetch_last_reported($repository_id);
41     } else if (ctype_alnum($filter)) {
42         $commits = $fetcher->fetch_revision($repository_id, $filter);
43     } else { // V2 UI compatibility.
44         $matches = array();
45         if (!preg_match('/([A-Za-z0-9]+)[\:\-]([A-Za-z0-9]+)/', $filter, $matches))
46             exit_with_error('UnknownFilter', array('repositoryName' => $repository_name, 'filter' => $filter));
47         $commits = $fetcher->fetch_between($repository_id, $matches[1], $matches[2]);
48     }
49
50     if (!is_array($commits))
51         exit_with_error('FailedToFetchCommits', array('repository' => $repository_id, 'filter' => $filter));
52
53     exit_with_success(array('commits' => $commits));
54 }
55
56 main(array_key_exists('PATH_INFO', $_SERVER) ? explode('/', trim($_SERVER['PATH_INFO'], '/')) : array());
57
58 ?>