Add condition in getTagDates for when endTag is undefined
Signed-off-by: Erik Engervall <erik.engervall@gmail.com>
This commit is contained in:
@@ -23,7 +23,54 @@ import {
|
||||
import { getTagDates } from './getTagDates';
|
||||
|
||||
describe('getTagDates', () => {
|
||||
beforeEach(jest.clearAllMocks);
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
jest.resetAllMocks();
|
||||
});
|
||||
|
||||
it('should get tag dates for startTag when is tag and endTag is undefined', async () => {
|
||||
(mockApiClient.getTag as jest.Mock).mockResolvedValueOnce(
|
||||
createMockTag({ date: 'TAG-START' }),
|
||||
);
|
||||
|
||||
const result = await getTagDates({
|
||||
pluginApiClient: mockApiClient,
|
||||
project: mockSemverProject,
|
||||
startTag: {
|
||||
tagSha: 'sha-start',
|
||||
tagType: 'tag',
|
||||
},
|
||||
});
|
||||
|
||||
expect(result).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"endDate": undefined,
|
||||
"startDate": "TAG-START",
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
it('should get tag dates for startTag when startTag is commit and endTag is undefined', async () => {
|
||||
(mockApiClient.getCommit as jest.Mock).mockResolvedValueOnce(
|
||||
createMockCommit({ createdAt: 'COMMIT_START' }),
|
||||
);
|
||||
|
||||
const result = await getTagDates({
|
||||
pluginApiClient: mockApiClient,
|
||||
project: mockSemverProject,
|
||||
startTag: {
|
||||
tagSha: 'sha-start',
|
||||
tagType: 'commit',
|
||||
},
|
||||
});
|
||||
|
||||
expect(result).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"endDate": undefined,
|
||||
"startDate": "COMMIT_START",
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
it('should get tag dates when startTag & endTag both are of type tag', async () => {
|
||||
(mockApiClient.getTag as jest.Mock)
|
||||
|
||||
@@ -25,7 +25,7 @@ interface GetTagDates {
|
||||
tagSha: string;
|
||||
tagType: 'tag' | 'commit';
|
||||
};
|
||||
endTag: {
|
||||
endTag?: {
|
||||
tagSha: string;
|
||||
tagType: 'tag' | 'commit';
|
||||
};
|
||||
@@ -37,6 +37,33 @@ export const getTagDates = async ({
|
||||
startTag,
|
||||
endTag,
|
||||
}: GetTagDates) => {
|
||||
if (!endTag) {
|
||||
if (startTag.tagType === 'tag') {
|
||||
const { tag: startTagResponse } = await pluginApiClient.getTag({
|
||||
owner: project.owner,
|
||||
repo: project.repo,
|
||||
tagSha: startTag.tagSha,
|
||||
});
|
||||
|
||||
return {
|
||||
startDate: startTagResponse.date,
|
||||
endDate: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
// If tagType is not a 'tag', it has to be a commit
|
||||
const { commit: startCommit } = await pluginApiClient.getCommit({
|
||||
owner: project.owner,
|
||||
repo: project.repo,
|
||||
ref: startTag.tagSha,
|
||||
});
|
||||
|
||||
return {
|
||||
startDate: startCommit.createdAt,
|
||||
endDate: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
if (startTag.tagType === 'tag' && endTag.tagType === 'tag') {
|
||||
const [
|
||||
{ tag: startTagResponse },
|
||||
@@ -124,7 +151,7 @@ async function getCommitFromTag({
|
||||
}: {
|
||||
pluginApiClient: GetTagDates['pluginApiClient'];
|
||||
project: GetTagDates['project'];
|
||||
tag: GetTagDates['startTag'] | GetTagDates['endTag'];
|
||||
tag: GetTagDates['startTag'] | NonNullable<GetTagDates['endTag']>;
|
||||
}) {
|
||||
const { tag: tagResponse } = await pluginApiClient.getTag({
|
||||
owner: project.owner,
|
||||
|
||||
Reference in New Issue
Block a user