Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
32 changes: 14 additions & 18 deletions extensions/compose/src/compose-github-releases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,21 @@ export class ComposeGitHubReleases {
}
}

// Provides last 5 majors releases from GitHub using the GitHub API
// return name, tag and id of the release
async grabLatestsReleasesMetadata(): Promise<ComposeGithubReleaseArtifactMetadata[]> {
// Grab last 5 majors releases from GitHub using the GitHub API
private async getOctokitOrThrow(): Promise<Octokit> {
await this.ensureOctokit();

if (!this.octokit) {
throw new Error('Octokit instance not initialized');
}
return this.octokit;
}

// Provides last 5 majors releases from GitHub using the GitHub API
// return name, tag and id of the release
async grabLatestsReleasesMetadata(): Promise<ComposeGithubReleaseArtifactMetadata[]> {
// Grab last 5 majors releases from GitHub using the GitHub API
const octokit = await this.getOctokitOrThrow();

const lastReleases = await this.octokit.repos.listReleases({
const lastReleases = await octokit.repos.listReleases({
owner: ComposeGitHubReleases.COMPOSE_GITHUB_OWNER,
repo: ComposeGitHubReleases.COMPOSE_GITHUB_REPOSITORY,
});
Expand All @@ -75,11 +79,7 @@ export class ComposeGitHubReleases {
// operatingSystem: win32, darwin, linux (see os.platform())
// arch: x64, arm64 (see os.arch())
async getReleaseAssetId(releaseId: number, operatingSystem: string, arch: string): Promise<number> {
await this.ensureOctokit();

if (!this.octokit) {
throw new Error('Octokit instance not initialized');
}
const octokit = await this.getOctokitOrThrow();

let extension = '';
if (operatingSystem === 'win32') {
Expand All @@ -93,7 +93,7 @@ export class ComposeGitHubReleases {
arch = 'aarch64';
}

const listOfAssets = await this.octokit.paginate(this.octokit.repos.listReleaseAssets, {
const listOfAssets = await octokit.paginate(octokit.repos.listReleaseAssets, {
owner: ComposeGitHubReleases.COMPOSE_GITHUB_OWNER,
repo: ComposeGitHubReleases.COMPOSE_GITHUB_REPOSITORY,
release_id: releaseId,
Expand All @@ -112,13 +112,9 @@ export class ComposeGitHubReleases {

// download the given asset id
async downloadReleaseAsset(assetId: number, destination: string): Promise<void> {
await this.ensureOctokit();

if (!this.octokit) {
throw new Error('Octokit instance not initialized');
}
const octokit = await this.getOctokitOrThrow();

const asset = await this.octokit.repos.getReleaseAsset({
const asset = await octokit.repos.getReleaseAsset({
owner: ComposeGitHubReleases.COMPOSE_GITHUB_OWNER,
repo: ComposeGitHubReleases.COMPOSE_GITHUB_REPOSITORY,
asset_id: assetId,
Expand Down
32 changes: 14 additions & 18 deletions extensions/kind/src/kind-installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ export class KindInstaller {
}
}

private async getOctokitOrThrow(): Promise<Octokit> {
await this.ensureOctokit();
if (!this.octokit) {
throw new Error('Octokit instance not initialized');
}
return this.octokit;
}

// Get the latest version of kubectl from GitHub Releases
// and return the artifact metadata
async getLatestVersionAsset(): Promise<KindGithubReleaseArtifactMetadata> {
Expand All @@ -88,13 +96,9 @@ export class KindInstaller {
// return name, tag and id of the release
async grabLatestsReleasesMetadata(): Promise<KindGithubReleaseArtifactMetadata[]> {
// Grab last 5 majors releases from GitHub using the GitHub API
await this.ensureOctokit();

if (!this.octokit) {
throw new Error('Octokit instance not initialized');
}
const octokit = await this.getOctokitOrThrow();

const lastReleases = await this.octokit.repos.listReleases({
const lastReleases = await octokit.repos.listReleases({
owner: this.KIND_GITHUB_OWNER,
repo: this.KIND_GITHUB_REPOSITORY,
});
Expand Down Expand Up @@ -138,11 +142,7 @@ export class KindInstaller {
// operatingSystem: win32, darwin, linux (see os.platform())
// arch: x64, arm64 (see os.arch())
async getReleaseAssetId(releaseId: number, operatingSystem: string, arch: string): Promise<number> {
await this.ensureOctokit();

if (!this.octokit) {
throw new Error('Octokit instance not initialized');
}
const octokit = await this.getOctokitOrThrow();

if (operatingSystem === 'win32') {
operatingSystem = 'windows';
Expand All @@ -151,7 +151,7 @@ export class KindInstaller {
arch = 'amd64';
}

const listOfAssets = await this.octokit.repos.listReleaseAssets({
const listOfAssets = await octokit.repos.listReleaseAssets({
owner: this.KIND_GITHUB_OWNER,
repo: this.KIND_GITHUB_REPOSITORY,
release_id: releaseId,
Expand Down Expand Up @@ -201,13 +201,9 @@ export class KindInstaller {
}

async downloadReleaseAsset(assetId: number, destination: string): Promise<void> {
await this.ensureOctokit();

if (!this.octokit) {
throw new Error('Octokit instance not initialized');
}
const octokit = await this.getOctokitOrThrow();

const asset = await this.octokit.repos.getReleaseAsset({
const asset = await octokit.repos.getReleaseAsset({
owner: this.KIND_GITHUB_OWNER,
repo: this.KIND_GITHUB_REPOSITORY,
asset_id: assetId,
Expand Down
16 changes: 10 additions & 6 deletions extensions/kubectl-cli/src/kubectl-github-releases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,21 @@ export class KubectlGitHubReleases {
}
}

// Provides last 5 majors releases from GitHub using the GitHub API
// return name, tag and id of the release
async grabLatestsReleasesMetadata(): Promise<KubectlGithubReleaseArtifactMetadata[]> {
// Grab last 5 majors releases from GitHub using the GitHub API
private async getOctokitOrThrow(): Promise<Octokit> {
await this.ensureOctokit();

if (!this.octokit) {
throw new Error('Octokit instance not initialized');
}
return this.octokit;
}

// Provides last 5 majors releases from GitHub using the GitHub API
// return name, tag and id of the release
async grabLatestsReleasesMetadata(): Promise<KubectlGithubReleaseArtifactMetadata[]> {
// Grab last 5 majors releases from GitHub using the GitHub API
const octokit = await this.getOctokitOrThrow();

const lastReleases = await this.octokit.repos.listReleases({
const lastReleases = await octokit.repos.listReleases({
owner: KubectlGitHubReleases.KUBECTL_GITHUB_OWNER,
repo: KubectlGitHubReleases.KUBECTL_GITHUB_REPOSITORY,
per_page: 10, // limit to last 5 releases
Expand Down
Loading