Files
Sebastian Poxhofer b106668a95 refactor(oxlint): enable typescript/no-useless-default-assignment (#44419)
- Convert `param: T | undefined = undefined` to optional `param?: T`.
- Drop dead `= false` defaults on the required cache-provider options.
- Make `GraphqlPaginatedContent.nodes/edges` optional so the `= []`
  fallbacks (load-bearing for partial GraphQL connections) are valid.
- Type the unchecked `default_branch` response field as optional so
  the `'HEAD'` fallback is retained.
- Drop `tag = undefined` from the Forgejo/Gitea/GitLab preset configs.

Part of #43845

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-07 16:38:48 +00:00

43 lines
1.2 KiB
TypeScript

import { parseJson } from '../common.ts';
import { regEx } from '../regex.ts';
import { isHttpUrl } from '../url.ts';
import { HttpBase, type InternalHttpOptions } from './http.ts';
import type { HttpOptions } from './types.ts';
let baseUrl: string;
export function setBaseUrl(url: string): void {
baseUrl = url;
}
/**
* Access Gerrit REST-API and strip-of the "magic prefix" from responses.
* @see https://gerrit-review.googlesource.com/Documentation/rest-api.html
*/
export class GerritHttp extends HttpBase {
private static magicPrefix = regEx(/^\)]}'\n/g);
protected override get baseUrl(): string | undefined {
return baseUrl;
}
constructor(options?: HttpOptions) {
super('gerrit', options);
}
override resolveUrl(requestUrl: string | URL, options?: HttpOptions): URL {
// ensure trailing slash for gerrit
return super.resolveUrl(
isHttpUrl(requestUrl) ? requestUrl : `${baseUrl}${requestUrl}`,
options,
);
}
protected override processOptions(
url: URL,
options: InternalHttpOptions,
): void {
options.parseJson = (text: string) =>
parseJson(text.replace(GerritHttp.magicPrefix, ''), url.pathname);
}
}