Api refactor, return object for getAllTags

Signed-off-by: Erik Engervall <erik.engervall@gmail.com>
This commit is contained in:
Erik Engervall
2021-04-30 14:21:48 +02:00
parent 28bcc9f4e4
commit de28d4e07c
4 changed files with 24 additions and 20 deletions
@@ -457,13 +457,15 @@ export class GitReleaseApiClient implements GitReleaseApi {
...DISABLE_CACHE,
});
return tags
.map(tag => ({
tagName: tag.ref.replace('refs/tags/', ''),
tagSha: tag.object.sha,
tagType: tag.object.type as 'tag' | 'commit',
}))
.reverse();
return {
tags: tags
.map(tag => ({
tagName: tag.ref.replace('refs/tags/', ''),
tagSha: tag.object.sha,
tagType: tag.object.type as 'tag' | 'commit',
}))
.reverse(),
};
};
getAllReleases: GitReleaseApi['getAllReleases'] = async ({ owner, repo }) => {
@@ -728,13 +730,13 @@ export interface GitReleaseApi {
*/
getAllTags: (
args: OwnerRepo,
) => Promise<
Array<{
) => Promise<{
tags: Array<{
tagName: string;
tagSha: string;
tagType: 'tag' | 'commit';
}>
>;
}>;
}>;
getAllReleases: (
args: OwnerRepo,
@@ -25,7 +25,7 @@ export function getReleaseStats({
project,
mappedReleases,
}: {
allTags: GetAllTagsResult;
allTags: GetAllTagsResult['tags'];
project: Project;
mappedReleases: ReleaseStats;
}) {
@@ -25,7 +25,7 @@ export const useGetStats = () => {
const { project } = useProjectContext();
const stats = useAsync(async () => {
const [allReleases, allTags] = await Promise.all([
const [allReleases, { tags: allTags }] = await Promise.all([
pluginApiClient.getAllReleases({
owner: project.owner,
repo: project.repo,
@@ -293,13 +293,15 @@ export const mockApiClient: GitReleaseApi = {
},
})),
getAllTags: jest.fn(async () => [
{
tagName: MOCK_RELEASE_CANDIDATE_TAG_NAME_CALVER,
tagSha: 'mock_sha',
tagType: 'tag' as const,
},
]),
getAllTags: jest.fn(async () => ({
tags: [
{
tagName: MOCK_RELEASE_CANDIDATE_TAG_NAME_CALVER,
tagSha: 'mock_sha',
tagType: 'tag' as const,
},
],
})),
getAllReleases: jest.fn(async () => [
{