Skip to content

Commit 119ec4a

Browse files
committed
Bump Octokit Rest to v21, add retry/throttle plugins, and fix Variables breaking change
1 parent b2c15d8 commit 119ec4a

File tree

10 files changed

+636
-368
lines changed

10 files changed

+636
-368
lines changed

package-lock.json

+589-349
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,9 @@
563563
"dependencies": {
564564
"@actions/languageserver": "*",
565565
"@actions/workflow-parser": "*",
566-
"@octokit/rest": "^19.0.7",
566+
"@octokit/plugin-retry": "^7.1.4",
567+
"@octokit/plugin-throttling": "^9.4.0",
568+
"@octokit/rest": "^21.1.1",
567569
"@vscode/vsce": "^2.19.0",
568570
"buffer": "^6.0.3",
569571
"crypto-browserify": "^3.12.0",

src/api/api.ts

+26-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,36 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
12
import {Octokit} from "@octokit/rest";
23
import {version} from "../../package.json";
34
import {getGitHubApiUri} from "../configuration/configuration";
5+
import {throttling} from "@octokit/plugin-throttling";
6+
import {retry} from "@octokit/plugin-retry";
47

58
export const userAgent = `VS Code GitHub Actions (${version})`;
69

7-
export function getClient(token: string): Octokit {
8-
return new Octokit({
10+
const GhaOctokit = Octokit.plugin(throttling, retry);
11+
export type GhaOctokit = InstanceType<typeof GhaOctokit>;
12+
13+
export function getClient(token: string) {
14+
return new GhaOctokit({
915
auth: token,
1016
userAgent: userAgent,
11-
baseUrl: getGitHubApiUri()
17+
baseUrl: getGitHubApiUri(),
18+
throttle: {
19+
onRateLimit: (retryAfter, options, octokit) => {
20+
octokit.log.warn(
21+
`Request quota exhausted for request ${options.method} ${options.url}. Retrying after ${retryAfter} seconds.`
22+
);
23+
24+
if (options.request.retryCount === 0) {
25+
// only retries once
26+
return true;
27+
}
28+
},
29+
onSecondaryRateLimit: (retryAfter, options, octokit) => {
30+
octokit.log.warn(
31+
`Abuse detected for request ${options.method} ${options.url}. Retrying after ${retryAfter} seconds.`
32+
);
33+
}
34+
}
1235
});
1336
}

src/api/handleSamlError.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
import {Octokit} from "@octokit/rest";
21
import {AuthenticationSession} from "vscode";
32

43
import {newSession} from "../auth/auth";
54
import {logDebug} from "../log";
6-
import {getClient} from "./api";
5+
import {getClient, GhaOctokit} from "./api";
76

87
export async function handleSamlError<T>(
98
session: AuthenticationSession,
10-
request: (client: Octokit) => Promise<T>
9+
request: (client: GhaOctokit) => Promise<T>
1110
): Promise<T> {
1211
try {
1312
const client = getClient(session.accessToken);

src/commands/secrets/addSecret.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,14 @@ export async function createOrUpdateEnvSecret(
6666
value: string
6767
) {
6868
const keyResponse = await context.client.actions.getEnvironmentPublicKey({
69-
repository_id: context.id,
69+
owner: context.owner,
70+
repo: context.name,
7071
environment_name: environment
7172
});
7273

7374
await context.client.actions.createOrUpdateEnvironmentSecret({
74-
repository_id: context.id,
75+
owner: context.owner,
76+
repo: context.name,
7577
environment_name: environment,
7678
secret_name: name,
7779
key_id: keyResponse.data.key_id,

src/commands/secrets/deleteSecret.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ export function registerDeleteSecret(context: vscode.ExtensionContext) {
1818
if (answer === acceptText) {
1919
if (environment) {
2020
await gitHubRepoContext.client.actions.deleteEnvironmentSecret({
21-
repository_id: gitHubRepoContext.id,
21+
owner: gitHubRepoContext.owner,
22+
repo: gitHubRepoContext.name,
2223
environment_name: environment.name,
2324
secret_name: secret.name
2425
});

src/commands/variables/addVariable.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ export function registerAddVariable(context: vscode.ExtensionContext) {
3131
try {
3232
if ("environment" in args) {
3333
await gitHubRepoContext.client.actions.createEnvironmentVariable({
34-
repository_id: gitHubRepoContext.id,
34+
owner: gitHubRepoContext.owner,
35+
repo: gitHubRepoContext.name,
3536
environment_name: args.environment.name,
3637
name,
3738
value

src/git/repository.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as vscode from "vscode";
2-
import {Octokit} from "@octokit/rest";
3-
2+
import {type GhaOctokit} from "../api/api";
43
import {canReachGitHubAPI} from "../api/canReachGitHubAPI";
54
import {handleSamlError} from "../api/handleSamlError";
65
import {getSession} from "../auth/auth";
@@ -131,7 +130,7 @@ export async function getGitHubUrls(): Promise<GitHubUrls[] | null> {
131130
}
132131

133132
export interface GitHubRepoContext {
134-
client: Octokit;
133+
client: GhaOctokit;
135134
repositoryState: RepositoryState | undefined;
136135

137136
workspaceUri: vscode.Uri;
@@ -186,7 +185,7 @@ export async function getGitHubContext(): Promise<GitHubContext | undefined> {
186185
}
187186
const username = session.account.label;
188187

189-
const repos = await handleSamlError(session, async (client: Octokit) => {
188+
const repos = await handleSamlError(session, async (client: GhaOctokit) => {
190189
return await Promise.all(
191190
protocolInfos.map(async (protocolInfo): Promise<GitHubRepoContext> => {
192191
logDebug("Getting infos for repository", protocolInfo.url);

src/treeViews/settings/environmentSecretsNode.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ export class EnvironmentSecretsNode extends vscode.TreeItem {
2525
// @ts-expect-error FIXME: Newer Typescript catches a problem that previous didn't. This will be fixed in Octokit bump.
2626
this.gitHubRepoContext.client.actions.listEnvironmentSecrets,
2727
{
28-
repository_id: this.gitHubRepoContext.id,
28+
owner: this.gitHubRepoContext.owner,
29+
repo: this.gitHubRepoContext.name,
2930
environment_name: this.environment.name,
3031
per_page: 100
3132
},

src/treeViews/settings/environmentVariablesNode.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ export class EnvironmentVariablesNode extends vscode.TreeItem {
2525
// @ts-expect-error FIXME: Newer Typescript catches a problem that previous didn't. This will be fixed in Octokit bump.
2626
this.gitHubRepoContext.client.actions.listEnvironmentVariables,
2727
{
28-
repository_id: this.gitHubRepoContext.id,
29-
environment_name: this.environment.name,
30-
per_page: 100
28+
owner: this.gitHubRepoContext.owner,
29+
repo: this.gitHubRepoContext.name,
30+
environment_name: this.environment.name
3131
},
3232
// @ts-expect-error FIXME: Newer Typescript catches a problem that previous didn't. This will be fixed in Octokit bump.
3333
response => response.data.map(v => new VariableNode(this.gitHubRepoContext, v, this.environment))

0 commit comments

Comments
 (0)