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).
This commit is contained in:
10
extensions/ql-vscode/src/common/octokit.ts
Normal file
10
extensions/ql-vscode/src/common/octokit.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import * as Octokit from "@octokit/rest";
|
||||||
|
import { retry } from "@octokit/plugin-retry";
|
||||||
|
import fetch from "node-fetch";
|
||||||
|
|
||||||
|
export const AppOctokit = Octokit.Octokit.defaults({
|
||||||
|
request: {
|
||||||
|
fetch,
|
||||||
|
},
|
||||||
|
retry,
|
||||||
|
});
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import * as vscode from "vscode";
|
import * as vscode from "vscode";
|
||||||
import * as Octokit from "@octokit/rest";
|
import * as Octokit from "@octokit/rest";
|
||||||
import { retry } from "@octokit/plugin-retry";
|
|
||||||
import { Credentials } from "../authentication";
|
import { Credentials } from "../authentication";
|
||||||
|
import { AppOctokit } from "../octokit";
|
||||||
|
|
||||||
export const GITHUB_AUTH_PROVIDER_ID = "github";
|
export const GITHUB_AUTH_PROVIDER_ID = "github";
|
||||||
|
|
||||||
@@ -32,9 +32,8 @@ export class VSCodeCredentials implements Credentials {
|
|||||||
|
|
||||||
const accessToken = await this.getAccessToken();
|
const accessToken = await this.getAccessToken();
|
||||||
|
|
||||||
return new Octokit.Octokit({
|
return new AppOctokit({
|
||||||
auth: accessToken,
|
auth: accessToken,
|
||||||
retry,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { retry } from "@octokit/plugin-retry";
|
|
||||||
import { throttling } from "@octokit/plugin-throttling";
|
import { throttling } from "@octokit/plugin-throttling";
|
||||||
import { Octokit } from "@octokit/rest";
|
import { Octokit } from "@octokit/rest";
|
||||||
import { Progress, CancellationToken } from "vscode";
|
import { Progress, CancellationToken } from "vscode";
|
||||||
import { Credentials } from "../common/authentication";
|
import { Credentials } from "../common/authentication";
|
||||||
import { BaseLogger } from "../common/logging";
|
import { BaseLogger } from "../common/logging";
|
||||||
|
import { AppOctokit } from "../common/octokit";
|
||||||
|
|
||||||
export async function getCodeSearchRepositories(
|
export async function getCodeSearchRepositories(
|
||||||
query: string,
|
query: string,
|
||||||
@@ -46,12 +46,11 @@ async function provideOctokitWithThrottling(
|
|||||||
credentials: Credentials,
|
credentials: Credentials,
|
||||||
logger: BaseLogger,
|
logger: BaseLogger,
|
||||||
): Promise<Octokit> {
|
): Promise<Octokit> {
|
||||||
const MyOctokit = Octokit.plugin(throttling);
|
const MyOctokit = AppOctokit.plugin(throttling);
|
||||||
const auth = await credentials.getAccessToken();
|
const auth = await credentials.getAccessToken();
|
||||||
|
|
||||||
const octokit = new MyOctokit({
|
const octokit = new MyOctokit({
|
||||||
auth,
|
auth,
|
||||||
retry,
|
|
||||||
throttle: {
|
throttle: {
|
||||||
onRateLimit: (retryAfter: number, options: any): boolean => {
|
onRateLimit: (retryAfter: number, options: any): boolean => {
|
||||||
void logger.log(
|
void logger.log(
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import {
|
|||||||
} from "fs-extra";
|
} from "fs-extra";
|
||||||
import { basename, join } from "path";
|
import { basename, join } from "path";
|
||||||
import * as Octokit from "@octokit/rest";
|
import * as Octokit from "@octokit/rest";
|
||||||
import { retry } from "@octokit/plugin-retry";
|
|
||||||
|
|
||||||
import { DatabaseManager, DatabaseItem } from "./local-databases";
|
import { DatabaseManager, DatabaseItem } from "./local-databases";
|
||||||
import { tmpDir } from "../tmp-dir";
|
import { tmpDir } from "../tmp-dir";
|
||||||
@@ -32,6 +31,7 @@ import { Credentials } from "../common/authentication";
|
|||||||
import { AppCommandManager } from "../common/commands";
|
import { AppCommandManager } from "../common/commands";
|
||||||
import { allowHttp } from "../config";
|
import { allowHttp } from "../config";
|
||||||
import { showAndLogInformationMessage } from "../common/logging";
|
import { showAndLogInformationMessage } from "../common/logging";
|
||||||
|
import { AppOctokit } from "../common/octokit";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prompts a user to fetch a database from a remote location. Database is assumed to be an archive file.
|
* 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(
|
|||||||
|
|
||||||
const octokit = credentials
|
const octokit = credentials
|
||||||
? await credentials.getOctokit()
|
? await credentials.getOctokit()
|
||||||
: new Octokit.Octokit({ retry });
|
: new AppOctokit();
|
||||||
|
|
||||||
const result = await convertGithubNwoToDatabaseUrl(
|
const result = await convertGithubNwoToDatabaseUrl(
|
||||||
nwo,
|
nwo,
|
||||||
|
|||||||
Reference in New Issue
Block a user