cli load uses discourse key (#1326)
This commit modifies `cli/load` to appropriately load a Discourse key from the environment, if it is available. The mechanics are basically the same as with the GitHub token. Test plan: Unit tests added. `yarn test` passes.
This commit is contained in:
parent
243437f1cd
commit
b4463f2ab7
|
@ -23,3 +23,7 @@ export function sourcecredDirectory(): string {
|
||||||
export function githubToken(): string | null {
|
export function githubToken(): string | null {
|
||||||
return NullUtil.orElse(process.env.SOURCECRED_GITHUB_TOKEN, null);
|
return NullUtil.orElse(process.env.SOURCECRED_GITHUB_TOKEN, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function discourseKey(): string | null {
|
||||||
|
return NullUtil.orElse(process.env.SOURCECRED_DISCOURSE_KEY, null);
|
||||||
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import {
|
||||||
defaultSourcecredDirectory,
|
defaultSourcecredDirectory,
|
||||||
sourcecredDirectory,
|
sourcecredDirectory,
|
||||||
githubToken,
|
githubToken,
|
||||||
|
discourseKey,
|
||||||
} from "./common";
|
} from "./common";
|
||||||
|
|
||||||
describe("cli/common", () => {
|
describe("cli/common", () => {
|
||||||
|
@ -54,4 +55,15 @@ describe("cli/common", () => {
|
||||||
expect(githubToken()).toBe(null);
|
expect(githubToken()).toBe(null);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("discourseKey", () => {
|
||||||
|
it("uses the environment variable when available", () => {
|
||||||
|
process.env.SOURCECRED_DISCOURSE_KEY = "010101";
|
||||||
|
expect(discourseKey()).toEqual("010101");
|
||||||
|
});
|
||||||
|
it("returns `null` if the environment variable is not set", () => {
|
||||||
|
delete process.env.SOURCECRED_DISCOURSE_KEY;
|
||||||
|
expect(discourseKey()).toBe(null);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -110,7 +110,7 @@ const loadCommand: Command = async (args, std) => {
|
||||||
params,
|
params,
|
||||||
sourcecredDirectory: Common.sourcecredDirectory(),
|
sourcecredDirectory: Common.sourcecredDirectory(),
|
||||||
githubToken,
|
githubToken,
|
||||||
discourseKey: null,
|
discourseKey: Common.discourseKey(),
|
||||||
}));
|
}));
|
||||||
// Deliberately load in serial because GitHub requests that their API not
|
// Deliberately load in serial because GitHub requests that their API not
|
||||||
// be called concurrently
|
// be called concurrently
|
||||||
|
|
|
@ -27,10 +27,12 @@ describe("cli/load", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const fakeGithubToken = "....".replace(/./g, "0123456789");
|
const fakeGithubToken = "....".replace(/./g, "0123456789");
|
||||||
|
const fakeDiscourseKey = "abcdefg";
|
||||||
function newSourcecredDirectory() {
|
function newSourcecredDirectory() {
|
||||||
const dirname = tmp.dirSync().name;
|
const dirname = tmp.dirSync().name;
|
||||||
process.env.SOURCECRED_DIRECTORY = dirname;
|
process.env.SOURCECRED_DIRECTORY = dirname;
|
||||||
process.env.SOURCECRED_GITHUB_TOKEN = fakeGithubToken;
|
process.env.SOURCECRED_GITHUB_TOKEN = fakeGithubToken;
|
||||||
|
process.env.SOURCECRED_DISCOURSE_KEY = fakeDiscourseKey;
|
||||||
return dirname;
|
return dirname;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +79,7 @@ describe("cli/load", () => {
|
||||||
params: {alpha: 0.05, intervalDecay: 0.5, weights: defaultWeights()},
|
params: {alpha: 0.05, intervalDecay: 0.5, weights: defaultWeights()},
|
||||||
sourcecredDirectory: Common.sourcecredDirectory(),
|
sourcecredDirectory: Common.sourcecredDirectory(),
|
||||||
githubToken: fakeGithubToken,
|
githubToken: fakeGithubToken,
|
||||||
discourseKey: null,
|
discourseKey: fakeDiscourseKey,
|
||||||
};
|
};
|
||||||
expect(await invocation).toEqual({
|
expect(await invocation).toEqual({
|
||||||
exitCode: 0,
|
exitCode: 0,
|
||||||
|
@ -101,7 +103,7 @@ describe("cli/load", () => {
|
||||||
params: {alpha: 0.05, intervalDecay: 0.5, weights: defaultWeights()},
|
params: {alpha: 0.05, intervalDecay: 0.5, weights: defaultWeights()},
|
||||||
sourcecredDirectory: Common.sourcecredDirectory(),
|
sourcecredDirectory: Common.sourcecredDirectory(),
|
||||||
githubToken: fakeGithubToken,
|
githubToken: fakeGithubToken,
|
||||||
discourseKey: null,
|
discourseKey: fakeDiscourseKey,
|
||||||
});
|
});
|
||||||
expect(await invocation).toEqual({
|
expect(await invocation).toEqual({
|
||||||
exitCode: 0,
|
exitCode: 0,
|
||||||
|
@ -138,7 +140,7 @@ describe("cli/load", () => {
|
||||||
params: {alpha: 0.05, intervalDecay: 0.5, weights},
|
params: {alpha: 0.05, intervalDecay: 0.5, weights},
|
||||||
sourcecredDirectory: Common.sourcecredDirectory(),
|
sourcecredDirectory: Common.sourcecredDirectory(),
|
||||||
githubToken: fakeGithubToken,
|
githubToken: fakeGithubToken,
|
||||||
discourseKey: null,
|
discourseKey: fakeDiscourseKey,
|
||||||
};
|
};
|
||||||
expect(await invocation).toEqual({
|
expect(await invocation).toEqual({
|
||||||
exitCode: 0,
|
exitCode: 0,
|
||||||
|
|
Loading…
Reference in New Issue