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

Gracefully handle git config command in Netlify #295

Merged
merged 6 commits into from Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 12 additions & 11 deletions bin/main.test.js
Expand Up @@ -127,17 +127,18 @@ fs.statSync = jest.fn((path) => {
});

jest.mock('./git/git', () => ({
hasPreviousCommit: () => true,
getCommit: () => ({
commit: 'commit',
committedAt: 1234,
committerEmail: 'test@test.com',
committerName: 'tester',
}),
getBranch: () => 'branch',
getBaselineCommits: () => ['baseline'],
getSlug: () => 'user/repo',
getVersion: () => '2.24.1',
hasPreviousCommit: () => Promise.resolve(true),
getCommit: () =>
Promise.resolve({
commit: 'commit',
committedAt: 1234,
committerEmail: 'test@test.com',
committerName: 'tester',
}),
getBranch: () => Promise.resolve('branch'),
getBaselineCommits: () => Promise.resolve(['baseline']),
getSlug: () => Promise.resolve('user/repo'),
getVersion: () => Promise.resolve('2.24.1'),
}));

jest.mock('./lib/startStorybook');
Expand Down
4 changes: 3 additions & 1 deletion bin/tasks/gitInfo.js
Expand Up @@ -21,8 +21,10 @@ const TesterSkipBuildMutation = `
export const setGitInfo = async (ctx, task) => {
const { branchName, patchBaseRef, fromCI: ci } = ctx.options;
ctx.git = await getCommitAndBranch({ branchName, patchBaseRef, ci, log: ctx.log });
ctx.git.slug = ctx.git.slug || (await getSlug());
ctx.git.version = await getVersion();
if (!ctx.git.slug) {
ctx.git.slug = await getSlug().catch((e) => ctx.log.warn('Failed to retrieve slug', e));
}
ghengeveld marked this conversation as resolved.
Show resolved Hide resolved

if (ctx.options.ownerName) {
ctx.git.slug = ctx.git.slug.replace(/[^/]+/, ctx.options.ownerName);
ghengeveld marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
16 changes: 8 additions & 8 deletions bin/tasks/gitInfo.test.js
Expand Up @@ -9,10 +9,10 @@ const log = { debug: jest.fn() };

describe('setGitInfo', () => {
it('sets the git info on context', async () => {
getCommitAndBranch.mockReturnValue({ commit: '123asdf', branch: 'something' });
getBaselineCommits.mockReturnValue(['asd2344']);
getVersion.mockReturnValue('Git v1.0.0');
getSlug.mockReturnValue('user/repo');
getCommitAndBranch.mockReturnValue(Promise.resolve({ commit: '123asdf', branch: 'something' }));
ghengeveld marked this conversation as resolved.
Show resolved Hide resolved
getBaselineCommits.mockReturnValue(Promise.resolve(['asd2344']));
getVersion.mockReturnValue(Promise.resolve('Git v1.0.0'));
getSlug.mockReturnValue(Promise.resolve('user/repo'));
const ctx = { log, options: {} };
await setGitInfo(ctx, {});
expect(ctx.git).toMatchObject({
Expand All @@ -25,10 +25,10 @@ describe('setGitInfo', () => {
});

it('supports overriding the owner name in the slug', async () => {
getCommitAndBranch.mockReturnValue({ commit: '123asdf', branch: 'something' });
getBaselineCommits.mockReturnValue(['asd2344']);
getVersion.mockReturnValue('Git v1.0.0');
getSlug.mockReturnValue('user/repo');
getCommitAndBranch.mockReturnValue(Promise.resolve({ commit: '123asdf', branch: 'something' }));
getBaselineCommits.mockReturnValue(Promise.resolve(['asd2344']));
getVersion.mockReturnValue(Promise.resolve('Git v1.0.0'));
getSlug.mockReturnValue(Promise.resolve('user/repo'));
const ctx = { log, options: { ownerName: 'org' } };
await setGitInfo(ctx, {});
expect(ctx.git).toMatchObject({
Expand Down