From 1ed2f1af42e38ef8749bc145d20a53dfa0c10c54 Mon Sep 17 00:00:00 2001 From: Erik Engervall Date: Wed, 6 Oct 2021 16:47:40 +0200 Subject: [PATCH] Update naming from patch validation to patch dry run Signed-off-by: Erik Engervall --- .../src/features/Patch/hooks/usePatch.ts | 18 +++---- ...idationSequence.tsx => usePatchDryRun.tsx} | 51 +++++++++---------- 2 files changed, 34 insertions(+), 35 deletions(-) rename plugins/git-release-manager/src/features/Patch/hooks/{usePatchValidationSequence.tsx => usePatchDryRun.tsx} (90%) diff --git a/plugins/git-release-manager/src/features/Patch/hooks/usePatch.ts b/plugins/git-release-manager/src/features/Patch/hooks/usePatch.ts index df80339108..188ffbca2e 100644 --- a/plugins/git-release-manager/src/features/Patch/hooks/usePatch.ts +++ b/plugins/git-release-manager/src/features/Patch/hooks/usePatch.ts @@ -14,27 +14,27 @@ * limitations under the License. */ -import { useEffect, useState } from 'react'; import { useAsync } from 'react-use'; -import { - GetLatestReleaseResult, - GetRecentCommitsResultSingle, -} from '../../../api/GitReleaseClient'; +import { useEffect, useState } from 'react'; -import { CalverTagParts } from '../../../helpers/tagParts/getCalverTagParts'; import { CardHook, ComponentConfig, PatchOnSuccessArgs, } from '../../../types/types'; +import { + GetLatestReleaseResult, + GetRecentCommitsResultSingle, +} from '../../../api/GitReleaseClient'; +import { CalverTagParts } from '../../../helpers/tagParts/getCalverTagParts'; import { getPatchCommitSuffix } from '../helpers/getPatchCommitSuffix'; import { gitReleaseManagerApiRef } from '../../../api/serviceApiRef'; import { Project } from '../../../contexts/ProjectContext'; import { SemverTagParts } from '../../../helpers/tagParts/getSemverTagParts'; import { TAG_OBJECT_MESSAGE } from '../../../constants/constants'; -import { useUserContext } from '../../../contexts/UserContext'; import { useApi } from '@backstage/core-plugin-api'; -import { usePatchValidationSequence } from './usePatchValidationSequence'; +import { usePatchDryRun } from './usePatchDryRun'; +import { useUserContext } from '../../../contexts/UserContext'; export interface UsePatch { bumpedTag: string; @@ -67,7 +67,7 @@ export function usePatch({ responseSteps, TOTAL_PATCH_PREP_STEPS, selectedPatchCommit, - } = usePatchValidationSequence({ + } = usePatchDryRun({ bumpedTag, releaseBranchName, project, diff --git a/plugins/git-release-manager/src/features/Patch/hooks/usePatchValidationSequence.tsx b/plugins/git-release-manager/src/features/Patch/hooks/usePatchDryRun.tsx similarity index 90% rename from plugins/git-release-manager/src/features/Patch/hooks/usePatchValidationSequence.tsx rename to plugins/git-release-manager/src/features/Patch/hooks/usePatchDryRun.tsx index 0ab0deee73..5227399970 100644 --- a/plugins/git-release-manager/src/features/Patch/hooks/usePatchValidationSequence.tsx +++ b/plugins/git-release-manager/src/features/Patch/hooks/usePatchDryRun.tsx @@ -18,40 +18,40 @@ import { useApi } from '@backstage/core-plugin-api'; import { useAsync, useAsyncFn } from 'react-use'; import React from 'react'; -import { GetRecentCommitsResultSingle } from '../../../api/GitReleaseClient'; import { CalverTagParts } from '../../../helpers/tagParts/getCalverTagParts'; import { getPatchCommitSuffix } from '../helpers/getPatchCommitSuffix'; +import { GetRecentCommitsResultSingle } from '../../../api/GitReleaseClient'; import { gitReleaseManagerApiRef } from '../../../api/serviceApiRef'; import { GitReleaseManagerError } from '../../../errors/GitReleaseManagerError'; import { Project } from '../../../contexts/ProjectContext'; import { SemverTagParts } from '../../../helpers/tagParts/getSemverTagParts'; import { useResponseSteps } from '../../../hooks/useResponseSteps'; -export interface UsePatchValidationSequence { +export interface UsePatchDryRun { bumpedTag: string; releaseBranchName: string; project: Project; tagParts: NonNullable; } -const PatchValidationMessage = ({ message }: { message: string }) => ( +const PatchDryRunMessage = ({ message }: { message: string }) => ( <> - [Patch validation] {message} + [Patch dry run] {message} ); // Inspiration: https://stackoverflow.com/questions/53859199/how-to-cherry-pick-through-githubs-api -export function usePatchValidationSequence({ +export function usePatchDryRun({ bumpedTag, releaseBranchName, project, tagParts, -}: UsePatchValidationSequence) { +}: UsePatchDryRun) { const pluginApiClient = useApi(gitReleaseManagerApiRef); const { responseSteps, addStepToResponseSteps, asyncCatcher, abortIfError } = useResponseSteps(); - const tempPatchBranchName = `${releaseBranchName}-backstage-grm-patch-validation`; + const tempPatchBranchName = `${releaseBranchName}-backstage-grm-patch-dry-run`; /** * (1) Get the release branch's most recent commit @@ -80,7 +80,7 @@ export function usePatchValidationSequence({ addStepToResponseSteps({ message: ( - ), @@ -120,8 +120,8 @@ export function usePatchValidationSequence({ addStepToResponseSteps({ message: ( - ), }); @@ -156,7 +156,7 @@ export function usePatchValidationSequence({ addStepToResponseSteps({ message: ( - ), @@ -182,7 +182,7 @@ export function usePatchValidationSequence({ .createCommit({ owner: project.owner, repo: project.repo, - message: `[Patch validation] Temporary commit for patch ${tagParts.patch}`, + message: `Temporary commit for patch ${tagParts.patch}`, parents: [ tempPatchBranchRes.value.selectedPatchCommit.firstParentSha ?? '', ], @@ -191,7 +191,7 @@ export function usePatchValidationSequence({ .catch(asyncCatcher); addStepToResponseSteps({ - message: , + message: , }); return { @@ -219,7 +219,7 @@ export function usePatchValidationSequence({ addStepToResponseSteps({ message: ( - ), @@ -258,7 +258,7 @@ export function usePatchValidationSequence({ } throw new GitReleaseManagerError( - 'Patching failed due to merge conflict. Will attempt to delete temporary patch validation branch. Manual patching is recommended.', + 'Patching failed due to merge conflict. Will attempt to delete temporary patch dry run branch. Manual patching is recommended.', ); } @@ -268,7 +268,7 @@ export function usePatchValidationSequence({ addStepToResponseSteps({ message: ( - ), @@ -289,25 +289,24 @@ export function usePatchValidationSequence({ if (!mergeRes.value || !tempPatchBranchRes.value) return undefined; const releaseBranchSha = tempPatchBranchRes.value.releaseBranch.commit.sha; - const selectedPatchCommit = tempPatchBranchRes.value.selectedPatchCommit; + const { + commit: { message }, + sha: commitSha, + } = tempPatchBranchRes.value.selectedPatchCommit; const { commit: cherryPickCommit } = await pluginApiClient.createCommit({ owner: project.owner, repo: project.repo, - message: `[Patch validation] [patch ${bumpedTag}] ${ - selectedPatchCommit.commit.message - } + message: `[patch (dry run) ${bumpedTag}] ${message} - ${getPatchCommitSuffix({ - commitSha: selectedPatchCommit.sha, - })}`, + ${getPatchCommitSuffix({ commitSha })}`, parents: [releaseBranchSha], tree: mergeRes.value.commit.tree.sha, }); addStepToResponseSteps({ message: ( - ), @@ -338,7 +337,7 @@ export function usePatchValidationSequence({ addStepToResponseSteps({ message: ( - ), @@ -365,7 +364,7 @@ export function usePatchValidationSequence({ addStepToResponseSteps({ message: ( - ),