Api refactor, return object for getCommit

Signed-off-by: Erik Engervall <erik.engervall@gmail.com>
This commit is contained in:
Erik Engervall
2021-04-30 14:07:04 +02:00
parent 6854dcd9e1
commit 71943aad09
5 changed files with 28 additions and 25 deletions
@@ -213,12 +213,14 @@ export class GitReleaseApiClient implements GitReleaseApi {
});
return {
sha: latestCommit.sha,
htmlUrl: latestCommit.html_url,
commit: {
message: latestCommit.commit.message,
sha: latestCommit.sha,
htmlUrl: latestCommit.html_url,
commit: {
message: latestCommit.commit.message,
},
createdAt: latestCommit.commit.committer?.date,
},
createdAt: latestCommit.commit.committer?.date,
};
};
@@ -568,12 +570,14 @@ export interface GitReleaseApi {
ref: string;
} & OwnerRepo,
) => Promise<{
sha: string;
htmlUrl: string;
commit: {
message: string;
sha: string;
htmlUrl: string;
commit: {
message: string;
};
createdAt?: string;
};
createdAt?: string;
}>;
getBranch: (
@@ -70,7 +70,7 @@ export function useCreateReleaseCandidate({
* (1) Get the default branch's most recent commit
*/
const [latestCommitRes, run] = useAsyncFn(async () => {
const latestCommit = await pluginApiClient
const { commit: latestCommit } = await pluginApiClient
.getCommit({
owner: project.owner,
repo: project.repo,
@@ -52,7 +52,7 @@ export function usePromoteRc({
* (1) Fetch most recent release branch commit
*/
const [latestReleaseBranchCommitSha, run] = useAsyncFn(async () => {
const latestCommit = await pluginApiClient
const { commit: latestCommit } = await pluginApiClient
.getCommit({
owner: project.owner,
repo: project.repo,
@@ -58,10 +58,7 @@ export const getTagDates = async ({
}
if (startTag.tagType === 'commit' && endTag.tagType === 'commit') {
const [
{ createdAt: startDate },
{ createdAt: endDate },
] = await Promise.all([
const [{ commit: startCommit }, { commit: endCommit }] = await Promise.all([
pluginApiClient.getCommit({
owner: project.owner,
repo: project.repo,
@@ -75,13 +72,13 @@ export const getTagDates = async ({
]);
return {
startDate,
endDate,
startDate: startCommit.createdAt,
endDate: endCommit.createdAt,
};
}
if (startTag.tagType === 'tag' && endTag.tagType === 'commit') {
const [{ date: startDate }, { createdAt: endDate }] = await Promise.all([
const [{ date: startDate }, { commit: endCommit }] = await Promise.all([
getCommitFromTag({ pluginApiClient, project, tag: startTag }),
pluginApiClient.getCommit({
owner: project.owner,
@@ -92,12 +89,12 @@ export const getTagDates = async ({
return {
startDate,
endDate,
endDate: endCommit.createdAt,
};
}
if (startTag.tagType === 'commit' && endTag.tagType === 'tag') {
const [{ createdAt: startDate }, { date: endDate }] = await Promise.all([
const [{ commit: startCommit }, { date: endDate }] = await Promise.all([
pluginApiClient.getCommit({
owner: project.owner,
repo: project.repo,
@@ -107,7 +104,7 @@ export const getTagDates = async ({
]);
return {
startDate,
startDate: startCommit.createdAt,
endDate,
};
}
@@ -131,7 +128,7 @@ async function getCommitFromTag({
repo: project.repo,
tagSha: tag.tagSha,
});
const startCommit = await pluginApiClient.getCommit({
const { commit: startCommit } = await pluginApiClient.getCommit({
owner: project.owner,
repo: project.repo,
ref: singleTag.objectSha,
@@ -218,12 +218,14 @@ export const mockApiClient: GitReleaseApi = {
})),
getCommit: jest.fn(async () => ({
sha: 'latestCommit.sha',
htmlUrl: 'latestCommit.html_url',
commit: {
message: 'latestCommit.commit.message',
sha: 'latestCommit.sha',
htmlUrl: 'latestCommit.html_url',
commit: {
message: 'latestCommit.commit.message',
},
createdAt: '2021-01-01T10:11:12Z',
},
createdAt: '2021-01-01T10:11:12Z',
})),
getBranch: jest.fn(async () => ({