Rename successCb to onSuccess

Signed-off-by: Erik Engervall <erik.engervall@gmail.com>
This commit is contained in:
Erik Engervall
2021-05-05 17:10:00 +02:00
parent 1005c8c2af
commit 24346f2dce
14 changed files with 52 additions and 52 deletions
+1 -1
View File
@@ -79,7 +79,7 @@ createDevApp()
}}
features={{
createRc: {
successCb: ({
onSuccess: ({
comparisonUrl,
createdTag,
gitReleaseName,
@@ -45,7 +45,7 @@ interface CreateReleaseCandidateProps {
defaultBranch: GetRepositoryResult['repository']['defaultBranch'];
latestRelease: GetLatestReleaseResult['latestRelease'];
releaseBranch: GetBranchResult['branch'] | null;
successCb?: ComponentConfigCreateRc['successCb'];
onSuccess?: ComponentConfigCreateRc['onSuccess'];
}
const InfoCardPlusWrapper = ({ children }: { children: React.ReactNode }) => {
@@ -63,7 +63,7 @@ export const CreateReleaseCandidate = ({
defaultBranch,
latestRelease,
releaseBranch,
successCb,
onSuccess,
}: CreateReleaseCandidateProps) => {
const { project } = useProjectContext();
@@ -90,7 +90,7 @@ export const CreateReleaseCandidate = ({
latestRelease,
releaseCandidateGitInfo,
project,
successCb,
onSuccess,
});
if (responseSteps.length > 0) {
return (
@@ -56,14 +56,14 @@ describe('useCreateReleaseCandidate', () => {
expect(result.current.responseSteps).toHaveLength(6);
});
it('should return the expected responseSteps and progress (with successCb)', async () => {
it('should return the expected responseSteps and progress (with onSuccess)', async () => {
const { result } = renderHook(() =>
useCreateReleaseCandidate({
defaultBranch: mockDefaultBranch,
latestRelease: mockReleaseVersionCalver,
releaseCandidateGitInfo: mockNextGitInfoCalver,
project: mockCalverProject,
successCb: jest.fn(),
onSuccess: jest.fn(),
}),
);
@@ -36,7 +36,7 @@ interface UseCreateReleaseCandidate {
latestRelease: GetLatestReleaseResult['latestRelease'];
releaseCandidateGitInfo: ReturnType<typeof getReleaseCandidateGitInfo>;
project: Project;
successCb?: ComponentConfigCreateRc['successCb'];
onSuccess?: ComponentConfigCreateRc['onSuccess'];
}
export function useCreateReleaseCandidate({
@@ -44,7 +44,7 @@ export function useCreateReleaseCandidate({
latestRelease,
releaseCandidateGitInfo,
project,
successCb,
onSuccess,
}: UseCreateReleaseCandidate): CardHook<void> {
const pluginApiClient = useApi(gitReleaseManagerApiRef);
const { user } = useUserContext();
@@ -258,14 +258,14 @@ export function useCreateReleaseCandidate({
}, [getComparisonRes.value, getComparisonRes.error]);
/**
* (7) Run successCb if defined
* (7) Run onSuccess if defined
*/
useAsync(async () => {
if (successCb && !!createReleaseRes.value && !!getComparisonRes.value) {
if (onSuccess && !!createReleaseRes.value && !!getComparisonRes.value) {
abortIfError(createReleaseRes.error);
try {
await successCb({
await onSuccess({
comparisonUrl: getComparisonRes.value.htmlUrl,
createdTag: createReleaseRes.value.tagName,
gitReleaseName: createReleaseRes.value.name,
@@ -283,7 +283,7 @@ export function useCreateReleaseCandidate({
}
}, [createReleaseRes.value]);
const TOTAL_STEPS = 6 + (!!successCb ? 1 : 0);
const TOTAL_STEPS = 6 + (!!onSuccess ? 1 : 0);
const [progress, setProgress] = useState(0);
useEffect(() => {
setProgress((responseSteps.length / TOTAL_STEPS) * 100);
@@ -125,14 +125,14 @@ export function Features({
latestRelease={gitBatchInfo.value.latestRelease}
releaseBranch={gitBatchInfo.value.releaseBranch}
defaultBranch={gitBatchInfo.value.repository.defaultBranch}
successCb={features?.createRc?.successCb}
onSuccess={features?.createRc?.onSuccess}
/>
)}
{!features?.promoteRc?.omit && (
<PromoteRc
latestRelease={gitBatchInfo.value.latestRelease}
successCb={features?.promoteRc?.successCb}
onSuccess={features?.promoteRc?.onSuccess}
/>
)}
@@ -140,7 +140,7 @@ export function Features({
<Patch
latestRelease={gitBatchInfo.value.latestRelease}
releaseBranch={gitBatchInfo.value.releaseBranch}
successCb={features?.patch?.successCb}
onSuccess={features?.patch?.onSuccess}
/>
)}
</ErrorBoundary>
@@ -32,13 +32,13 @@ import { useProjectContext } from '../../contexts/ProjectContext';
interface PatchProps {
latestRelease: GetLatestReleaseResult['latestRelease'];
releaseBranch: GetBranchResult['branch'] | null;
successCb?: ComponentConfigPatch['successCb'];
onSuccess?: ComponentConfigPatch['onSuccess'];
}
export const Patch = ({
latestRelease,
releaseBranch,
successCb,
onSuccess,
}: PatchProps) => {
return (
<InfoCardPlus>
@@ -51,13 +51,13 @@ export const Patch = ({
<BodyWrapper
latestRelease={latestRelease}
releaseBranch={releaseBranch}
successCb={successCb}
onSuccess={onSuccess}
/>
</InfoCardPlus>
);
};
function BodyWrapper({ latestRelease, releaseBranch, successCb }: PatchProps) {
function BodyWrapper({ latestRelease, releaseBranch, onSuccess }: PatchProps) {
const { project } = useProjectContext();
if (latestRelease === null) {
@@ -91,7 +91,7 @@ function BodyWrapper({ latestRelease, releaseBranch, successCb }: PatchProps) {
bumpedTag={bumpedTag.bumpedTag}
latestRelease={latestRelease}
releaseBranch={releaseBranch}
successCb={successCb}
onSuccess={onSuccess}
tagParts={bumpedTag.tagParts}
/>
);
@@ -56,7 +56,7 @@ interface PatchBodyProps {
bumpedTag: string;
latestRelease: NonNullable<GetLatestReleaseResult['latestRelease']>;
releaseBranch: GetBranchResult['branch'];
successCb?: ComponentConfigPatch['successCb'];
onSuccess?: ComponentConfigPatch['onSuccess'];
tagParts: NonNullable<CalverTagParts | SemverTagParts>;
}
@@ -64,7 +64,7 @@ export const PatchBody = ({
bumpedTag,
latestRelease,
releaseBranch,
successCb,
onSuccess,
tagParts,
}: PatchBodyProps) => {
const pluginApiClient = useApi(gitReleaseManagerApiRef);
@@ -98,7 +98,7 @@ export const PatchBody = ({
latestRelease,
project,
tagParts,
successCb,
onSuccess,
});
if (responseSteps.length > 0) {
@@ -57,14 +57,14 @@ describe('patch', () => {
expect(result.current.responseSteps).toHaveLength(9);
});
it('should return the expected responseSteps and progress (with successCb)', async () => {
it('should return the expected responseSteps and progress (with onSuccess)', async () => {
const { result } = renderHook(() =>
usePatch({
bumpedTag: mockBumpedTag,
latestRelease: mockReleaseVersionCalver,
project: mockCalverProject,
tagParts: mockTagParts,
successCb: jest.fn(),
onSuccess: jest.fn(),
}),
);
@@ -37,7 +37,7 @@ interface Patch {
latestRelease: NonNullable<GetLatestReleaseResult['latestRelease']>;
project: Project;
tagParts: NonNullable<CalverTagParts | SemverTagParts>;
successCb?: ComponentConfigPatch['successCb'];
onSuccess?: ComponentConfigPatch['onSuccess'];
}
// Inspiration: https://stackoverflow.com/questions/53859199/how-to-cherry-pick-through-githubs-api
@@ -46,7 +46,7 @@ export function usePatch({
latestRelease,
project,
tagParts,
successCb,
onSuccess,
}: Patch): CardHook<GetRecentCommitsResultSingle> {
const pluginApiClient = useApi(gitReleaseManagerApiRef);
const { user } = useUserContext();
@@ -327,16 +327,16 @@ ${selectedPatchCommit.commit.message}`,
}, [createdReferenceRes.value, createdReferenceRes.error]);
/**
* (10) Run successCb if defined
* (10) Run onSuccess if defined
*/
useAsync(async () => {
if (!successCb) return;
if (!onSuccess) return;
abortIfError(updatedReleaseRes.error);
if (!updatedReleaseRes.value || !releaseBranchRes.value) return;
try {
await successCb?.({
await onSuccess?.({
updatedReleaseUrl: updatedReleaseRes.value.htmlUrl,
updatedReleaseName: updatedReleaseRes.value.name,
previousTag: latestRelease.tagName,
@@ -355,7 +355,7 @@ ${selectedPatchCommit.commit.message}`,
});
}, [updatedReleaseRes.value]);
const TOTAL_STEPS = 9 + (!!successCb ? 1 : 0);
const TOTAL_STEPS = 9 + (!!onSuccess ? 1 : 0);
const [progress, setProgress] = useState(0);
useEffect(() => {
setProgress((responseSteps.length / TOTAL_STEPS) * 100);
@@ -27,10 +27,10 @@ import { TEST_IDS } from '../../test-helpers/test-ids';
interface PromoteRcProps {
latestRelease: GetLatestReleaseResult['latestRelease'];
successCb?: ComponentConfigPromoteRc['successCb'];
onSuccess?: ComponentConfigPromoteRc['onSuccess'];
}
export const PromoteRc = ({ latestRelease, successCb }: PromoteRcProps) => {
export const PromoteRc = ({ latestRelease, onSuccess }: PromoteRcProps) => {
function Body() {
if (latestRelease === null) {
return <NoLatestRelease />;
@@ -52,7 +52,7 @@ export const PromoteRc = ({ latestRelease, successCb }: PromoteRcProps) => {
);
}
return <PromoteRcBody rcRelease={latestRelease} successCb={successCb} />;
return <PromoteRcBody rcRelease={latestRelease} onSuccess={onSuccess} />;
}
return (
@@ -26,16 +26,16 @@ import { usePromoteRc } from './hooks/usePromoteRc';
interface PromoteRcBodyProps {
rcRelease: NonNullable<GetLatestReleaseResult['latestRelease']>;
successCb?: ComponentConfigPromoteRc['successCb'];
onSuccess?: ComponentConfigPromoteRc['onSuccess'];
}
export const PromoteRcBody = ({ rcRelease, successCb }: PromoteRcBodyProps) => {
export const PromoteRcBody = ({ rcRelease, onSuccess }: PromoteRcBodyProps) => {
const releaseVersion = rcRelease.tagName.replace('rc-', 'version-');
const { progress, responseSteps, run, runInvoked } = usePromoteRc({
rcRelease,
releaseVersion,
successCb,
onSuccess,
});
if (responseSteps.length > 0) {
@@ -57,12 +57,12 @@ describe('usePromoteRc', () => {
expect(result.current.responseSteps).toHaveLength(4);
});
it('should return the expected responseSteps and progress (with successCb)', async () => {
it('should return the expected responseSteps and progress (with onSuccess)', async () => {
const { result } = renderHook(() =>
usePromoteRc({
rcRelease: mockReleaseCandidateCalver,
releaseVersion: 'version-1.2.3',
successCb: jest.fn(),
onSuccess: jest.fn(),
}),
);
@@ -30,13 +30,13 @@ import { useUserContext } from '../../../contexts/UserContext';
interface PromoteRc {
rcRelease: NonNullable<GetLatestReleaseResult['latestRelease']>;
releaseVersion: string;
successCb?: ComponentConfigPromoteRc['successCb'];
onSuccess?: ComponentConfigPromoteRc['onSuccess'];
}
export function usePromoteRc({
rcRelease,
releaseVersion,
successCb,
onSuccess,
}: PromoteRc): CardHook<void> {
const pluginApiClient = useApi(gitReleaseManagerApiRef);
const { user } = useUserContext();
@@ -162,14 +162,14 @@ export function usePromoteRc({
}, [createRcRes.value, createRcRes.error]);
/**
* (5) Run successCb if defined
* (5) Run onSuccess if defined
*/
useAsync(async () => {
if (successCb && !!promotedReleaseRes.value) {
if (onSuccess && !!promotedReleaseRes.value) {
abortIfError(promotedReleaseRes.error);
try {
await successCb?.({
await onSuccess?.({
gitReleaseUrl: promotedReleaseRes.value.htmlUrl,
gitReleaseName: promotedReleaseRes.value.name,
previousTagUrl: rcRelease.htmlUrl,
@@ -188,7 +188,7 @@ export function usePromoteRc({
}
}, [promotedReleaseRes.value]);
const TOTAL_STEPS = 4 + (!!successCb ? 1 : 0);
const TOTAL_STEPS = 4 + (!!onSuccess ? 1 : 0);
const [progress, setProgress] = useState(0);
useEffect(() => {
setProgress((responseSteps.length / TOTAL_STEPS) * 100);
@@ -16,19 +16,19 @@
export type ComponentConfig<Args> = {
omit?: boolean;
successCb?: (args: Args) => Promise<void> | void;
onSuccess?: (args: Args) => Promise<void> | void;
};
interface CreateRcSuccessCbArgs {
interface CreateRcOnSuccessArgs {
gitReleaseUrl: string;
gitReleaseName: string | null;
comparisonUrl: string;
previousTag?: string;
createdTag: string;
}
export type ComponentConfigCreateRc = ComponentConfig<CreateRcSuccessCbArgs>;
export type ComponentConfigCreateRc = ComponentConfig<CreateRcOnSuccessArgs>;
interface PromoteRcSuccessCbArgs {
interface PromoteRcOnSuccessArgs {
gitReleaseUrl: string;
gitReleaseName: string | null;
previousTagUrl: string;
@@ -36,9 +36,9 @@ interface PromoteRcSuccessCbArgs {
updatedTagUrl: string;
updatedTag: string;
}
export type ComponentConfigPromoteRc = ComponentConfig<PromoteRcSuccessCbArgs>;
export type ComponentConfigPromoteRc = ComponentConfig<PromoteRcOnSuccessArgs>;
interface PatchSuccessCbArgs {
interface PatchOnSuccessArgs {
updatedReleaseUrl: string;
updatedReleaseName: string | null;
previousTag: string;
@@ -46,7 +46,7 @@ interface PatchSuccessCbArgs {
patchCommitUrl: string;
patchCommitMessage: string;
}
export type ComponentConfigPatch = ComponentConfig<PatchSuccessCbArgs>;
export type ComponentConfigPatch = ComponentConfig<PatchOnSuccessArgs>;
export interface ResponseStep {
message: string | React.ReactNode;