Merge pull request #2567 from github/NlightNFotis/feature_flag_fix

Tolerate other GitHub variants when retrieving feature flags from GitHub API
This commit is contained in:
Fotis Koutoulakis 2024-10-25 17:38:31 +01:00 committed by GitHub
commit 3aa71356c7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 53 additions and 4 deletions

3
lib/feature-flags.js generated
View file

@ -346,7 +346,8 @@ class GitHubFeatureFlags {
}
async loadApiResponse() {
// Do nothing when not running against github.com
if (this.gitHubVersion.type !== util.GitHubVariant.DOTCOM) {
if (this.gitHubVersion.type !== util.GitHubVariant.DOTCOM &&
this.gitHubVersion.type !== util.GitHubVariant.GHE_DOTCOM) {
this.logger.debug("Not running against github.com. Disabling all toggleable features.");
this.hasAccessedRemoteFeatureFlags = false;
return {};

File diff suppressed because one or more lines are too long

View file

@ -53,6 +53,21 @@ const testRepositoryNwo = (0, repository_1.parseRepositoryNwo)("github/example")
"Not running against github.com. Disabling all toggleable features.") !== undefined);
});
});
(0, ava_1.default)(`Feature flags are requested in Proxima`, async (t) => {
await (0, util_1.withTmpDir)(async (tmpDir) => {
const loggedMessages = [];
const features = setUpFeatureFlagTests(tmpDir, (0, testing_utils_1.getRecordingLogger)(loggedMessages), { type: util_1.GitHubVariant.GHE_DOTCOM });
(0, testing_utils_1.mockFeatureFlagApiEndpoint)(200, initializeFeatures(true));
for (const feature of Object.values(feature_flags_1.Feature)) {
// Ensure we have gotten a response value back from the Mock API
t.assert(await features.getValue(feature, includeCodeQlIfRequired(feature)));
}
// And that we haven't bailed preemptively.
t.assert(loggedMessages.find((v) => v.type === "debug" &&
v.message ===
"Not running against github.com. Disabling all toggleable features.") === undefined);
});
});
(0, ava_1.default)("API response missing and features use default value", async (t) => {
await (0, util_1.withTmpDir)(async (tmpDir) => {
const loggedMessages = [];

File diff suppressed because one or more lines are too long

View file

@ -60,6 +60,36 @@ test(`All features are disabled if running against GHES`, async (t) => {
});
});
test(`Feature flags are requested in Proxima`, async (t) => {
await withTmpDir(async (tmpDir) => {
const loggedMessages = [];
const features = setUpFeatureFlagTests(
tmpDir,
getRecordingLogger(loggedMessages),
{ type: GitHubVariant.GHE_DOTCOM },
);
mockFeatureFlagApiEndpoint(200, initializeFeatures(true));
for (const feature of Object.values(Feature)) {
// Ensure we have gotten a response value back from the Mock API
t.assert(
await features.getValue(feature, includeCodeQlIfRequired(feature)),
);
}
// And that we haven't bailed preemptively.
t.assert(
loggedMessages.find(
(v: LoggedMessage) =>
v.type === "debug" &&
v.message ===
"Not running against github.com. Disabling all toggleable features.",
) === undefined,
);
});
});
test("API response missing and features use default value", async (t) => {
await withTmpDir(async (tmpDir) => {
const loggedMessages: LoggedMessage[] = [];

View file

@ -485,7 +485,10 @@ class GitHubFeatureFlags {
private async loadApiResponse(): Promise<GitHubFeatureFlagsApiResponse> {
// Do nothing when not running against github.com
if (this.gitHubVersion.type !== util.GitHubVariant.DOTCOM) {
if (
this.gitHubVersion.type !== util.GitHubVariant.DOTCOM &&
this.gitHubVersion.type !== util.GitHubVariant.GHE_DOTCOM
) {
this.logger.debug(
"Not running against github.com. Disabling all toggleable features.",
);