Skip to content

Commit 0cd72da

Browse files
committed
feat: Refactor GitOps conflict handling and improve type definitions in CICD pipeline components
1 parent 451974b commit 0cd72da

File tree

3 files changed

+22
-23
lines changed

3 files changed

+22
-23
lines changed

src/Pages/App/Configurations/WorkflowEditor/CreateCICDPipeline/CDStepperContent.tsx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -85,22 +85,22 @@ export const CDStepperContent = ({
8585
setCiCdPipeline({ ci, cd })
8686
}
8787

88-
const checkGitOpsRepoConflict = () => {
88+
const checkGitOpsRepoConflict = async () => {
8989
setGitopsConflictLoading(true)
90-
getGitOpsRepoConfig(+appId)
91-
.then(() => {
92-
push(`/app/${appId}/edit/${URLS.APP_GITOPS_CONFIG}`)
93-
})
94-
.catch((err) => {
95-
if (err.code === API_STATUS_CODES.CONFLICT) {
96-
setReloadNoGitOpsRepoConfiguredModal(true)
97-
} else {
98-
showError(err)
99-
}
100-
})
101-
.finally(() => {
102-
setGitopsConflictLoading(false)
103-
})
90+
91+
try {
92+
await getGitOpsRepoConfig(+appId)
93+
94+
setGitopsConflictLoading(false)
95+
push(`/app/${appId}/edit/${URLS.APP_GITOPS_CONFIG}`)
96+
} catch (err) {
97+
setGitopsConflictLoading(false)
98+
if (err.code === API_STATUS_CODES.CONFLICT) {
99+
setReloadNoGitOpsRepoConfiguredModal(true)
100+
} else {
101+
showError(err)
102+
}
103+
}
104104
}
105105

106106
// RENDERERS

src/Pages/App/Configurations/WorkflowEditor/CreateCICDPipeline/CreateCICDPipeline.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Dispatch, SetStateAction, useEffect, useRef, useState } from 'react'
22

33
import {
4+
API_STATUS_CODES,
45
APIResponseHandler,
56
ButtonStyleType,
67
ComponentSizeType,
@@ -133,15 +134,11 @@ export const CreateCICDPipeline = ({
133134
})
134135
}
135136

136-
if (
137+
return (
137138
gitOpsRepoNotConfiguredAndOptionsHidden ||
138139
isGitOpsRepoNotConfiguredAndGitopsEnforced ||
139140
isGitOpsRepoNotConfiguredAndOptionsVisible
140-
) {
141-
return true
142-
}
143-
144-
return false
141+
)
145142
}
146143

147144
const createWorkflow = async ({ shouldCreateCINode }: { shouldCreateCINode: boolean }) => {
@@ -239,7 +236,7 @@ export const CreateCICDPipeline = ({
239236
setCdNodeCreateError(cdNodeRes.reason)
240237

241238
if (!shouldCreateCINode) {
242-
if (cdNodeRes.reason.code === 409) {
239+
if (cdNodeRes.reason.code === API_STATUS_CODES.CONFLICT) {
243240
setReloadNoGitOpsRepoConfiguredModal(true)
244241
} else {
245242
showError(cdNodeRes.reason)

src/Pages/App/Configurations/WorkflowEditor/CreateCICDPipeline/service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import {
22
DeploymentAppTypes,
3+
DeploymentStrategy,
34
getEnvironmentListMinPublic,
45
getIsRequestAborted,
56
ModuleNameMap,
67
ModuleStatus,
78
ReleaseMode,
9+
SavedDeploymentStrategy,
810
showError,
911
TriggerType,
1012
YAMLStringify,
@@ -18,7 +20,7 @@ import { getModuleInfo } from '@Components/v2/devtronStackManager/DevtronStackMa
1820

1921
import { CreateCICDPipelineData } from './types'
2022

21-
const getSavedStrategies = (strategies: any[]) => {
23+
const getSavedStrategies = (strategies: DeploymentStrategy[]): SavedDeploymentStrategy[] => {
2224
if (strategies.length > 0) {
2325
const allStrategies = strategies.reduce((acc, strategy) => {
2426
acc[strategy.deploymentTemplate] = strategy.config

0 commit comments

Comments
 (0)