| <?php |
| /******************************************************************************* |
| * Copyright (c) 2010, 2012 Eclipse Foundation and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Wayne Beaton (Eclipse Foundation)- initial API and implementation |
| *******************************************************************************/ |
| require_once dirname(__FILE__) . '/common/common-functions.inc'; |
| |
| $path = '/gitroot/tycho'; |
| //$path = '/home/wayne/git/www'; |
| |
| scanForRepositories($path); |
| |
| function scanForRepositories($path) { |
| createTables(); |
| $find="find $path -type d -name *.git | xargs -I '{}' git --git-dir={} rev-parse --git-dir 2> /dev/null"; |
| $handle = popen($find, 'r'); |
| while ($repository = fgets($handle)) { |
| captureRepository(trim($repository)); |
| } |
| pclose($handle); |
| } |
| |
| function createTables() { |
| $sql = "create table if not exists repositories ( |
| name varchar(100) not null, |
| path varchar(255) not null primary key, |
| git varchar(255), |
| gerrit varchar(255), |
| http varchar(255), |
| github varchar(255), |
| description varchar(1024) |
| );"; |
| dashboard_sql(preg_replace('/\s/', ' ', $sql)); |
| } |
| |
| function captureRepository($repository) { |
| $name = mysql_real_escape_string(getName($repository)); |
| $git = mysql_real_escape_string("git://git.eclipse.org$repository"); |
| $gerrit = mysql_real_escape_string(getGerritUrl($repository)); |
| $http = mysql_real_escape_string(getHttpUrl($repository)); |
| $github = mysql_real_escape_string(getGitHubUrl($repository)); |
| $description = mysql_real_escape_string(getDescription($repository)); |
| |
| dashboard_sql("insert ignore into repositories (name, path) values('$name', '$repository')"); |
| dashboard_sql("update repositories set name='$name', git='$git', gerrit='$gerrit', http='$http', github='$github', description='$description' where path='$repository'"); |
| } |
| |
| function getName($path) { |
| if (preg_match('/org\.eclipse\.(.*)\.git$/', $path, $matches)) { |
| return $matches[1]; |
| } else if (preg_match('/org\.eclipse\.(.*)$/', $path, $matches)) { |
| return $matches[1]; |
| } else if (preg_match('/([^\/]*)\.git$/', $path, $matches)) { |
| return $matches[1]; |
| } else if (preg_match('/([^\/]*)$/', $path, $matches)) { |
| return $matches[1]; |
| } else { |
| return $this->path; |
| } |
| } |
| |
| function getHttpUrl($path) { |
| preg_match('/\/gitroot\/(.+)/', $path, $matches); |
| $partial = $matches[1]; |
| return "http://git.eclipse.org/c/$partial"; |
| } |
| |
| function getGerritUrl($path) { |
| preg_match('/\/gitroot\/(.+)/', $path, $matches); |
| $partial = $matches[1]; |
| $gerrit = "https://git.eclipse.org/r/p/$partial"; |
| return isValidUrl($gerrit) ? $gerrit : ''; |
| } |
| |
| function getGitHubUrl($path) { |
| $url = "https://github.com/eclipse/" . getName($path); |
| return isValidUrl($url) ? $url : ''; |
| } |
| |
| function getDescription($path) { |
| return @file_get_contents("$path/description"); |
| } |
| |
| function isValidUrl($url) { |
| foreach(get_headers($url) as $header) { |
| if (preg_match('/^HTTP.*(\d)\d\d/', $header, $matches)) { |
| // We are happy with 200 or 300 codes. |
| return $matches[1] == '2' || $matches[1] == '3'; |
| } |
| } |
| return false; |
| } |
| |
| // Pull in a list of repostories |
| |
| // For each... |
| |
| // Grab the description file, remember the contents. |
| |
| // Build the probable Gerrit URL, test. If not 404, remember. |
| |
| // Build the probable GitHub URL, test. If not 404, remember. |
| |
| |
| ?> |