From 2f4b0036d19cbe81d11e5ae78ee75012af49bb4d Mon Sep 17 00:00:00 2001 From: Karan Saraswat Date: Wed, 11 Sep 2024 11:50:04 +0000 Subject: [PATCH] feat: [CODE-2338]: Add dry run rules param to create branch API (#2680) * addressed review comments * Merge branch 'main' of https://git0.harness.io/l7B_kbSEQD2wjrM7PShm5w/PROD/Harness_Commons/gitness into CODE-2346 * feat: [CODE-2346]: Add an option to restore branch for merged/closed PR * feat: [CODE-2338]: Add dry run rules param to create branch API --- web/src/framework/strings/stringTypes.ts | 2 + web/src/i18n/strings.en.yaml | 2 + .../PullRequestActionsBox.tsx | 93 ++++++------------ .../PullRequestOverviewPanel.module.scss | 2 +- .../PullRequestOverviewPanel.module.scss.d.ts | 2 +- .../PullRequestOverviewPanel.tsx | 46 +++++++-- .../PullRequestPanelSections.tsx | 2 +- ...chSection.tsx => BranchActionsSection.tsx} | 97 ++++++++++++------- .../pages/PullRequest/PullRequestUtils.tsx | 2 +- web/src/services/code/index.tsx | 35 +++++-- web/src/services/code/swagger.yaml | 43 ++++++-- 11 files changed, 204 insertions(+), 122 deletions(-) rename web/src/pages/PullRequest/Conversation/PullRequestOverviewPanel/sections/{DeleteBranchSection.tsx => BranchActionsSection.tsx} (54%) diff --git a/web/src/framework/strings/stringTypes.ts b/web/src/framework/strings/stringTypes.ts index b93b9bbc4..82d5e8fe8 100644 --- a/web/src/framework/strings/stringTypes.ts +++ b/web/src/framework/strings/stringTypes.ts @@ -127,6 +127,7 @@ export interface StringsMap { 'branchProtection.targetPlaceholder': string 'branchProtection.title': string branchProtectionRules: string + branchRestored: string branchSource: string branchSourceDesc: string branchTagCreation: string @@ -908,6 +909,7 @@ export interface StringsMap { resolveComments: string resolved: string resolvedComments: string + restoreBranch: string results: string reviewProjectSettings: string reviewerNotFound: string diff --git a/web/src/i18n/strings.en.yaml b/web/src/i18n/strings.en.yaml index 32295af3d..d866cd6d6 100644 --- a/web/src/i18n/strings.en.yaml +++ b/web/src/i18n/strings.en.yaml @@ -176,6 +176,7 @@ branchCreated: Branch {branch} created. tagCreated: Tag {{tag}} created. confirmation: Confirmation deleteBranch: Delete Branch +restoreBranch: Restore Branch deleteTag: Delete Tag deleteTagConfirm: Are you sure you want to delete tag {{name}}? You can't undo this action. deleteBranchConfirm: Are you sure you want to delete branch {{name}}? You can't undo this action. @@ -187,6 +188,7 @@ compare: Compare commitString: 'Commit {commit}' repoDeleted: Repository {{repo}} deleted. branchDeleted: Branch {branch} deleted. +branchRestored: Branch {branch} restored. tagDeleted: Tag {tag} deleted. failedToDeleteBranch: Failed to delete Branch. Please try again. createFile: Create __path__ diff --git a/web/src/pages/PullRequest/Conversation/PullRequestActionsBox/PullRequestActionsBox.tsx b/web/src/pages/PullRequest/Conversation/PullRequestActionsBox/PullRequestActionsBox.tsx index 459d39d72..bd5e00b0b 100644 --- a/web/src/pages/PullRequest/Conversation/PullRequestActionsBox/PullRequestActionsBox.tsx +++ b/web/src/pages/PullRequest/Conversation/PullRequestActionsBox/PullRequestActionsBox.tsx @@ -37,6 +37,9 @@ import { Menu, PopoverPosition, Icon as BIcon } from '@blueprintjs/core' import cx from 'classnames' import ReactTimeago from 'react-timeago' import type { + CreateBranchPathParams, + DeleteBranchQueryParams, + OpenapiCreateBranchRequest, OpenapiStatePullReqRequest, TypesListCommitResponse, TypesPullReq, @@ -58,6 +61,7 @@ import { OptionsMenuButton } from 'components/OptionsMenuButton/OptionsMenuButto import { UserPreference, useUserPreference } from 'hooks/useUserPreference' import { useGetRepositoryMetadata } from 'hooks/useGetRepositoryMetadata' import { PullReqSuggestionsBatch } from 'components/PullReqSuggestionsBatch/PullReqSuggestionsBatch' +import { BranchActionsButton } from '../PullRequestOverviewPanel/sections/BranchActionsSection' import InlineMergeBox from './InlineMergeBox' import css from './PullRequestActionsBox.module.scss' @@ -71,18 +75,13 @@ export interface PullRequestActionsBoxProps extends Pick> refetchPullReq: () => void refetchActivities: () => void - deleteBranch: MutateMethod< - any, - any, - { - bypass_rules: boolean - dry_run_rules: boolean - commit_sha: string - }, - unknown - > + createBranch: MutateMethod + refetchBranch: () => Promise + deleteBranch: MutateMethod + showRestoreBranchButton: boolean showDeleteBranchButton: boolean setShowDeleteBranchButton: React.Dispatch> + setShowRestoreBranchButton: React.Dispatch> isSourceBranchDeleted: boolean } @@ -96,13 +95,17 @@ export const PullRequestActionsBox: React.FC = ({ setConflictingFiles, refetchPullReq, refetchActivities, + createBranch, + refetchBranch, deleteBranch, + showRestoreBranchButton, showDeleteBranchButton, + setShowRestoreBranchButton, setShowDeleteBranchButton, isSourceBranchDeleted }) => { const { getString } = useStrings() - const { showSuccess, showError } = useToaster() + const { showError } = useToaster() const inlineMergeRef = useRef(null) const { hooks, standalone } = useAppContext() const space = useGetSpaceParam() @@ -263,11 +266,13 @@ export const PullRequestActionsBox: React.FC = ({ return ( ) } @@ -542,28 +547,15 @@ export const PullRequestActionsBox: React.FC = ({ const MergeInfo: React.FC<{ pullRequestMetadata: TypesPullReq + showRestoreBranchButton: boolean showDeleteBranchButton: boolean setShowDeleteBranchButton: React.Dispatch> - deleteBranch: MutateMethod< - any, - any, - { - bypass_rules: boolean - dry_run_rules: boolean - commit_sha: string - }, - unknown - > - showSuccess: (message: React.ReactNode, timeout?: number, key?: string) => void - showError: (message: React.ReactNode, timeout?: number, key?: string) => void -}> = ({ - pullRequestMetadata, - showDeleteBranchButton, - setShowDeleteBranchButton, - deleteBranch, - showSuccess, - showError -}) => { + setShowRestoreBranchButton: React.Dispatch> + refetchBranch: () => Promise + createBranch: MutateMethod + deleteBranch: MutateMethod +}> = props => { + const { pullRequestMetadata, showRestoreBranchButton, showDeleteBranchButton } = props const { getString } = useStrings() return ( @@ -606,36 +598,11 @@ const MergeInfo: React.FC<{ /> - {showDeleteBranchButton && ( -