blob: 369fd00b14d2270ead105f96c1ffb4194ed45dc5 [file] [log] [blame]
<?php
/*******************************************************************************
* Copyright (c) 2016 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
*******************************************************************************/
/*
* Export information about a project. This exists primarily to
* feed data into slack.
*
* The script assumes that it is being invoked via GET.
*/
require_once(dirname(__FILE__) . "/../../eclipse.org-common/system/app.class.php");
$App = new App();
require_once(dirname(__FILE__) . "/../classes/common.php");
require_once(dirname(__FILE__) . "/../classes/debug.php");
function getProjectBaseUrl($id) {
// FIXME Use the Forge class.
if (preg_match('/^polarsys\.(.+)$/', $id, $matches)) {
return 'https://www.polarsys.org/projects/' . $matches[1];
} else {
return 'https://projects.eclipse.org/projects/' . $id;
}
}
if (!$id = $_SERVER['REQUEST_METHOD'] == 'GET' ? @$_GET['text'] : @$_POST['text']) {
$data = array(
'response_type' => 'ephemeral',
'text' => "Specify either the full id (e.g. technology.egit) or short name (e.g. egit) of a project." . join("\n", $_GET)
);
header('Content-Type: application/json');
echo json_encode($data);
exit;
}
$id = $App->sqlSanitize($id);
// FIXME Use the Forge class.
$sql = "
select
project_id as id, name
from projects
where is_active
and (project_id like '%$id%' or name like '%$id%')
and project_id not in ('polarsys')
limit 10";
$result = $App->eclipse_sql($sql);
$projects = array();
while ($row=mysql_fetch_assoc($result)) {
$id = $row['id'];
$name = $row['name'];
$url = getProjectBaseUrl($id);
$ipzilla = "https://dev.eclipse.org/ipzilla/buglist.cgi?component=$id";
$projects[] = "$name [<$url|overview>|<$url/downloads|downloads>|<$url/who|who>|<$ipzilla|cqs>]";
}
if (!$projects) {
$data = array(
'response_type' => 'ephemeral',
'text' => "No projects found."
);
header('Content-Type: application/json');
echo json_encode($data);
exit;
}
$data = array(
'response_type' => 'ephemeral',
'text' => join("\n", $projects)
);
header('Content-Type: application/json');
echo json_encode($data);
?>