Skip to content

Bump: Octokit Rest and add plugins #451

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Bump Octokit Rest to v21, add retry/throttle plugins, and fix Variabl…
…es breaking change
  • Loading branch information
JustinGrote committed Mar 12, 2025
commit 119ec4ad5d8bc7f536720b09c60e4460cf04c5b2
938 changes: 589 additions & 349 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -563,7 +563,9 @@
"dependencies": {
"@actions/languageserver": "*",
"@actions/workflow-parser": "*",
"@octokit/rest": "^19.0.7",
"@octokit/plugin-retry": "^7.1.4",
"@octokit/plugin-throttling": "^9.4.0",
"@octokit/rest": "^21.1.1",
"@vscode/vsce": "^2.19.0",
"buffer": "^6.0.3",
"crypto-browserify": "^3.12.0",
29 changes: 26 additions & 3 deletions src/api/api.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,36 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import {Octokit} from "@octokit/rest";
import {version} from "../../package.json";
import {getGitHubApiUri} from "../configuration/configuration";
import {throttling} from "@octokit/plugin-throttling";
import {retry} from "@octokit/plugin-retry";

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

export function getClient(token: string): Octokit {
return new Octokit({
const GhaOctokit = Octokit.plugin(throttling, retry);
export type GhaOctokit = InstanceType<typeof GhaOctokit>;

export function getClient(token: string) {
return new GhaOctokit({
auth: token,
userAgent: userAgent,
baseUrl: getGitHubApiUri()
baseUrl: getGitHubApiUri(),
throttle: {
onRateLimit: (retryAfter, options, octokit) => {
octokit.log.warn(
`Request quota exhausted for request ${options.method} ${options.url}. Retrying after ${retryAfter} seconds.`
);

if (options.request.retryCount === 0) {
// only retries once
return true;
}
},
onSecondaryRateLimit: (retryAfter, options, octokit) => {
octokit.log.warn(
`Abuse detected for request ${options.method} ${options.url}. Retrying after ${retryAfter} seconds.`
);
}
}
});
}
5 changes: 2 additions & 3 deletions src/api/handleSamlError.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import {Octokit} from "@octokit/rest";
import {AuthenticationSession} from "vscode";

import {newSession} from "../auth/auth";
import {logDebug} from "../log";
import {getClient} from "./api";
import {getClient, GhaOctokit} from "./api";

export async function handleSamlError<T>(
session: AuthenticationSession,
request: (client: Octokit) => Promise<T>
request: (client: GhaOctokit) => Promise<T>
): Promise<T> {
try {
const client = getClient(session.accessToken);
6 changes: 4 additions & 2 deletions src/commands/secrets/addSecret.ts
Original file line number Diff line number Diff line change
@@ -66,12 +66,14 @@ export async function createOrUpdateEnvSecret(
value: string
) {
const keyResponse = await context.client.actions.getEnvironmentPublicKey({
repository_id: context.id,
owner: context.owner,
repo: context.name,
environment_name: environment
});

await context.client.actions.createOrUpdateEnvironmentSecret({
repository_id: context.id,
owner: context.owner,
repo: context.name,
environment_name: environment,
secret_name: name,
key_id: keyResponse.data.key_id,
3 changes: 2 additions & 1 deletion src/commands/secrets/deleteSecret.ts
Original file line number Diff line number Diff line change
@@ -18,7 +18,8 @@ export function registerDeleteSecret(context: vscode.ExtensionContext) {
if (answer === acceptText) {
if (environment) {
await gitHubRepoContext.client.actions.deleteEnvironmentSecret({
repository_id: gitHubRepoContext.id,
owner: gitHubRepoContext.owner,
repo: gitHubRepoContext.name,
environment_name: environment.name,
secret_name: secret.name
});
3 changes: 2 additions & 1 deletion src/commands/variables/addVariable.ts
Original file line number Diff line number Diff line change
@@ -31,7 +31,8 @@ export function registerAddVariable(context: vscode.ExtensionContext) {
try {
if ("environment" in args) {
await gitHubRepoContext.client.actions.createEnvironmentVariable({
repository_id: gitHubRepoContext.id,
owner: gitHubRepoContext.owner,
repo: gitHubRepoContext.name,
environment_name: args.environment.name,
name,
value
7 changes: 3 additions & 4 deletions src/git/repository.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as vscode from "vscode";
import {Octokit} from "@octokit/rest";

import {type GhaOctokit} from "../api/api";
import {canReachGitHubAPI} from "../api/canReachGitHubAPI";
import {handleSamlError} from "../api/handleSamlError";
import {getSession} from "../auth/auth";
@@ -131,7 +130,7 @@ export async function getGitHubUrls(): Promise<GitHubUrls[] | null> {
}

export interface GitHubRepoContext {
client: Octokit;
client: GhaOctokit;
repositoryState: RepositoryState | undefined;

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

const repos = await handleSamlError(session, async (client: Octokit) => {
const repos = await handleSamlError(session, async (client: GhaOctokit) => {
return await Promise.all(
protocolInfos.map(async (protocolInfo): Promise<GitHubRepoContext> => {
logDebug("Getting infos for repository", protocolInfo.url);
3 changes: 2 additions & 1 deletion src/treeViews/settings/environmentSecretsNode.ts
Original file line number Diff line number Diff line change
@@ -25,7 +25,8 @@ export class EnvironmentSecretsNode extends vscode.TreeItem {
// @ts-expect-error FIXME: Newer Typescript catches a problem that previous didn't. This will be fixed in Octokit bump.
this.gitHubRepoContext.client.actions.listEnvironmentSecrets,
{
repository_id: this.gitHubRepoContext.id,
owner: this.gitHubRepoContext.owner,
repo: this.gitHubRepoContext.name,
environment_name: this.environment.name,
per_page: 100
},
6 changes: 3 additions & 3 deletions src/treeViews/settings/environmentVariablesNode.ts
Original file line number Diff line number Diff line change
@@ -25,9 +25,9 @@ export class EnvironmentVariablesNode extends vscode.TreeItem {
// @ts-expect-error FIXME: Newer Typescript catches a problem that previous didn't. This will be fixed in Octokit bump.
this.gitHubRepoContext.client.actions.listEnvironmentVariables,
{
repository_id: this.gitHubRepoContext.id,
environment_name: this.environment.name,
per_page: 100
owner: this.gitHubRepoContext.owner,
repo: this.gitHubRepoContext.name,
environment_name: this.environment.name
},
// @ts-expect-error FIXME: Newer Typescript catches a problem that previous didn't. This will be fixed in Octokit bump.
response => response.data.map(v => new VariableNode(this.gitHubRepoContext, v, this.environment))