44 lines
1.1 KiB
PHP
44 lines
1.1 KiB
PHP
<?php
|
|
// azure/AzureDevOpsService.php
|
|
|
|
require_once __DIR__ . '/config.php';
|
|
|
|
class AzureDevOpsService {
|
|
private $config;
|
|
|
|
public function __construct() {
|
|
$this->config = getAzureDevOpsConfig();
|
|
}
|
|
|
|
private function sendRequest($url) {
|
|
$ch = curl_init();
|
|
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
|
|
|
|
$headers = [
|
|
'Authorization: Basic ' . base64_encode(':' . $this->config['pat']),
|
|
'Content-Type: application/json',
|
|
];
|
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
|
|
|
$result = curl_exec($ch);
|
|
if (curl_errno($ch)) {
|
|
// Handle cURL error
|
|
http_response_code(500);
|
|
echo json_encode(['error' => 'cURL Error: ' . curl_error($ch)]);
|
|
exit;
|
|
}
|
|
curl_close($ch);
|
|
|
|
return json_decode($result, true);
|
|
}
|
|
|
|
public function getProjects() {
|
|
$url = $this->config['apiUrl'] . '/_apis/projects?api-version=6.0';
|
|
return $this->sendRequest($url);
|
|
}
|
|
}
|