Skip to content
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

Fix migrations #553

Merged
merged 1 commit into from
Jul 27, 2023
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
12 changes: 12 additions & 0 deletions src/config/loadGitHubOrgs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,16 @@ describe('loadGitHubOrgs', function () {
"ENOENT: no such file or directory, open 'test/nope-no-file-here-nada-zippo-zilch.yml'"
);
});

it('works with knex migrations', async function () {
const orig = process.cwd;
process.cwd = jest.fn(() => '/blah/blah/blah/src');
const curdir = orig().split('/').pop();
const orgs = loadGitHubOrgs({
GH_ORGS_YML: `${curdir}/test/github-orgs.good.yml`,
});
expect(orgs.get('hurple').appAuth.appId).toEqual(42);
expect(process.cwd).toHaveBeenCalled();
process.cwd = orig;
});
});
10 changes: 9 additions & 1 deletion src/config/loadGitHubOrgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,16 @@ export class GitHubOrgs {

export function loadGitHubOrgs(env) {
let configs = {};
const filepath = env.GH_ORGS_YML || 'github-orgs.yml';
let filepath = env.GH_ORGS_YML || 'github-orgs.yml';
if (filepath) {
if (process.cwd().endsWith('/src')) {
// GH_ORGS_YML assumes that cwd is the project root, so work around Knex
// migrations cd'ing into the directory of the knexfile.ts. We could do
// something fancier to protect against the general case, but let's keep
// it simple for now.

filepath = '../' + filepath;
}
configs = yaml.load(fs.readFileSync(filepath));
}

Expand Down
Loading