Skip to content

Commit

Permalink
Fixes gitlens not loading in vscode.dev
Browse files Browse the repository at this point in the history
  • Loading branch information
d13 authored and eamodio committed Jul 13, 2022
1 parent e99cf89 commit 0f1cea8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/env/browser/fetch.ts
@@ -1,5 +1,5 @@
const fetch = globalThis.fetch;
export { fetch };
export { fetch, fetch as insecureFetch };

declare global {
interface RequestInit {
Expand All @@ -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 };
15 changes: 14 additions & 1 deletion 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;

Expand Down Expand Up @@ -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;
}
}
16 changes: 4 additions & 12 deletions 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';
Expand Down Expand Up @@ -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,
Expand All @@ -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}`;

Expand Down

0 comments on commit 0f1cea8

Please sign in to comment.