gitea plug
This commit is contained in:
1 parent
86508ffcca
commit
dd1afbbeb2
6 files changed
+1650
-30
No files matched your search
@@ -85,6 +85,80 @@ class GiteaClient
|
||||
return is_array($resp) ? $resp : [];
|
||||
}
|
||||
|
||||
/** Post a new comment on an issue. Returns the created comment object. */
|
||||
public function createIssueComment(string $owner, string $repo, int $index, string $body): array
|
||||
{
|
||||
$path = '/repos/' . rawurlencode($owner) . '/' . rawurlencode($repo) . '/issues/' . $index . '/comments';
|
||||
$resp = $this->request('POST', $path, [], ['body' => $body]);
|
||||
return is_array($resp) ? $resp : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit an issue. Pass any subset of: title, body, state ('open'|'closed'),
|
||||
* assignees (string[]), milestone (int), due_date (RFC3339), unset_due_date (bool).
|
||||
* Returns the updated issue.
|
||||
*/
|
||||
public function editIssue(string $owner, string $repo, int $index, array $changes): array
|
||||
{
|
||||
$allowed = ['title', 'body', 'state', 'assignees', 'milestone', 'due_date', 'ref', 'unset_due_date'];
|
||||
$payload = [];
|
||||
foreach ($allowed as $k) {
|
||||
if (array_key_exists($k, $changes)) $payload[$k] = $changes[$k];
|
||||
}
|
||||
if (!$payload) return [];
|
||||
$path = '/repos/' . rawurlencode($owner) . '/' . rawurlencode($repo) . '/issues/' . $index;
|
||||
$resp = $this->request('PATCH', $path, [], $payload);
|
||||
return is_array($resp) ? $resp : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the labels of an issue. $labels is an array of label IDs (ints).
|
||||
* Returns the resulting list of labels.
|
||||
*/
|
||||
public function replaceIssueLabels(string $owner, string $repo, int $index, array $labels): array
|
||||
{
|
||||
$path = '/repos/' . rawurlencode($owner) . '/' . rawurlencode($repo) . '/issues/' . $index . '/labels';
|
||||
$resp = $this->request('PUT', $path, [], ['labels' => array_map('intval', $labels)]);
|
||||
return is_array($resp) ? $resp : [];
|
||||
}
|
||||
|
||||
/** Fetch the available labels for a repository. */
|
||||
public function listRepoLabels(string $owner, string $repo, int $page = 1, int $limit = 100): array
|
||||
{
|
||||
$path = '/repos/' . rawurlencode($owner) . '/' . rawurlencode($repo) . '/labels';
|
||||
$resp = $this->request('GET', $path, ['page' => $page, 'limit' => $limit]);
|
||||
return is_array($resp) ? $resp : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new issue in a repository. Pass any of: title (required),
|
||||
* body, assignees (string[]), labels (int[] of label IDs), milestone (int),
|
||||
* due_date (RFC3339), ref, closed (bool).
|
||||
* Returns the created issue.
|
||||
*/
|
||||
public function createIssue(string $owner, string $repo, array $opts): array
|
||||
{
|
||||
if (empty($opts['title'])) return [];
|
||||
$allowed = ['title', 'body', 'assignees', 'labels', 'milestone', 'due_date', 'ref', 'closed'];
|
||||
$payload = [];
|
||||
foreach ($allowed as $k) {
|
||||
if (array_key_exists($k, $opts) && $opts[$k] !== null) $payload[$k] = $opts[$k];
|
||||
}
|
||||
$path = '/repos/' . rawurlencode($owner) . '/' . rawurlencode($repo) . '/issues';
|
||||
$resp = $this->request('POST', $path, [], $payload);
|
||||
return is_array($resp) ? $resp : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* List repositories the authenticated user has access to.
|
||||
* Used to populate the repo picker for "new issue".
|
||||
*/
|
||||
public function listMyRepos(int $page = 1, int $limit = 100): array
|
||||
{
|
||||
$resp = $this->request('GET', '/user/repos', ['page' => $page, 'limit' => $limit]);
|
||||
return is_array($resp) ? $resp : [];
|
||||
}
|
||||
|
||||
// ── Low-level request ─────────────────────────────────────────
|
||||
|
||||
private function request(string $method, string $path, array $query = [], ?array $payload = null)
|
||||
|
||||
Reference in new issue
Block a user