Skip to content

Commit

Permalink
Merge pull request #2567 from github/NlightNFotis/feature_flag_fix
Browse files Browse the repository at this point in the history
Tolerate other GitHub variants when retrieving feature flags from GitHub API
  • Loading branch information
NlightNFotis authored Oct 25, 2024
2 parents b91f43b + fddb49d commit 3aa7135
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/feature-flags.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/feature-flags.js.map

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions lib/feature-flags.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/feature-flags.test.js.map

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions src/feature-flags.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];
Expand Down
5 changes: 4 additions & 1 deletion src/feature-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
);
Expand Down

0 comments on commit 3aa7135

Please sign in to comment.