Skip to content

Commit

Permalink
feat: [code-1991]: adding merge conflict files to be seen in merge se…
Browse files Browse the repository at this point in the history
…ction (harness#2126)
  • Loading branch information
cjlee01 authored and Harness committed Jun 21, 2024
1 parent 1b244fe commit 16fa4e7
Show file tree
Hide file tree
Showing 10 changed files with 626 additions and 159 deletions.
16 changes: 16 additions & 0 deletions web/src/framework/strings/stringTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,18 @@ export interface StringsMap {
cloneText: string
close: string
closed: string
'cmdlineInfo.content': string
'cmdlineInfo.stepFive': string
'cmdlineInfo.stepFiveSub': string
'cmdlineInfo.stepFour': string
'cmdlineInfo.stepFourSub': string
'cmdlineInfo.stepOne': string
'cmdlineInfo.stepOneSub': string
'cmdlineInfo.stepThree': string
'cmdlineInfo.stepThreeSub': string
'cmdlineInfo.stepTwo': string
'cmdlineInfo.stepTwoSub': string
'cmdlineInfo.title': string
code: string
'codeOwner.approvalCompleted': string
'codeOwner.changesRequested': string
Expand All @@ -259,6 +271,7 @@ export interface StringsMap {
codeSearch: string
codeSearchModal: string
comingSoon: string
commandLine: string
comment: string
commentDeleted: string
commit: string
Expand Down Expand Up @@ -286,6 +299,7 @@ export interface StringsMap {
confirmRepoVisButton: string
confirmStrat: string
confirmation: string
conflictsFoundInThisBranch: string
content: string
contents: string
contributor: string
Expand Down Expand Up @@ -802,6 +816,7 @@ export interface StringsMap {
'pr.titlePlaceHolder': string
'pr.toggleComments': string
'pr.unified': string
'pr.useCmdLineToResolveConflicts': string
'prChecks.error': string
'prChecks.failure': string
'prChecks.killed': string
Expand Down Expand Up @@ -973,6 +988,7 @@ export interface StringsMap {
status: string
'step.select': string
'stepCategory.select': string
stepNum: string
submitReview: string
success: string
suggestion: string
Expand Down
19 changes: 18 additions & 1 deletion web/src/i18n/strings.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ webhook: Webhook
diff: Diff
draft: Draft
conversation: Conversation
commandLine: command line
pr:
toggleComments: Toggle comments
suggestedChange: Suggested change
Expand All @@ -267,6 +268,7 @@ pr:
expandFullFile: Expand all
collapseFullFile: Collapse expanded lines
ableToMerge: Able to merge.
useCmdLineToResolveConflicts: Use the {cmd} to resolve conflicts
cantBeMerged: This branch has conflicts with the {{name}} branch.
cantMerge: Can't be merged. You can still create the pull request.
failedToCreate: Failed to create Pull Request.
Expand Down Expand Up @@ -1043,6 +1045,7 @@ resolveComments: There are {{n}} unresolved comments
view: View
mergeCheckInProgress: Merge check in progress...
allConflictsNeedToBeResolved: All conflicts have to be resolved before merging
conflictsFoundInThisBranch: Conflicts found in this branch
details: Details
showCheckAll: Show all checks
showLessCheck: Show less checks
Expand All @@ -1053,7 +1056,7 @@ customizeMergeCommitMessage: Customize merge commit message
mergeStrategy: Merge strategy
selectMergeStrat: Select merge strategy
writeDownCommit: Write down commit message here
prHasNoConflicts: This branch has no conflicts with {{name}} branch
prHasNoConflicts: This branch has no conflicts with {name} branch
checkStatus:
succeeded: Succeeded in {time}
failed: Failed in {time}
Expand Down Expand Up @@ -1181,3 +1184,17 @@ changesRequestedBy: CHANGES REQUESTED BY
mergeBranchTitle: Merge branch {{branchName}} of {{repoPath}} (#{{prNum}})
http: HTTP
ssh: SSH
stepNum: STEP {{num}}
cmdlineInfo:
title: Resolve conflicts via command line
content: If the conflicts on this branch are too complex to resolve in the web editor, you can check it out via command line to resolve the conflicts
stepOne: Clone the repository or update your local repository with the latest changes
stepOneSub: git pull origin {target}
stepTwo: Switch to the head branch of the pull request
stepTwoSub: git checkout {source}
stepThree: Merge the base branch into the head branch
stepThreeSub: git merge {target}
stepFour: Fix the conflicts and commit the result
stepFourSub: See Resolving a merge conflict using the command line for step-by-step instruction on resolving merge conflicts
stepFive: Push the changes
stepFiveSub: git push -u origin {source}
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,10 @@ import cx from 'classnames'
import ReactTimeago from 'react-timeago'
import type { OpenapiStatePullReqRequest, TypesPullReq, TypesRuleViolations } from 'services/code'
import { useStrings } from 'framework/strings'
import { CodeIcon, MergeStrategy, PullRequestFilterOption, PullRequestState } from 'utils/GitUtils'
import { CodeIcon, MergeStrategy, PullRequestFilterOption, PullRequestState, dryMerge } from 'utils/GitUtils'
import { useGetSpaceParam } from 'hooks/useGetSpaceParam'
import { useAppContext } from 'AppContext'
import {
dryMerge,
extractInfoFromRuleViolationArr,
getErrorMessage,
inlineMergeFormRefType,
Expand All @@ -65,7 +64,8 @@ export const PullRequestActionsBox: React.FC<PullRequestActionsBoxProps> = ({
onPRStateChanged,
allowedStrategy,
pullReqCommits,
PRStateLoading
PRStateLoading,
setConflictingFiles
}) => {
const { getString } = useStrings()
const { showError } = useToaster()
Expand Down Expand Up @@ -126,7 +126,8 @@ export const PullRequestActionsBox: React.FC<PullRequestActionsBoxProps> = ({
setRuleViolationArr,
setAllowedStrats,
pullRequestSection,
showError
showError,
setConflictingFiles
) // eslint-disable-next-line react-hooks/exhaustive-deps
}, [unchecked, pullReqMetadata?.source_sha])
const [prMerged, setPrMerged] = useState(false)
Expand All @@ -144,7 +145,8 @@ export const PullRequestActionsBox: React.FC<PullRequestActionsBoxProps> = ({
setRuleViolationArr,
setAllowedStrats,
pullRequestSection,
showError
showError,
setConflictingFiles
)
}
}, POLLING_INTERVAL) // Poll every 20 seconds
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
/*
* Copyright 2023 Harness, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React from 'react'
import { Color, FontVariation } from '@harnessio/design-system'
import { Container, Layout, StringSubstitute, Text } from '@harnessio/uicore'
import type { TypesPullReq } from 'services/code'
import { useStrings } from 'framework/strings'
import { CopyButton } from 'components/CopyButton/CopyButton'
import { CodeIcon } from 'utils/GitUtils'
import css from './PullRequestOverviewPanel.module.scss'

interface CommandLineInfoProps {
pullReqMetadata: TypesPullReq
}

const CommandLineInfo = (props: CommandLineInfoProps) => {
const { pullReqMetadata } = props

const { getString } = useStrings()
const stepOneCopy = getString('cmdlineInfo.stepOneSub').replace('{target}', pullReqMetadata.target_branch as string)
const stepTwoCopy = getString('cmdlineInfo.stepTwoSub').replace('{source}', pullReqMetadata.source_branch as string)
const stepThreeCopy = getString('cmdlineInfo.stepThreeSub').replace(
'{target}',
pullReqMetadata.target_branch as string
)
const stepFiveCopy = getString('cmdlineInfo.stepFiveSub').replace('{source}', pullReqMetadata.source_branch as string)
return (
<Container
className={css.cmdInfoContainer}
margin={{ top: 'small', bottom: 'small' }}
padding={{ top: 'large', left: 'xxxlarge', right: 'xlarge', bottom: 'large' }}>
<Layout.Vertical>
<Container className={css.cmdTextTitleContainer}>
<Text padding={{ bottom: 'xsmall' }} font={{ variation: FontVariation.H5 }}>
{getString('cmdlineInfo.title')}
</Text>
</Container>
<Text
color={Color.GREY_450}
className={css.stepText}
font={{ variation: FontVariation.BODY2 }}
padding={{ top: 'xsmall' }}>
{getString('cmdlineInfo.content')}
</Text>
<Layout.Vertical>
<Layout.Horizontal flex={{ alignItems: 'center', justifyContent: 'flex-start' }} padding={{ top: 'small' }}>
<Text className={css.checkName} padding={{ right: 'small' }} font={{ variation: FontVariation.CARD_TITLE }}>
{getString('stepNum', { num: 1 }).toUpperCase()}
</Text>
<Text color={Color.GREY_450} className={css.stepText} font={{ variation: FontVariation.BODY2 }}>
{getString('cmdlineInfo.stepOne')}
</Text>
</Layout.Horizontal>
<Layout.Horizontal margin={{ left: 'small' }} padding={{ top: 'xsmall', left: 'xxxlarge' }}>
<Layout.Horizontal
flex={{ justifyContent: 'space-between' }}
className={css.blueCopyContainer}
padding={{ top: 'small', left: 'medium', right: 'medium', bottom: 'small' }}>
<Text className={css.stepFont}>
<StringSubstitute
str={getString('cmdlineInfo.stepOneSub')}
vars={{
target: pullReqMetadata.target_branch
}}
/>
</Text>
<CopyButton
className={css.copyIconContainer}
content={stepOneCopy}
icon={CodeIcon.Copy}
color={Color.PRIMARY_7}
iconProps={{ size: 14, color: Color.PRIMARY_7 }}
background={Color.PRIMARY_1}
/>
</Layout.Horizontal>
</Layout.Horizontal>
<Layout.Horizontal flex={{ alignItems: 'center', justifyContent: 'flex-start' }} padding={{ top: 'small' }}>
<Text className={css.checkName} padding={{ right: 'small' }} font={{ variation: FontVariation.CARD_TITLE }}>
{getString('stepNum', { num: 2 }).toUpperCase()}
</Text>
<Text color={Color.GREY_450} className={css.stepText} font={{ variation: FontVariation.BODY2 }}>
{getString('cmdlineInfo.stepTwo')}
</Text>
</Layout.Horizontal>
<Layout.Horizontal margin={{ left: 'small' }} padding={{ top: 'xsmall', left: 'xxxlarge' }}>
<Layout.Horizontal
flex={{ justifyContent: 'space-between' }}
className={css.blueCopyContainer}
padding={{ top: 'small', left: 'medium', right: 'medium', bottom: 'small' }}>
<Text className={css.stepFont}>
<StringSubstitute
str={getString('cmdlineInfo.stepTwoSub')}
vars={{
source: pullReqMetadata.source_branch
}}
/>
</Text>
<CopyButton
className={css.copyIconContainer}
content={stepTwoCopy}
icon={CodeIcon.Copy}
color={Color.PRIMARY_7}
iconProps={{ size: 14, color: Color.PRIMARY_7 }}
background={Color.PRIMARY_1}
/>
</Layout.Horizontal>
</Layout.Horizontal>

<Layout.Horizontal flex={{ alignItems: 'center', justifyContent: 'flex-start' }} padding={{ top: 'small' }}>
<Text className={css.checkName} padding={{ right: 'small' }} font={{ variation: FontVariation.CARD_TITLE }}>
{getString('stepNum', { num: 3 }).toUpperCase()}
</Text>
<Text color={Color.GREY_450} className={css.stepText} font={{ variation: FontVariation.BODY2 }}>
{getString('cmdlineInfo.stepThree')}
</Text>
</Layout.Horizontal>
<Layout.Horizontal margin={{ left: 'small' }} padding={{ top: 'xsmall', left: 'xxxlarge' }}>
<Layout.Horizontal
flex={{ justifyContent: 'space-between' }}
className={css.blueCopyContainer}
padding={{ top: 'small', left: 'medium', right: 'medium', bottom: 'small' }}>
<Text className={css.stepFont}>
<StringSubstitute
str={getString('cmdlineInfo.stepThreeSub')}
vars={{
target: pullReqMetadata.target_branch
}}
/>
</Text>
<CopyButton
className={css.copyIconContainer}
content={stepThreeCopy}
icon={CodeIcon.Copy}
color={Color.PRIMARY_7}
iconProps={{ size: 14, color: Color.PRIMARY_7 }}
background={Color.PRIMARY_1}
/>
</Layout.Horizontal>
</Layout.Horizontal>
<Layout.Horizontal flex={{ alignItems: 'center', justifyContent: 'flex-start' }} padding={{ top: 'small' }}>
<Text className={css.checkName} padding={{ right: 'small' }} font={{ variation: FontVariation.CARD_TITLE }}>
{getString('stepNum', { num: 4 }).toUpperCase()}
</Text>
<Text color={Color.GREY_450} className={css.stepText} font={{ variation: FontVariation.BODY2 }}>
{getString('cmdlineInfo.stepFour')}
</Text>
</Layout.Horizontal>
<Layout.Horizontal margin={{ left: 'small' }} padding={{ top: 'xsmall', left: 'xxxlarge' }}>
<Layout.Horizontal flex={{ justifyContent: 'space-between' }}>
<Text
padding={{ left: 'tiny' }}
color={Color.GREY_450}
className={css.stepText}
font={{ variation: FontVariation.BODY2 }}>
{getString('cmdlineInfo.stepFourSub')}
</Text>
</Layout.Horizontal>
</Layout.Horizontal>
<Layout.Horizontal flex={{ alignItems: 'center', justifyContent: 'flex-start' }} padding={{ top: 'small' }}>
<Text className={css.checkName} padding={{ right: 'small' }} font={{ variation: FontVariation.CARD_TITLE }}>
{getString('stepNum', { num: 5 }).toUpperCase()}
</Text>
<Text color={Color.GREY_450} className={css.stepText} font={{ variation: FontVariation.BODY2 }}>
{getString('cmdlineInfo.stepFive')}
</Text>
</Layout.Horizontal>
<Layout.Horizontal margin={{ left: 'small' }} padding={{ top: 'xsmall', left: 'xxxlarge' }}>
<Layout.Horizontal
flex={{ justifyContent: 'space-between' }}
className={css.blueCopyContainer}
padding={{ top: 'small', left: 'medium', right: 'medium', bottom: 'small' }}>
<Text className={css.stepFont}>
<StringSubstitute
str={getString('cmdlineInfo.stepFiveSub')}
vars={{
source: pullReqMetadata.source_branch
}}
/>
</Text>
<CopyButton
className={css.copyIconContainer}
content={stepFiveCopy}
icon={CodeIcon.Copy}
color={Color.PRIMARY_7}
iconProps={{ size: 14, color: Color.PRIMARY_7 }}
background={Color.PRIMARY_1}
/>
</Layout.Horizontal>
</Layout.Horizontal>
</Layout.Vertical>
</Layout.Vertical>
</Container>
)
}

export default CommandLineInfo
Loading

0 comments on commit 16fa4e7

Please sign in to comment.