mirror of
https://github.com/harness/drone.git
synced 2025-05-22 03:49:54 +08:00
Fix commit logic
This commit is contained in:
parent
3cde715e5f
commit
3848a98570
@ -22,7 +22,7 @@ import pipelineSchema from './schema/pipeline-schema.json'
|
|||||||
import css from './AddUpdatePipeline.module.scss'
|
import css from './AddUpdatePipeline.module.scss'
|
||||||
|
|
||||||
const starterPipelineAsString =
|
const starterPipelineAsString =
|
||||||
'stages:\n- type: ci\n spec:\n steps:\n - type: script\n spec:\n run: echo hello world'
|
'version: 1\nstages:\n- type: ci\n spec:\n steps:\n - type: script\n spec:\n run: echo hello world'
|
||||||
|
|
||||||
const AddUpdatePipeline = (): JSX.Element => {
|
const AddUpdatePipeline = (): JSX.Element => {
|
||||||
const { routes } = useAppContext()
|
const { routes } = useAppContext()
|
||||||
@ -46,7 +46,7 @@ const AddUpdatePipeline = (): JSX.Element => {
|
|||||||
lazy: !repoMetadata
|
lazy: !repoMetadata
|
||||||
})
|
})
|
||||||
|
|
||||||
const { data: resourceContent, loading: resourceLoading } = useGetResourceContent({
|
const { data: pipelineYAMLFileContent, loading: resourceLoading } = useGetResourceContent({
|
||||||
repoMetadata,
|
repoMetadata,
|
||||||
gitRef: pipelineData?.default_branch || '',
|
gitRef: pipelineData?.default_branch || '',
|
||||||
resourcePath: pipelineData?.config_path || ''
|
resourcePath: pipelineData?.config_path || ''
|
||||||
@ -54,9 +54,9 @@ const AddUpdatePipeline = (): JSX.Element => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!resourceLoading) {
|
if (!resourceLoading) {
|
||||||
setIsExistingPipeline(!isEmpty(pipelineData) && !isUndefined(pipelineData.id))
|
setIsExistingPipeline(!isEmpty(pipelineYAMLFileContent) && !isUndefined(pipelineYAMLFileContent.content))
|
||||||
}
|
}
|
||||||
}, [resourceContent, resourceLoading])
|
}, [pipelineYAMLFileContent, resourceLoading])
|
||||||
|
|
||||||
const handleSaveAndRun = (): void => {
|
const handleSaveAndRun = (): void => {
|
||||||
try {
|
try {
|
||||||
@ -66,7 +66,7 @@ const AddUpdatePipeline = (): JSX.Element => {
|
|||||||
action: isExistingPipeline ? 'UPDATE' : 'CREATE',
|
action: isExistingPipeline ? 'UPDATE' : 'CREATE',
|
||||||
path: pipelineData?.config_path,
|
path: pipelineData?.config_path,
|
||||||
payload: pipelineAsYAML,
|
payload: pipelineAsYAML,
|
||||||
sha: isExistingPipeline ? resourceContent?.sha : ''
|
sha: isExistingPipeline ? pipelineYAMLFileContent?.sha : ''
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
branch: repoMetadata?.default_branch,
|
branch: repoMetadata?.default_branch,
|
||||||
@ -122,9 +122,8 @@ const AddUpdatePipeline = (): JSX.Element => {
|
|||||||
language={'yaml'}
|
language={'yaml'}
|
||||||
schema={pipelineSchema}
|
schema={pipelineSchema}
|
||||||
source={
|
source={
|
||||||
isExistingPipeline
|
decodeGitContent((pipelineYAMLFileContent?.content as RepoFileContent)?.data) ||
|
||||||
? decodeGitContent((resourceContent?.content as RepoFileContent)?.data)
|
starterPipelineAsString
|
||||||
: starterPipelineAsString
|
|
||||||
}
|
}
|
||||||
onChange={(value: string) => setPipelineAsYaml(value)}
|
onChange={(value: string) => setPipelineAsYaml(value)}
|
||||||
/>
|
/>
|
||||||
|
Loading…
Reference in New Issue
Block a user