Skip to content

Commit

Permalink
Merge pull request #295 from chromaui/handle-netlify-git
Browse files Browse the repository at this point in the history
Gracefully handle git config command in Netlify
  • Loading branch information
ghengeveld committed Mar 11, 2021
2 parents 4fb5adc + 89c8662 commit 4edc95e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
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
6 changes: 4 additions & 2 deletions bin/tasks/gitInfo.js
Expand Up @@ -21,10 +21,12 @@ 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));
}

if (ctx.options.ownerName) {
if (ctx.git.slug && ctx.options.ownerName) {
ctx.git.slug = ctx.git.slug.replace(/[^/]+/, ctx.options.ownerName);
}

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.mockResolvedValue({ commit: '123asdf', branch: 'something' });
getBaselineCommits.mockResolvedValue(['asd2344']);
getVersion.mockResolvedValue('Git v1.0.0');
getSlug.mockResolvedValue('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.mockResolvedValue({ commit: '123asdf', branch: 'something' });
getBaselineCommits.mockResolvedValue(['asd2344']);
getVersion.mockResolvedValue('Git v1.0.0');
getSlug.mockResolvedValue('user/repo');
const ctx = { log, options: { ownerName: 'org' } };
await setGitInfo(ctx, {});
expect(ctx.git).toMatchObject({
Expand Down

0 comments on commit 4edc95e

Please sign in to comment.