feat(phase3): comments, issue compose, PR diff viewer, reviews, merge, checks
- API: comments CRUD, create/edit issue, milestones, collaborators, pull files, raw unified diff (getText), reviews, merge, combined commit status - hooks: comment thread + composer mutations, issue compose mutations, pull files/diff/reviews, create review, merge, combined status - UI: TextArea, ChipSelect, CommentItem, CommentComposer, native DiffView (parseDiff), StatusChecks - screens: IssueCompose (create/edit), PullFiles, PullDiff, PullReview; issue detail gains thread + close/reopen; PR detail gains reviews, merge, files, checks; commit detail shows checks - navigation/types + i18n (en/nl) updated; centralized safeHost helper - tests: diff parser, endpoint body shapes (merge capitalisation), client getText
This commit is contained in:
1 parent
f641238b6f
commit
ddd834b7ac
32 files changed
+2546
-68
No files matched your search
@@ -117,6 +117,66 @@ export class GiteaClient {
|
||||
return raw.data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches a plain-text response (e.g. a pull request `.diff`).
|
||||
*
|
||||
* Shares the timeout/abort/error-normalization contract of {@link raw}, but
|
||||
* deliberately does not parse JSON. A non-2xx response is still mapped to an
|
||||
* {@link ApiError} that never contains the URL or the token.
|
||||
*/
|
||||
async getText(path: string, options: Omit<RequestOptions, 'method' | 'body'> = {}): Promise<string> {
|
||||
const url = `${this.apiRoot}${path}${buildQuery(options.query ?? {})}`;
|
||||
const headers: Record<string, string> = { Accept: 'text/plain' };
|
||||
if (this.token) headers.Authorization = `token ${this.token}`;
|
||||
|
||||
const controller = new AbortController();
|
||||
let timedOut = false;
|
||||
const timeoutMs = options.timeoutMs ?? this.timeoutMs;
|
||||
const timer = setTimeout(() => {
|
||||
timedOut = true;
|
||||
controller.abort();
|
||||
}, timeoutMs);
|
||||
const onCallerAbort = () => controller.abort();
|
||||
if (options.signal) {
|
||||
if (options.signal.aborted) {
|
||||
clearTimeout(timer);
|
||||
throw new ApiError({ kind: 'aborted', status: 0, message: 'Request cancelled.' });
|
||||
}
|
||||
options.signal.addEventListener('abort', onCallerAbort);
|
||||
}
|
||||
|
||||
let response: Response;
|
||||
try {
|
||||
response = await this.fetchImpl(url, { method: 'GET', headers, signal: controller.signal });
|
||||
} catch (error) {
|
||||
if (timedOut) {
|
||||
throw new ApiError({
|
||||
kind: 'timeout',
|
||||
status: 0,
|
||||
message: 'The server took too long to respond.',
|
||||
});
|
||||
}
|
||||
if (options.signal?.aborted) {
|
||||
throw new ApiError({ kind: 'aborted', status: 0, message: 'Request cancelled.' });
|
||||
}
|
||||
throw toApiError(error);
|
||||
} finally {
|
||||
clearTimeout(timer);
|
||||
options.signal?.removeEventListener('abort', onCallerAbort);
|
||||
}
|
||||
|
||||
const text = await response.text();
|
||||
if (!response.ok) {
|
||||
const kind = ApiError.kindForStatus(response.status);
|
||||
throw new ApiError({
|
||||
kind,
|
||||
status: response.status,
|
||||
message: messageForStatus(kind, response.status, null),
|
||||
});
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a request and returns data plus pagination metadata.
|
||||
* `hasMore` uses `X-Total-Count` when present, otherwise a length heuristic
|
||||
|
||||
Reference in new issue
Block a user