mirror of
https://github.com/harness/drone.git
synced 2025-05-19 02:20:03 +08:00
Disable branch creation when committing first new file into an empty repo (#217)
This commit is contained in:
parent
797e339e02
commit
92c82f5c44
@ -50,6 +50,7 @@ interface CommitModalButtonProps extends Omit<ButtonProps, 'onClick' | 'onSubmit
|
|||||||
gitRef: string
|
gitRef: string
|
||||||
resourcePath: string
|
resourcePath: string
|
||||||
commitTitlePlaceHolder: string
|
commitTitlePlaceHolder: string
|
||||||
|
disableBranchCreation?: boolean
|
||||||
oldResourcePath?: string
|
oldResourcePath?: string
|
||||||
payload?: string
|
payload?: string
|
||||||
sha?: string
|
sha?: string
|
||||||
@ -63,6 +64,7 @@ export const CommitModalButton: React.FC<CommitModalButtonProps> = ({
|
|||||||
resourcePath,
|
resourcePath,
|
||||||
commitTitlePlaceHolder,
|
commitTitlePlaceHolder,
|
||||||
oldResourcePath,
|
oldResourcePath,
|
||||||
|
disableBranchCreation = false,
|
||||||
payload = '',
|
payload = '',
|
||||||
sha,
|
sha,
|
||||||
onSuccess,
|
onSuccess,
|
||||||
@ -172,6 +174,7 @@ export const CommitModalButton: React.FC<CommitModalButtonProps> = ({
|
|||||||
)}>
|
)}>
|
||||||
<FormInput.RadioGroup
|
<FormInput.RadioGroup
|
||||||
name="branch"
|
name="branch"
|
||||||
|
disabled={disableBranchCreation}
|
||||||
label=""
|
label=""
|
||||||
onChange={e => {
|
onChange={e => {
|
||||||
setTargetBranchOption(get(e.target, 'defaultValue'))
|
setTargetBranchOption(get(e.target, 'defaultValue'))
|
||||||
|
@ -25,8 +25,8 @@ export function useGetResourceContent({
|
|||||||
lazy: !repoMetadata || lazy
|
lazy: !repoMetadata || lazy
|
||||||
})
|
})
|
||||||
const isRepositoryEmpty = useMemo(
|
const isRepositoryEmpty = useMemo(
|
||||||
() => repoMetadata && error && !data && response?.status === 404,
|
() => (repoMetadata && resourcePath === '' && error && response?.status === 404) || false,
|
||||||
[repoMetadata, error, data, response]
|
[repoMetadata, resourcePath, error, response]
|
||||||
)
|
)
|
||||||
|
|
||||||
return { data, error: isRepositoryEmpty ? undefined : error, loading, refetch, response, isRepositoryEmpty }
|
return { data, error: isRepositoryEmpty ? undefined : error, loading, refetch, response, isRepositoryEmpty }
|
||||||
|
@ -15,9 +15,10 @@ import css from './FileEditor.module.scss'
|
|||||||
|
|
||||||
interface EditorProps extends Pick<GitInfoProps, 'repoMetadata' | 'gitRef' | 'resourcePath'> {
|
interface EditorProps extends Pick<GitInfoProps, 'repoMetadata' | 'gitRef' | 'resourcePath'> {
|
||||||
resourceContent: GitInfoProps['resourceContent'] | null
|
resourceContent: GitInfoProps['resourceContent'] | null
|
||||||
|
isRepositoryEmpty: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
function Editor({ resourceContent, repoMetadata, gitRef, resourcePath }: EditorProps) {
|
function Editor({ resourceContent, repoMetadata, gitRef, resourcePath, isRepositoryEmpty }: EditorProps) {
|
||||||
const history = useHistory()
|
const history = useHistory()
|
||||||
const inputRef = useRef<HTMLInputElement | null>()
|
const inputRef = useRef<HTMLInputElement | null>()
|
||||||
const isNew = useMemo(() => !resourceContent || isDir(resourceContent), [resourceContent])
|
const isNew = useMemo(() => !resourceContent || isDir(resourceContent), [resourceContent])
|
||||||
@ -200,6 +201,7 @@ function Editor({ resourceContent, repoMetadata, gitRef, resourcePath }: EditorP
|
|||||||
}
|
}
|
||||||
setOriginalContent(content)
|
setOriginalContent(content)
|
||||||
}}
|
}}
|
||||||
|
disableBranchCreation={isRepositoryEmpty}
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
text={getString('cancel')}
|
text={getString('cancel')}
|
||||||
|
@ -35,6 +35,7 @@ export default function RepositoryFileEdit() {
|
|||||||
gitRef={gitRef}
|
gitRef={gitRef}
|
||||||
resourcePath={resourcePath}
|
resourcePath={resourcePath}
|
||||||
resourceContent={resourceContent}
|
resourceContent={resourceContent}
|
||||||
|
isRepositoryEmpty={isRepositoryEmpty}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</Container>
|
</Container>
|
||||||
|
Loading…
Reference in New Issue
Block a user