Explicitly pass repository to feature flags constructor

As suggested in review: The `GITHUB_REPOSITORY` environment variable is
only available on Actions. Passing it in explicitly avoids potentially
crashing if this code is called from the runner.
This commit is contained in:
Henry Mercer 2021-12-15 17:03:43 +00:00
parent 621e0794ac
commit 5e87034b3b
9 changed files with 31 additions and 33 deletions

View file

@ -6,6 +6,7 @@ import * as apiClient from "./api-client";
import { GitHubApiDetails } from "./api-client";
import { GitHubFeatureFlags } from "./feature-flags";
import { getRunnerLogger } from "./logging";
import { parseRepositoryNwo } from "./repository";
import {
getRecordingLogger,
LoggedMessage,
@ -25,11 +26,6 @@ setupTests(test);
test.beforeEach(() => {
initializeEnvironment(Mode.actions, "1.2.3");
sinon
.stub(util, "getRequiredEnvParam")
.withArgs("GITHUB_REPOSITORY")
.returns("github/example");
});
const testApiDetails: GitHubApiDetails = {
@ -37,6 +33,8 @@ const testApiDetails: GitHubApiDetails = {
url: "https://github.com",
};
const testRepositoryNwo = parseRepositoryNwo("github/example");
function mockHttpRequests(
responseStatusCode: number,
flags: { [flagName: string]: boolean }
@ -83,6 +81,7 @@ for (const variant of ALL_FEATURE_FLAGS_DISABLED_VARIANTS) {
const featureFlags = new GitHubFeatureFlags(
variant.gitHubVersion,
testApiDetails,
testRepositoryNwo,
getRecordingLogger(loggedMessages)
);
@ -110,6 +109,7 @@ test("Feature flags are disabled if they're not returned in API response", async
const featureFlags = new GitHubFeatureFlags(
{ type: GitHubVariant.DOTCOM },
testApiDetails,
testRepositoryNwo,
getRecordingLogger(loggedMessages)
);
@ -143,6 +143,7 @@ test("Feature flags exception is propagated if the API request errors", async (t
const featureFlags = new GitHubFeatureFlags(
{ type: GitHubVariant.DOTCOM },
testApiDetails,
testRepositoryNwo,
getRunnerLogger(true)
);
@ -169,6 +170,7 @@ for (const featureFlag of FEATURE_FLAGS) {
const featureFlags = new GitHubFeatureFlags(
{ type: GitHubVariant.DOTCOM },
testApiDetails,
testRepositoryNwo,
getRunnerLogger(true)
);