Skip to content

Commit 3c10e87

Browse files
committed
Switch Octokit to use node-fetch
It seems like Node's native `fetch` implementation isn't quite working right with Octokit and MSW. This switches to using `node-fetch` like we're already doing for all other requests (e.g. downloading databases).
1 parent a1ea1f8 commit 3c10e87

4 files changed

Lines changed: 16 additions & 8 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as Octokit from "@octokit/rest";
2+
import { retry } from "@octokit/plugin-retry";
3+
import fetch from "node-fetch";
4+
5+
export const AppOctokit = Octokit.Octokit.defaults({
6+
request: {
7+
fetch,
8+
},
9+
retry,
10+
});

extensions/ql-vscode/src/common/vscode/authentication.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as vscode from "vscode";
22
import * as Octokit from "@octokit/rest";
3-
import { retry } from "@octokit/plugin-retry";
43
import { Credentials } from "../authentication";
4+
import { AppOctokit } from "../octokit";
55

66
export const GITHUB_AUTH_PROVIDER_ID = "github";
77

@@ -32,9 +32,8 @@ export class VSCodeCredentials implements Credentials {
3232

3333
const accessToken = await this.getAccessToken();
3434

35-
return new Octokit.Octokit({
35+
return new AppOctokit({
3636
auth: accessToken,
37-
retry,
3837
});
3938
}
4039

extensions/ql-vscode/src/databases/code-search-api.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { retry } from "@octokit/plugin-retry";
21
import { throttling } from "@octokit/plugin-throttling";
32
import { Octokit } from "@octokit/rest";
43
import { Progress, CancellationToken } from "vscode";
54
import { Credentials } from "../common/authentication";
65
import { BaseLogger } from "../common/logging";
6+
import { AppOctokit } from "../common/octokit";
77

88
export async function getCodeSearchRepositories(
99
query: string,
@@ -46,12 +46,11 @@ async function provideOctokitWithThrottling(
4646
credentials: Credentials,
4747
logger: BaseLogger,
4848
): Promise<Octokit> {
49-
const MyOctokit = Octokit.plugin(throttling);
49+
const MyOctokit = AppOctokit.plugin(throttling);
5050
const auth = await credentials.getAccessToken();
5151

5252
const octokit = new MyOctokit({
5353
auth,
54-
retry,
5554
throttle: {
5655
onRateLimit: (retryAfter: number, options: any): boolean => {
5756
void logger.log(

extensions/ql-vscode/src/databases/database-fetcher.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
} from "fs-extra";
1515
import { basename, join } from "path";
1616
import * as Octokit from "@octokit/rest";
17-
import { retry } from "@octokit/plugin-retry";
1817

1918
import { DatabaseManager, DatabaseItem } from "./local-databases";
2019
import { tmpDir } from "../tmp-dir";
@@ -32,6 +31,7 @@ import { Credentials } from "../common/authentication";
3231
import { AppCommandManager } from "../common/commands";
3332
import { allowHttp } from "../config";
3433
import { showAndLogInformationMessage } from "../common/logging";
34+
import { AppOctokit } from "../common/octokit";
3535

3636
/**
3737
* Prompts a user to fetch a database from a remote location. Database is assumed to be an archive file.
@@ -186,7 +186,7 @@ export async function downloadGitHubDatabase(
186186

187187
const octokit = credentials
188188
? await credentials.getOctokit()
189-
: new Octokit.Octokit({ retry });
189+
: new AppOctokit();
190190

191191
const result = await convertGithubNwoToDatabaseUrl(
192192
nwo,

0 commit comments

Comments
 (0)