blob: 2d7f25c3706bbe2df9bf4c0fc8c9fd0786b8d538 [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/Project.class.php");
require_once(dirname(__FILE__) . "/../classes/database.inc");
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;
}
// FIXME Use the Forge class.
$sql = "
select
ProjectID as id, Name as name
from Projects
where IsActive
and (ProjectID like '%:id%' or Name like '%:id%')
and ProjectID not in ('polarsys')
limit 10";
$projects = array();
query('foundation', $sql, array(':id' => $id), function($row) use (&$projects) {
$id = $row['id'];
if ($project = Project::getProject($id)) {
$name = $project->getFormalName();
$url = $project->getUrl();
$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);
?>