Skip to content

Commit 0f1cea8

Browse files
d13eamodio
authored andcommitted
Fixes gitlens not loading in vscode.dev
1 parent e99cf89 commit 0f1cea8

File tree

4 files changed

+26
-14
lines changed

4 files changed

+26
-14
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
66

77
## [Unreleased]
88

9+
## Fixed
10+
11+
- Fixes [#2048](https://github.com/gitkraken/vscode-gitlens/issues/2048) - Gitlens not loading in vscode.dev
12+
913
## [12.1.1] - 2022-06-16
1014

1115
## Added

src/env/browser/fetch.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const fetch = globalThis.fetch;
2-
export { fetch };
2+
export { fetch, fetch as insecureFetch };
33

44
declare global {
55
interface RequestInit {
@@ -15,3 +15,6 @@ export type { _BodyInit as BodyInit, _RequestInit as RequestInit, _Response as R
1515
export function getProxyAgent(_strictSSL?: boolean): undefined {
1616
return undefined;
1717
}
18+
19+
declare type FetchLike = (url: RequestInfo, init?: RequestInit | undefined) => Promise<Response>;
20+
export type { FetchLike };

src/env/node/fetch.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import * as url from 'url';
22
import { HttpsProxyAgent } from 'https-proxy-agent';
3-
import fetch from 'node-fetch';
3+
import fetch, { RequestInfo, RequestInit, Response } from 'node-fetch';
44
import { configuration } from '../../configuration';
55

66
export { fetch };
77
export type { BodyInit, RequestInit, Response } from 'node-fetch';
88

9+
export type FetchLike = (url: RequestInfo, init?: RequestInit | undefined) => Promise<Response>;
10+
911
export function getProxyAgent(strictSSL?: boolean): HttpsProxyAgent | undefined {
1012
let proxyUrl: string | undefined;
1113

@@ -43,3 +45,14 @@ export function getProxyAgent(strictSSL?: boolean): HttpsProxyAgent | undefined
4345

4446
return undefined;
4547
}
48+
49+
export async function insecureFetch(url: RequestInfo, init?: RequestInit): Promise<Response> {
50+
const previousRejectUnauthorized = process.env.NODE_TLS_REJECT_UNAUTHORIZED;
51+
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
52+
53+
try {
54+
return await fetch(url, init);
55+
} finally {
56+
process.env.NODE_TLS_REJECT_UNAUTHORIZED = previousRejectUnauthorized;
57+
}
58+
}

src/plus/gitlab/gitlab.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { HttpsProxyAgent } from 'https-proxy-agent';
22
import { Disposable, Uri, window } from 'vscode';
3-
import { fetch, getProxyAgent, RequestInit, Response } from '@env/fetch';
3+
import { fetch, getProxyAgent, insecureFetch } from '@env/fetch';
4+
import type { FetchLike, RequestInit, Response } from '@env/fetch';
45
import { isWeb } from '@env/platform';
56
import { configuration, CustomRemoteType } from '../../configuration';
67
import type { Container } from '../../container';
@@ -675,15 +676,10 @@ $search: String!
675676

676677
const agent = this.getProxyAgent(provider);
677678
const ignoreSSLErrors = this.getIgnoreSSLErrors(provider);
678-
let previousRejectUnauthorized;
679+
const fetchMethod: FetchLike = ignoreSSLErrors === 'force' ? insecureFetch : fetch;
679680

680681
try {
681-
if (ignoreSSLErrors === 'force') {
682-
previousRejectUnauthorized = process.env.NODE_TLS_REJECT_UNAUTHORIZED;
683-
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
684-
}
685-
686-
rsp = await fetch(`${baseUrl ?? 'https://gitlab.com/api'}/graphql`, {
682+
rsp = await fetchMethod(`${baseUrl ?? 'https://gitlab.com/api'}/graphql`, {
687683
method: 'POST',
688684
headers: { authorization: `Bearer ${token}`, 'content-type': 'application/json' },
689685
agent: agent as any,
@@ -699,10 +695,6 @@ $search: String!
699695

700696
throw new ProviderFetchError('GitLab', rsp);
701697
} finally {
702-
if (ignoreSSLErrors === 'force') {
703-
process.env.NODE_TLS_REJECT_UNAUTHORIZED = previousRejectUnauthorized;
704-
}
705-
706698
const match = /(^[^({\n]+)/.exec(query);
707699
const message = ` ${match?.[1].trim() ?? query}`;
708700

0 commit comments

Comments
 (0)