ソースを参照

Fixes gitlens not loading in vscode.dev

main
Keith Daulton 2年前
コミット
7b5205412d
4個のファイルの変更26行の追加14行の削除
  1. +4
    -0
      CHANGELOG.md
  2. +4
    -1
      src/env/browser/fetch.ts
  3. +14
    -1
      src/env/node/fetch.ts
  4. +4
    -12
      src/plus/gitlab/gitlab.ts

+ 4
- 0
CHANGELOG.md ファイルの表示

@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
## [Unreleased]
## Fixed
- Fixes [#2048](https://github.com/gitkraken/vscode-gitlens/issues/2048) - Gitlens not loading in vscode.dev
## [12.1.1] - 2022-06-16
## Added

+ 4
- 1
src/env/browser/fetch.ts ファイルの表示

@ -1,5 +1,5 @@
const fetch = globalThis.fetch;
export { fetch };
export { fetch, fetch as insecureFetch };
declare global {
interface RequestInit {
@ -15,3 +15,6 @@ export type { _BodyInit as BodyInit, _RequestInit as RequestInit, _Response as R
export function getProxyAgent(_strictSSL?: boolean): undefined {
return undefined;
}
declare type FetchLike = (url: RequestInfo, init?: RequestInit | undefined) => Promise<Response>;
export type { FetchLike };

+ 14
- 1
src/env/node/fetch.ts ファイルの表示

@ -1,11 +1,13 @@
import * as url from 'url';
import { HttpsProxyAgent } from 'https-proxy-agent';
import fetch from 'node-fetch';
import fetch, { RequestInfo, RequestInit, Response } from 'node-fetch';
import { configuration } from '../../configuration';
export { fetch };
export type { BodyInit, RequestInit, Response } from 'node-fetch';
export type FetchLike = (url: RequestInfo, init?: RequestInit | undefined) => Promise<Response>;
export function getProxyAgent(strictSSL?: boolean): HttpsProxyAgent | undefined {
let proxyUrl: string | undefined;
@ -43,3 +45,14 @@ export function getProxyAgent(strictSSL?: boolean): HttpsProxyAgent | undefined
return undefined;
}
export async function insecureFetch(url: RequestInfo, init?: RequestInit): Promise<Response> {
const previousRejectUnauthorized = process.env.NODE_TLS_REJECT_UNAUTHORIZED;
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
try {
return await fetch(url, init);
} finally {
process.env.NODE_TLS_REJECT_UNAUTHORIZED = previousRejectUnauthorized;
}
}

+ 4
- 12
src/plus/gitlab/gitlab.ts ファイルの表示

@ -1,6 +1,7 @@
import type { HttpsProxyAgent } from 'https-proxy-agent';
import { Disposable, Uri, window } from 'vscode';
import { fetch, getProxyAgent, RequestInit, Response } from '@env/fetch';
import { fetch, getProxyAgent, insecureFetch } from '@env/fetch';
import type { FetchLike, RequestInit, Response } from '@env/fetch';
import { isWeb } from '@env/platform';
import { configuration, CustomRemoteType } from '../../configuration';
import type { Container } from '../../container';
@ -675,15 +676,10 @@ $search: String!
const agent = this.getProxyAgent(provider);
const ignoreSSLErrors = this.getIgnoreSSLErrors(provider);
let previousRejectUnauthorized;
const fetchMethod: FetchLike = ignoreSSLErrors === 'force' ? insecureFetch : fetch;
try {
if (ignoreSSLErrors === 'force') {
previousRejectUnauthorized = process.env.NODE_TLS_REJECT_UNAUTHORIZED;
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
}
rsp = await fetch(`${baseUrl ?? 'https://gitlab.com/api'}/graphql`, {
rsp = await fetchMethod(`${baseUrl ?? 'https://gitlab.com/api'}/graphql`, {
method: 'POST',
headers: { authorization: `Bearer ${token}`, 'content-type': 'application/json' },
agent: agent as any,
@ -699,10 +695,6 @@ $search: String!
throw new ProviderFetchError('GitLab', rsp);
} finally {
if (ignoreSSLErrors === 'force') {
process.env.NODE_TLS_REJECT_UNAUTHORIZED = previousRejectUnauthorized;
}
const match = /(^[^({\n]+)/.exec(query);
const message = ` ${match?.[1].trim() ?? query}`;

読み込み中…
キャンセル
保存