Skip to content

Commit

Permalink
Merge pull request #315 from ahrbil/fix/commit-date-with-different-ti…
Browse files Browse the repository at this point in the history
…me-zone

fix(core): fix parsing commit date with different time zone
  • Loading branch information
ghiscoding committed Aug 24, 2022
2 parents f618ae9 + eb1f653 commit b120a90
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ describe('getOldestCommitSinceLastTag', () => {
});
});

afterEach(() => {
(execSync as jest.Mock).mockReset();
});

it('should expect a tag date & hash but queried with a particular tag match pattern when using independent mode', async () => {
const isIndependent = true;
const mockExecSyncResult = '"deadabcd 2022-07-01T00:01:02-06:00"';
Expand All @@ -132,5 +136,20 @@ describe('getOldestCommitSinceLastTag', () => {
);
expect(result).toEqual({ commitDate: '2022-07-01T00:01:02-06:00', commitHash: 'deadabcd' });
});

it('should expect a commit date and hash when using different time zone', async () => {
const isIndependent = true;
(execSync as jest.Mock).mockReturnValue('"deadbeef 2022-07-01T00:01:02+01:00"');
const result = await getOldestCommitSinceLastTag(execOpts, isIndependent, false);
const execSpy = (execSync as jest.Mock).mockReturnValueOnce('"deadbeef 2022-07-01T00:01:02+01:00"');

expect(describeRefSync).toHaveBeenCalledWith({ cwd: '/test', match: '*@*' }, false);
expect(execSpy).toHaveBeenCalledWith(
'git',
['log', '@my-workspace/pkg-a@2.0.3..HEAD', '--format="%h %aI"', '--reverse'],
execOpts
);
expect(result).toEqual({ commitDate: '2022-07-01T00:01:02+01:00', commitHash: 'deadbeef' });
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export function getOldestCommitSinceLastTag(execOpts?: ExecOpts, isIndependent?:
commitResult = execSync('git', gitCommandArgs, execOpts);
}

const [, commitHash, commitDate] = /^"?([0-9a-f]+)\s([0-9\-T\:]*)"?$/.exec(commitResult) || [];
const [, commitHash, commitDate] = /^"?([0-9a-f]+)\s([0-9\-|\+T\:]*)"?$/.exec(commitResult) || [];
// prettier-ignore
log.info('oldestCommitSinceLastTag', `commit found since last tag: ${lastTagName} - (SHA) ${commitHash} - ${commitDate}`);

Expand Down

0 comments on commit b120a90

Please sign in to comment.