Api refactor, propagate types
Signed-off-by: Erik Engervall <erik.engervall@gmail.com>
This commit is contained in:
+2
-2
@@ -42,8 +42,8 @@ import { useCreateReleaseCandidate } from './hooks/useCreateReleaseCandidate';
|
||||
import { useProjectContext } from '../../contexts/ProjectContext';
|
||||
|
||||
interface CreateReleaseCandidateProps {
|
||||
defaultBranch: GetRepositoryResult['defaultBranch'];
|
||||
latestRelease: GetLatestReleaseResult;
|
||||
defaultBranch: GetRepositoryResult['repository']['defaultBranch'];
|
||||
latestRelease: GetLatestReleaseResult['latestRelease'];
|
||||
releaseBranch: GetBranchResult | null;
|
||||
successCb?: ComponentConfigCreateRc['successCb'];
|
||||
}
|
||||
|
||||
+2
-2
@@ -32,8 +32,8 @@ import { useResponseSteps } from '../../../hooks/useResponseSteps';
|
||||
import { useUserContext } from '../../../contexts/UserContext';
|
||||
|
||||
interface UseCreateReleaseCandidate {
|
||||
defaultBranch: GetRepositoryResult['defaultBranch'];
|
||||
latestRelease: GetLatestReleaseResult;
|
||||
defaultBranch: GetRepositoryResult['repository']['defaultBranch'];
|
||||
latestRelease: GetLatestReleaseResult['latestRelease'];
|
||||
releaseCandidateGitInfo: ReturnType<typeof getReleaseCandidateGitInfo>;
|
||||
project: Project;
|
||||
successCb?: ComponentConfigCreateRc['successCb'];
|
||||
|
||||
@@ -31,7 +31,7 @@ import flowImage from './flow.png';
|
||||
|
||||
interface InfoCardProps {
|
||||
releaseBranch: GetBranchResult | null;
|
||||
latestRelease: GetLatestReleaseResult;
|
||||
latestRelease: GetLatestReleaseResult['latestRelease'];
|
||||
statsEnabled: boolean;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ import { PatchBody } from './PatchBody';
|
||||
import { useProjectContext } from '../../contexts/ProjectContext';
|
||||
|
||||
interface PatchProps {
|
||||
latestRelease: GetLatestReleaseResult;
|
||||
latestRelease: GetLatestReleaseResult['latestRelease'];
|
||||
releaseBranch: GetBranchResult | null;
|
||||
successCb?: ComponentConfigPatch['successCb'];
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ import { useProjectContext } from '../../contexts/ProjectContext';
|
||||
|
||||
interface PatchBodyProps {
|
||||
bumpedTag: string;
|
||||
latestRelease: NonNullable<GetLatestReleaseResult>;
|
||||
latestRelease: NonNullable<GetLatestReleaseResult['latestRelease']>;
|
||||
releaseBranch: GetBranchResult;
|
||||
successCb?: ComponentConfigPatch['successCb'];
|
||||
tagParts: NonNullable<CalverTagParts | SemverTagParts>;
|
||||
|
||||
@@ -34,7 +34,7 @@ import { useUserContext } from '../../../contexts/UserContext';
|
||||
|
||||
interface Patch {
|
||||
bumpedTag: string;
|
||||
latestRelease: NonNullable<GetLatestReleaseResult>;
|
||||
latestRelease: NonNullable<GetLatestReleaseResult['latestRelease']>;
|
||||
project: Project;
|
||||
tagParts: NonNullable<CalverTagParts | SemverTagParts>;
|
||||
successCb?: ComponentConfigPatch['successCb'];
|
||||
|
||||
@@ -26,7 +26,7 @@ import { PromoteRcBody } from './PromoteRcBody';
|
||||
import { TEST_IDS } from '../../test-helpers/test-ids';
|
||||
|
||||
interface PromoteRcProps {
|
||||
latestRelease: GetLatestReleaseResult;
|
||||
latestRelease: GetLatestReleaseResult['latestRelease'];
|
||||
successCb?: ComponentConfigPromoteRc['successCb'];
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ import { TEST_IDS } from '../../test-helpers/test-ids';
|
||||
import { usePromoteRc } from './hooks/usePromoteRc';
|
||||
|
||||
interface PromoteRcBodyProps {
|
||||
rcRelease: NonNullable<GetLatestReleaseResult>;
|
||||
rcRelease: NonNullable<GetLatestReleaseResult['latestRelease']>;
|
||||
successCb?: ComponentConfigPromoteRc['successCb'];
|
||||
}
|
||||
|
||||
|
||||
@@ -21,14 +21,14 @@ import { useApi } from '@backstage/core';
|
||||
import { CardHook, ComponentConfigPromoteRc } from '../../../types/types';
|
||||
import { GetLatestReleaseResult } from '../../../api/GitReleaseApiClient';
|
||||
import { gitReleaseManagerApiRef } from '../../../api/serviceApiRef';
|
||||
import { GitReleaseManagerError } from '../../../errors/GitReleaseManagerError';
|
||||
import { TAG_OBJECT_MESSAGE } from '../../../constants/constants';
|
||||
import { useProjectContext } from '../../../contexts/ProjectContext';
|
||||
import { useResponseSteps } from '../../../hooks/useResponseSteps';
|
||||
import { useUserContext } from '../../../contexts/UserContext';
|
||||
import { TAG_OBJECT_MESSAGE } from '../../../constants/constants';
|
||||
import { GitReleaseManagerError } from '../../../errors/GitReleaseManagerError';
|
||||
|
||||
interface PromoteRc {
|
||||
rcRelease: NonNullable<GetLatestReleaseResult>;
|
||||
rcRelease: NonNullable<GetLatestReleaseResult['latestRelease']>;
|
||||
releaseVersion: string;
|
||||
successCb?: ComponentConfigPromoteRc['successCb'];
|
||||
}
|
||||
|
||||
@@ -22,17 +22,19 @@ import { getSemverTagParts } from './tagParts/getSemverTagParts';
|
||||
import { Project } from '../contexts/ProjectContext';
|
||||
import { SEMVER_PARTS } from '../constants/constants';
|
||||
|
||||
interface GetReleaseCandidateGitInfo {
|
||||
project: Project;
|
||||
latestRelease: GetLatestReleaseResult['latestRelease'];
|
||||
semverBumpLevel: keyof typeof SEMVER_PARTS;
|
||||
injectedDate?: string;
|
||||
}
|
||||
|
||||
export const getReleaseCandidateGitInfo = ({
|
||||
project,
|
||||
latestRelease,
|
||||
semverBumpLevel,
|
||||
injectedDate = DateTime.now().toFormat('yyyy.MM.dd'),
|
||||
}: {
|
||||
project: Project;
|
||||
latestRelease: GetLatestReleaseResult;
|
||||
semverBumpLevel: keyof typeof SEMVER_PARTS;
|
||||
injectedDate?: string;
|
||||
}) => {
|
||||
}: GetReleaseCandidateGitInfo) => {
|
||||
if (project.versioningStrategy === 'calver') {
|
||||
return {
|
||||
rcBranch: `rc/${injectedDate}`,
|
||||
|
||||
@@ -31,10 +31,10 @@ describe('validateTagName', () => {
|
||||
});
|
||||
|
||||
expect(result).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"tagNameError": undefined,
|
||||
}
|
||||
`);
|
||||
Object {
|
||||
"tagNameError": undefined,
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
it('should not return any error for semver project without any releases (i.e. no tagName)', () => {
|
||||
@@ -74,13 +74,13 @@ describe('validateTagName', () => {
|
||||
});
|
||||
|
||||
expect(result).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"tagNameError": Object {
|
||||
"subtitle": "Expected calver matching \\"/(rc|version)-([0-9]{4}\\\\.[0-9]{2}\\\\.[0-9]{2})_([0-9]+)/\\", found \\"rc-1.2.3\\"",
|
||||
"title": "Invalid tag",
|
||||
},
|
||||
}
|
||||
`);
|
||||
Object {
|
||||
"tagNameError": Object {
|
||||
"subtitle": "Expected calver matching \\"/(rc|version)-([0-9]{4}\\\\.[0-9]{2}\\\\.[0-9]{2})_([0-9]+)/\\", found \\"rc-1.2.3\\"",
|
||||
"title": "Invalid tag",
|
||||
},
|
||||
}
|
||||
`);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -86,16 +86,8 @@ describe('useGetHubBatchInfo', () => {
|
||||
|
||||
expect(result.current.gitBatchInfo).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"error": [TypeError: Cannot read property 'latestRelease' of null],
|
||||
"loading": false,
|
||||
"value": Object {
|
||||
"latestRelease": null,
|
||||
"releaseBranch": null,
|
||||
"repository": Object {
|
||||
"defaultBranch": "mock_defaultBranch",
|
||||
"name": "mock_repo",
|
||||
"pushPermissions": true,
|
||||
},
|
||||
},
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
@@ -98,15 +98,13 @@ const createMockRelease = ({
|
||||
...rest
|
||||
}: Partial<
|
||||
NonNullable<GetLatestReleaseResult['latestRelease']>
|
||||
> = {}): NonNullable<GetLatestReleaseResult> => ({
|
||||
latestRelease: {
|
||||
id,
|
||||
htmlUrl: 'mock_release_html_url',
|
||||
prerelease,
|
||||
tagName: MOCK_RELEASE_CANDIDATE_TAG_NAME_CALVER,
|
||||
targetCommitish: MOCK_RELEASE_BRANCH_NAME_CALVER,
|
||||
...rest,
|
||||
},
|
||||
> = {}): NonNullable<GetLatestReleaseResult['latestRelease']> => ({
|
||||
id,
|
||||
htmlUrl: 'mock_release_html_url',
|
||||
prerelease,
|
||||
tagName: MOCK_RELEASE_CANDIDATE_TAG_NAME_CALVER,
|
||||
targetCommitish: MOCK_RELEASE_BRANCH_NAME_CALVER,
|
||||
...rest,
|
||||
});
|
||||
|
||||
export const mockReleaseCandidateCalver = createMockRelease({
|
||||
@@ -207,7 +205,9 @@ export const mockApiClient: GitReleaseApi = {
|
||||
],
|
||||
})),
|
||||
|
||||
getLatestRelease: jest.fn(async () => createMockRelease()),
|
||||
getLatestRelease: jest.fn(async () => ({
|
||||
latestRelease: createMockRelease(),
|
||||
})),
|
||||
|
||||
getRepository: jest.fn(async () => ({
|
||||
repository: {
|
||||
|
||||
Reference in New Issue
Block a user