blob: 64d369bedaf58f632658af1ca32b87afd3b62edf [file] [log] [blame]
<?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
*******************************************************************************/
$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,
git varchar(255) not null primary key,
gerrit varchar(255),
http varchar(255),
github varchar(255),
description varchar(1024)
)";
echo preg_replace('/\s/', ' ', $sql);
}
function captureRepository($repository) {
$name = getName($repository);
$git = "git://git.eclipse.org$repository";
$gerrit = getGerritLink($repository);
$http = getHttpLink($repository);
$github = "https://github.com/eclipse/$name";
$description = addslashes(getDescription($repository));
echo "insert ignore into repositories (name, git) values('$name', '$git');\n";
echo "update repositories set name='$name' git='$git' gerrit='$gerrit' http='$http' github='$github' $description='$description' where repo='$git');\n";
}
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 getHttpLink($path) {
preg_match('/\/gitroot\/(.+)/', $path, $matches);
$partial = $matches[1];
return "http://git.eclipse.org/c/$partial";
}
function getGerritLink($path) {
preg_match('/\/gitroot\/(.+)/', $path, $matches);
$partial = $matches[1];
$gerrit = "https://git.eclipse.org/r/p/$partial";
return isValidUrl($gerrit) ? $gerrit : '';
}
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.
?>