Skip to content

Tolerate other GitHub variants when retrieving feature flags from GitHub API #2567

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 25, 2024
Merged
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
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
Loading