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:
commit
3aa71356c7
6 changed files with 53 additions and 4 deletions
3
lib/feature-flags.js
generated
3
lib/feature-flags.js
generated
|
|
@ -346,7 +346,8 @@ class GitHubFeatureFlags {
|
||||||
}
|
}
|
||||||
async loadApiResponse() {
|
async loadApiResponse() {
|
||||||
// Do nothing when not running against github.com
|
// 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.logger.debug("Not running against github.com. Disabling all toggleable features.");
|
||||||
this.hasAccessedRemoteFeatureFlags = false;
|
this.hasAccessedRemoteFeatureFlags = false;
|
||||||
return {};
|
return {};
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
15
lib/feature-flags.test.js
generated
15
lib/feature-flags.test.js
generated
|
|
@ -53,6 +53,21 @@ const testRepositoryNwo = (0, repository_1.parseRepositoryNwo)("github/example")
|
||||||
"Not running against github.com. Disabling all toggleable features.") !== undefined);
|
"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) => {
|
(0, ava_1.default)("API response missing and features use default value", async (t) => {
|
||||||
await (0, util_1.withTmpDir)(async (tmpDir) => {
|
await (0, util_1.withTmpDir)(async (tmpDir) => {
|
||||||
const loggedMessages = [];
|
const loggedMessages = [];
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -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) => {
|
test("API response missing and features use default value", async (t) => {
|
||||||
await withTmpDir(async (tmpDir) => {
|
await withTmpDir(async (tmpDir) => {
|
||||||
const loggedMessages: LoggedMessage[] = [];
|
const loggedMessages: LoggedMessage[] = [];
|
||||||
|
|
|
||||||
|
|
@ -485,7 +485,10 @@ class GitHubFeatureFlags {
|
||||||
|
|
||||||
private async loadApiResponse(): Promise<GitHubFeatureFlagsApiResponse> {
|
private async loadApiResponse(): Promise<GitHubFeatureFlagsApiResponse> {
|
||||||
// Do nothing when not running against github.com
|
// 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(
|
this.logger.debug(
|
||||||
"Not running against github.com. Disabling all toggleable features.",
|
"Not running against github.com. Disabling all toggleable features.",
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue