diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 02725a2..5876aab 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -265,6 +265,22 @@ $routes->match(['get','post'],'/invtrans/edit/(:any)', 'InvTrans::edit/$1'); $routes->match(['get','post'],'/invtrans/user/(:any)', 'InvTrans::index_user/$1'); $routes->match(['get','post'],'/invtrans/reportusage/', 'InvTrans::reportusage/$1'); +// Khusus Untuk Gitea +$routes->get('/gitea', 'Gitea::index'); +$routes->group('api/gitea', function($routes) { + // Mendapatkan detail user + $routes->get('getuser/(:segment)', 'Gitea::getUser/$1'); + + // Mendapatkan daftar repositori milik user + $routes->get('getrepos/(:segment)', 'Gitea::getRepositories/$1'); + + // Mendapatkan daftar branch dari sebuah repositori + $routes->get('getbranches/(:segment)/(:segment)', 'Gitea::getBranches/$1/$2'); + + // Mendapatkan daftar commit dari sebuah repositori + $routes->get('getcommits/(:segment)/(:segment)', 'Gitea::getCommits/$1/$2'); +}); + //LQMS /* $routes->match(['get','post'],'/lqms', 'Lqms::index'); diff --git a/app/Controllers/Gitea.php b/app/Controllers/Gitea.php new file mode 100644 index 0000000..dc1ce8a --- /dev/null +++ b/app/Controllers/Gitea.php @@ -0,0 +1,136 @@ +baseUrl . $endpoint; + + $client = \Config\Services::curlrequest(); + + try { + $response = $client->request('GET', $url, [ + 'headers' => [ + 'Authorization' => "token {$token}", + 'Accept' => 'application/json', + ], + 'http_errors' => false, + ]); + + if ($response->getStatusCode() !== 200) { + // Return array dengan format error yang standar + return [ + 'success' => false, + 'message' => "Gagal mengambil data dari API. Status: " . $response->getStatusCode(), + 'data' => null + ]; + } + + // Return sukses dengan data yang sudah di-decode + return [ + 'success' => true, + 'message' => 'Data berhasil diambil', + 'data' => json_decode($response->getBody(), true) + ]; + + } catch (\Exception $e) { + return [ + 'success' => false, + 'message' => "Terjadi kesalahan cURL: " . $e->getMessage(), + 'data' => null + ]; + } + } + + /** + * Mengambil daftar Commits + * Contoh penggunaan di routes: /gitea/commits/mikael-zakaria/cobazaka + */ + // public function getCommits(string $owner, string $repo) + // { + // // Tangkap parameter branch jika ada (misal: ?sha=main) + // $branch = $this->request->getGet('sha'); + + // $endpoint = "/repos/{$owner}/{$repo}/commits"; + // if (!empty($branch)) { + // $endpoint .= "?sha=" . urlencode($branch); + // } + + // $result = $this->fetchFromGitea($endpoint); + // return $this->response->setJSON($result); + // } + public function getCommits(string $owner, string $repo) + { + // Tangkap parameter query string dari JavaScript + $branch = $this->request->getGet('sha'); + + // Atur default limit, misalnya 50 (maksimal biasanya tergantung setingan admin Gitea, umumnya 50-100) + $limit = $this->request->getGet('limit') ?? 50; + $page = $this->request->getGet('page') ?? 1; + + // Susun parameter API + $queryParams = [ + 'limit' => $limit, + 'page' => $page + ]; + + // Jika branch dipilih, tambahkan ke parameter + if (!empty($branch)) { + $queryParams['sha'] = $branch; + } + + // Gabungkan endpoint dengan query string + $endpoint = "/repos/{$owner}/{$repo}/commits?" . http_build_query($queryParams); + + $result = $this->fetchFromGitea($endpoint); + return $this->response->setJSON($result); + } + + /** + * Mengambil daftar Branches + * Contoh penggunaan di routes: /gitea/branches/mikael-zakaria/cobazaka + */ + public function getBranches(string $owner, string $repo) + { + $endpoint = "/repos/{$owner}/{$repo}/branches"; + $result = $this->fetchFromGitea($endpoint); + + return $this->response->setJSON($result); + } + + /** + * Mengambil detail User + * Contoh penggunaan di routes: /gitea/user/mikael-zakaria + */ + public function getUser(string $username) + { + $endpoint = "/users/{$username}"; + $result = $this->fetchFromGitea($endpoint); + + return $this->response->setJSON($result); + } + + /** + * Mengambil daftar Repositori milik User + * Contoh penggunaan di routes: /gitea/repos/mikael-zakaria + */ + public function getRepositories(string $username) + { + $endpoint = "/users/{$username}/repos"; + $result = $this->fetchFromGitea($endpoint); + + return $this->response->setJSON($result); + } + + public function index() + { + return view('gitea_index'); + } +} \ No newline at end of file diff --git a/app/Views/gitea_index.php b/app/Views/gitea_index.php new file mode 100644 index 0000000..0de8d36 --- /dev/null +++ b/app/Views/gitea_index.php @@ -0,0 +1,313 @@ +extend('layouts/main.php') ?> + +section('content') ?> + + +
+
+
+
+

Commit History

+
+
+ +
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ +
+
+ +
+
+
+ Please select a User -> Repository -> Branch first +
+
+
+ +
+
+endSection() ?> +section('script') ?> + +endSection() ?> \ No newline at end of file diff --git a/app/Views/layouts/_sidebar.php b/app/Views/layouts/_sidebar.php index db9be7f..62818c2 100644 --- a/app/Views/layouts/_sidebar.php +++ b/app/Views/layouts/_sidebar.php @@ -113,9 +113,10 @@
  • Activity Text
  • +
  • -
  • +