Build fix after r198234.
[WebKit-https.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');
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         $commits = $fetcher->fetch_last_reported($repository_id);
36     } else if (ctype_alnum($filter)) {
37         $commits = $fetcher->fetch_revision($repository_id, $filter);
38     } else {
39         $matches = array();
40         if (!preg_match('/([A-Za-z0-9]+)[\:\-]([A-Za-z0-9]+)/', $filter, $matches))
41             exit_with_error('UnknownFilter', array('repositoryName' => $repository_name, 'filter' => $filter));
42         $commits = $fetcher->fetch_between($repository_id, $matches[1], $matches[2]);
43     }
44
45     if (!is_array($commits))
46         exit_with_error('FailedToFetchCommits', array('repository' => $repository_id, 'filter' => $filter));
47
48     exit_with_success(array('commits' => $commits));
49 }
50
51 main(array_key_exists('PATH_INFO', $_SERVER) ? explode('/', trim($_SERVER['PATH_INFO'], '/')) : array());
52
53 ?>