gitea brauchbar
This commit is contained in:
1 parent
dd1afbbeb2
commit
7219bae655
6 files changed
+606
-60
No files matched your search
@@ -250,7 +250,10 @@ PluginManager::instance()->onApiRoute(function (string $route, string $method) {
|
||||
'color' => $l['color'] ?? '888888',
|
||||
], $issue['labels'] ?? []),
|
||||
'assignees' => array_map(fn($a) => $a['login'] ?? '', $issue['assignees'] ?? []),
|
||||
'milestone' => $issue['milestone']['title'] ?? null,
|
||||
'milestone' => isset($issue['milestone']) && $issue['milestone'] ? [
|
||||
'id' => $issue['milestone']['id'] ?? null,
|
||||
'title' => $issue['milestone']['title'] ?? '',
|
||||
] : null,
|
||||
],
|
||||
'comments' => array_map(fn($c) => [
|
||||
'id' => $c['id'] ?? null,
|
||||
@@ -493,15 +496,93 @@ PluginManager::instance()->onApiRoute(function (string $route, string $method) {
|
||||
if (!$row) giteaJson(['error' => 'account not found'], 404);
|
||||
try {
|
||||
$client = giteaOpenClient($row);
|
||||
$labels = $client->listRepoLabels($owner, $repo);
|
||||
giteaJson([
|
||||
// Merge repo-level + org-level labels (org labels are inherited by
|
||||
// repos in an org but don't appear in /repos/.../labels)
|
||||
$repoLabels = $client->listRepoLabels($owner, $repo);
|
||||
$orgLabels = [];
|
||||
$warning = null;
|
||||
try {
|
||||
$orgLabels = $client->listOrgLabels($owner);
|
||||
} catch (GiteaApiException $e) {
|
||||
if ($e->statusCode === 404) {
|
||||
// Owner is a user, not an org — no org labels exist. silent.
|
||||
} elseif ($e->statusCode === 403) {
|
||||
// Token lacks read:organization scope — surface a warning
|
||||
// but don't fail the whole request; repo labels still work.
|
||||
$warning = 'Token lacks read:organization scope — org-level labels are not visible. Update your gitea token to include read:organization to see them.';
|
||||
} else {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
// Dedupe by id (in case the same label appears in both)
|
||||
$seen = [];
|
||||
$merged = [];
|
||||
foreach (array_merge($repoLabels, $orgLabels) as $l) {
|
||||
$id = $l['id'] ?? null;
|
||||
if ($id !== null && !isset($seen[$id])) {
|
||||
$seen[$id] = true;
|
||||
$merged[] = $l;
|
||||
}
|
||||
}
|
||||
$payload = [
|
||||
'ok' => true,
|
||||
'labels' => array_map(fn($l) => [
|
||||
'id' => $l['id'] ?? null,
|
||||
'name' => $l['name'] ?? '',
|
||||
'color' => $l['color'] ?? '888888',
|
||||
'description' => $l['description'] ?? '',
|
||||
], $labels),
|
||||
], $merged),
|
||||
];
|
||||
if ($warning) $payload['warning'] = $warning;
|
||||
giteaJson($payload);
|
||||
} catch (GiteaApiException $e) {
|
||||
giteaJson(['ok' => false, 'error' => "HTTP {$e->statusCode}: " . substr($e->body, 0, 300)], 200);
|
||||
} catch (\Throwable $e) {
|
||||
giteaJson(['ok' => false, 'error' => $e->getMessage()], 200);
|
||||
}
|
||||
}
|
||||
|
||||
if (preg_match('#^/api/gitea/repo/(\d+)/([^/]+)/([^/]+)/milestones$#', $route, $m) && $method === 'GET') {
|
||||
$accId = (int)$m[1]; $owner = urldecode($m[2]); $repo = urldecode($m[3]);
|
||||
$row = giteaGetAccount($accId);
|
||||
if (!$row) giteaJson(['error' => 'account not found'], 404);
|
||||
try {
|
||||
$client = giteaOpenClient($row);
|
||||
$milestones = $client->listRepoMilestones($owner, $repo, 'open');
|
||||
giteaJson([
|
||||
'ok' => true,
|
||||
'milestones' => array_map(fn($ms) => [
|
||||
'id' => $ms['id'] ?? null,
|
||||
'title' => $ms['title'] ?? '',
|
||||
'description' => $ms['description'] ?? '',
|
||||
'due_on' => $ms['due_on'] ?? null,
|
||||
'state' => $ms['state'] ?? 'open',
|
||||
], $milestones),
|
||||
]);
|
||||
} catch (GiteaApiException $e) {
|
||||
giteaJson(['ok' => false, 'error' => "HTTP {$e->statusCode}: " . substr($e->body, 0, 300)], 200);
|
||||
} catch (\Throwable $e) {
|
||||
giteaJson(['ok' => false, 'error' => $e->getMessage()], 200);
|
||||
}
|
||||
}
|
||||
|
||||
if (preg_match('#^/api/gitea/repo/(\d+)/([^/]+)/([^/]+)/collaborators$#', $route, $m) && $method === 'GET') {
|
||||
$accId = (int)$m[1]; $owner = urldecode($m[2]); $repo = urldecode($m[3]);
|
||||
$row = giteaGetAccount($accId);
|
||||
if (!$row) giteaJson(['error' => 'account not found'], 404);
|
||||
try {
|
||||
$client = giteaOpenClient($row);
|
||||
// Use /assignees instead of /collaborators — it returns the full
|
||||
// set of users that can be assigned (owner + org members +
|
||||
// explicit collaborators), which is what we actually want.
|
||||
$assignees = $client->listRepoAssignees($owner, $repo);
|
||||
giteaJson([
|
||||
'ok' => true,
|
||||
'collaborators' => array_map(fn($u) => [
|
||||
'login' => $u['login'] ?? '',
|
||||
'full_name' => $u['full_name'] ?? '',
|
||||
'avatar_url' => $u['avatar_url'] ?? '',
|
||||
], $assignees),
|
||||
]);
|
||||
} catch (GiteaApiException $e) {
|
||||
giteaJson(['ok' => false, 'error' => "HTTP {$e->statusCode}: " . substr($e->body, 0, 300)], 200);
|
||||
|
||||
Reference in new issue
Block a user