Provide the proxy options to oktokit

This commit is contained in:
Joseph Garrone 2024-08-13 00:10:34 +02:00
parent d9132ea5a5
commit 43f455f4d0
5 changed files with 43 additions and 18 deletions

View File

@ -2,7 +2,10 @@ import { join as pathJoin, relative as pathRelative, dirname as pathDirname } fr
import type { BuildContext } from "../shared/buildContext"; import type { BuildContext } from "../shared/buildContext";
import * as fs from "fs"; import * as fs from "fs";
import chalk from "chalk"; import chalk from "chalk";
import { getLatestsSemVersionedTag } from "../shared/getLatestsSemVersionedTag"; import {
getLatestsSemVersionedTag,
type BuildContextLike as BuildContextLike_getLatestsSemVersionedTag
} from "../shared/getLatestsSemVersionedTag";
import fetch from "make-fetch-happen"; import fetch from "make-fetch-happen";
import { z } from "zod"; import { z } from "zod";
import { assert, type Equals } from "tsafe/assert"; import { assert, type Equals } from "tsafe/assert";
@ -12,8 +15,7 @@ import { npmInstall } from "../tools/npmInstall";
import { copyBoilerplate } from "./copyBoilerplate"; import { copyBoilerplate } from "./copyBoilerplate";
import { getThisCodebaseRootDirPath } from "../tools/getThisCodebaseRootDirPath"; import { getThisCodebaseRootDirPath } from "../tools/getThisCodebaseRootDirPath";
type BuildContextLike = { type BuildContextLike = BuildContextLike_getLatestsSemVersionedTag & {
cacheDirPath: string;
fetchOptions: BuildContext["fetchOptions"]; fetchOptions: BuildContext["fetchOptions"];
packageJsonFilePath: string; packageJsonFilePath: string;
}; };
@ -30,11 +32,11 @@ export async function initializeAccountTheme_singlePage(params: {
const REPO = "keycloak-account-ui"; const REPO = "keycloak-account-ui";
const [semVersionedTag] = await getLatestsSemVersionedTag({ const [semVersionedTag] = await getLatestsSemVersionedTag({
cacheDirPath: buildContext.cacheDirPath,
owner: OWNER, owner: OWNER,
repo: REPO, repo: REPO,
count: 1, count: 1,
doIgnoreReleaseCandidates: false doIgnoreReleaseCandidates: false,
buildContext
}); });
const dependencies = await fetch( const dependencies = await fetch(

View File

@ -30,7 +30,7 @@ export async function command(params: { cliCommandOptions: CliCommandOptions })
// NOTE: This is arbitrary // NOTE: This is arbitrary
startingFromMajor: 17, startingFromMajor: 17,
excludeMajorVersions: [], excludeMajorVersions: [],
cacheDirPath: buildContext.cacheDirPath buildContext
}); });
const { defaultThemeDirPath } = await downloadKeycloakDefaultTheme({ const { defaultThemeDirPath } = await downloadKeycloakDefaultTheme({

View File

@ -9,6 +9,7 @@ import { assert, type Equals } from "tsafe/assert";
import { id } from "tsafe/id"; import { id } from "tsafe/id";
import type { SemVer } from "../tools/SemVer"; import type { SemVer } from "../tools/SemVer";
import { same } from "evt/tools/inDepth/same"; import { same } from "evt/tools/inDepth/same";
import type { BuildContext } from "./buildContext";
type GetLatestsSemVersionedTag = ReturnType< type GetLatestsSemVersionedTag = ReturnType<
typeof getLatestsSemVersionedTagFactory typeof getLatestsSemVersionedTagFactory
@ -31,11 +32,23 @@ type Cache = {
}[]; }[];
}; };
export type BuildContextLike = {
cacheDirPath: string;
fetchOptions: BuildContext["fetchOptions"];
};
assert<BuildContext extends BuildContextLike ? true : false>();
export async function getLatestsSemVersionedTag({ export async function getLatestsSemVersionedTag({
cacheDirPath, buildContext,
...params ...params
}: Params & { cacheDirPath: string }): Promise<R> { }: Params & {
const cacheFilePath = pathJoin(cacheDirPath, "latest-sem-versioned-tags.json"); buildContext: BuildContextLike;
}): Promise<R> {
const cacheFilePath = pathJoin(
buildContext.cacheDirPath,
"latest-sem-versioned-tags.json"
);
const cacheLookupResult = (() => { const cacheLookupResult = (() => {
const getResult_currentCache = (currentCacheEntries: Cache["entries"]) => ({ const getResult_currentCache = (currentCacheEntries: Cache["entries"]) => ({
@ -144,9 +157,10 @@ export async function getLatestsSemVersionedTag({
const octokit = (() => { const octokit = (() => {
const githubToken = process.env.GITHUB_TOKEN; const githubToken = process.env.GITHUB_TOKEN;
const octokit = new Octokit( const octokit = new Octokit({
githubToken === undefined ? undefined : { auth: githubToken } ...(githubToken === undefined ? {} : { auth: githubToken }),
); request: buildContext.fetchOptions
});
return octokit; return octokit;
})(); })();

View File

@ -1,22 +1,31 @@
import { getLatestsSemVersionedTag } from "./getLatestsSemVersionedTag"; import {
getLatestsSemVersionedTag,
type BuildContextLike as BuildContextLike_getLatestsSemVersionedTag
} from "./getLatestsSemVersionedTag";
import cliSelect from "cli-select"; import cliSelect from "cli-select";
import { assert } from "tsafe/assert";
import { SemVer } from "../tools/SemVer"; import { SemVer } from "../tools/SemVer";
import type { BuildContext } from "./buildContext";
export type BuildContextLike = BuildContextLike_getLatestsSemVersionedTag & {};
assert<BuildContext extends BuildContextLike ? true : false>();
export async function promptKeycloakVersion(params: { export async function promptKeycloakVersion(params: {
startingFromMajor: number | undefined; startingFromMajor: number | undefined;
excludeMajorVersions: number[]; excludeMajorVersions: number[];
cacheDirPath: string; buildContext: BuildContextLike;
}) { }) {
const { startingFromMajor, excludeMajorVersions, cacheDirPath } = params; const { startingFromMajor, excludeMajorVersions, buildContext } = params;
const semVersionedTagByMajor = new Map<number, { tag: string; version: SemVer }>(); const semVersionedTagByMajor = new Map<number, { tag: string; version: SemVer }>();
const semVersionedTags = await getLatestsSemVersionedTag({ const semVersionedTags = await getLatestsSemVersionedTag({
cacheDirPath,
count: 50, count: 50,
owner: "keycloak", owner: "keycloak",
repo: "keycloak", repo: "keycloak",
doIgnoreReleaseCandidates: true doIgnoreReleaseCandidates: true,
buildContext
}); });
semVersionedTags.forEach(semVersionedTag => { semVersionedTags.forEach(semVersionedTag => {

View File

@ -103,7 +103,7 @@ export async function command(params: { cliCommandOptions: CliCommandOptions })
const { keycloakVersion } = await promptKeycloakVersion({ const { keycloakVersion } = await promptKeycloakVersion({
startingFromMajor: 18, startingFromMajor: 18,
excludeMajorVersions: [22], excludeMajorVersions: [22],
cacheDirPath: buildContext.cacheDirPath buildContext
}); });
console.log(`${keycloakVersion}`); console.log(`${keycloakVersion}`);