gitoria
All repositories: gitoria
2.9 KB
// JS target; redirects are followed explicitly. Network reasons are limited by the host Fetch API.function reason(e, timedOut) {if (timedOut) return 'timed out';const code = e?.cause?.code || e?.code;if (code === 'ECONNREFUSED') return 'connection refused';if (code === 'ENOTFOUND' || code === 'EAI_AGAIN') return 'could not resolve host';if (code === 'ECONNRESET' || code === 'UND_ERR_SOCKET') return 'connection reset by peer';if (code === 'ETIMEDOUT' || code === 'UND_ERR_CONNECT_TIMEOUT') return 'timed out';return e?.cause?.message || e?.message || String(e);}async function exchange(url, options, tolerant) {const o = options || {};const method = (o.method || 'GET').toUpperCase();let requestMethod = method;const controller = new AbortController();let timedOut = false;const timer = setTimeout(() => { timedOut = true; controller.abort(); }, o.timeoutMs ?? 30000);try {const headers = new Headers(o.headers || {});let body = o.body;if (o.json != null) {body = JSON.stringify(o.json);if (!headers.has('content-type')) headers.set('content-type', 'application/json');}// Generated modules use the runtime's Bytes wrapper; direct JS uses Uint8Array.if (body?._d instanceof Uint8Array) {const { hlIsBytes } = await import('../hl-runtime.js');if (hlIsBytes(body)) body = body._d;}if (body != null && typeof body !== 'string' && !(body instanceof Uint8Array)) {throw new Error('body must be a String or Bytes (use json for JSON)');}let target = url;const limit = o.maxRedirects ?? 5;for (let hop = 0; ; hop++) {const r = await globalThis.fetch(target, { method: requestMethod, headers, body, signal: controller.signal, redirect: 'manual' });const location = r.headers.get('location');if ([301, 302, 303, 307, 308].includes(r.status) && location && limit !== 0) {await r.body?.cancel();if (hop >= limit) throw new Error('too many redirects');const next = new URL(location, target);if (next.origin !== new URL(target).origin) {for (const name of ['authorization', 'proxy-authorization', 'cookie']) headers.delete(name);}if (r.status === 303 || ([301, 302].includes(r.status) && !['GET', 'HEAD'].includes(requestMethod))) {requestMethod = 'GET';body = undefined;headers.delete('content-type');headers.delete('content-length');}target = next.href;continue;}const text = await r.text();return { status: r.status, ok: r.ok, url: r.url, headers: Object.fromEntries(r.headers),body: text, tag: o.tag || '', text() { return text; }, json() { return JSON.parse(text); } };}} catch (e) {const error = `hl:fetch ${method} ${url}: ${reason(e, timedOut)}`;if (tolerant) return { ok: false, status: 0, error };throw new Error(error);} finally { clearTimeout(timer); }}export function fetch(url, options) { return exchange(url, options, false); }export function tryFetch(url, options) { return exchange(url, options, true); }
Branches
- f1-broken-json
- f2-api-bugs
- gp-gate-ports
- heap-revert
- hl25-records
- ident-chooser-selector
- mainmain branch
- p51-public-pr-reads
- records-1112
- s25-no-session-on-login-error
- v59
- w52-person-approval
- w52b-approval-followup
- w52c-header-phone
- w53-pulls-speed-pr
- w54-repo-rename-pr
- w55-rename-org
- w56-owner-members
- w62-pr-close
- w63-force-push
- w64-org-slash
Latest commits
- 93bdd26cpull state: wait for a claimed row, resync when it stays busy (#56)mre
- e53d284bpull state: stop on a failed branch scan, claim the row on writes (#56)mre
- d8608224close and reopen: keep a manual close against sync (#56)mre
- ffb60746|||PR close and reopen pull requests (#56)mre
- fe209ffeMerge branch 'w56-owner-members' into mainGitoria
- fa0754c8|||PR repository owner transfer and members API (#55)mre
- 8862e537Merge branch 'w55-rename-org' into mainGitoria
- 014d2b7fOne immutable readers snapshot per move for the left-organization event (#53)mre
- 1859d506Decide who hears a repo left its organization by its readers before the move (#53)mre
- 499f25f2Review fixes for the Settings organization move (#53)mre
- ed3b922b|||PR move a repository into an organization in Settings (#53)mre
- 74ec2af8Merge branch 'w54-repo-rename-pr' into mainGitoria
- 9f7ce8d8Preserve rename compatibility and live page titlesmre
- c3d95b6e|||PR separate names and addresses, rename repositories in Settings (#53)mre
- ce08920dMerge branch 'w52c-header-phone' into mainGitoria
- 0bab9e46|||PR header: ident status wraps on phones instead of clippingmre
- e7af3eceMerge branch 'w52b-approval-followup' into mainGitoria
- c01e66c6|||PR approvals follow-up: live Merge after status writes, helpers (#52)mre
- 841da497Merge branch 'w53-pulls-speed-pr' into mainGitoria
- 80307ae2|||PR pulls page cache: live PR numbers, complete scans onlymre