Skip to content

Commit b218aaa

Browse files
LaeeqdevYashasviDevtronprakarsh-dtRajeevRanjan27akshatsinha007
authored andcommitted
fix:duplicate workflow name fixed (#4841)
* duplicate workflow name bug resolved * refactored code * completed dev testing and code * PR code review comments resolved * resolved PR code review comments * resolved PR code review comments final * misc: Refactoring Pagerduty Issue Calculator script (#4856) * Modifying pager duty python script * Updated CODEOWNERS --------- Co-authored-by: Prakarsh <[email protected]> * feat: Add support for git hash in the app and app group overview section _revised (#4836) * Revised the api for handelling the overview git commits part using CiArtifact table only * Removed unnecessary comments * optimized the loop and intialization * used maps instead of slices * removed unused comments * modified the GetUniqueArtifactIds * Removed error from util function * renamed the function as generateArtifactIDCommitMap * feat:MailMaster Plugin v1.0 (#4825) * MailMaster Plugin v1.0 * Update 232_mailmaster.up.sql Updated Variable Names * Rename 232_mailmaster.down.sql to 233_mailmaster.down.sql * Rename 232_mailmaster.up.sql to 233_mailmaster.up.sql * 233_mailmaster.up.sql --------- Co-authored-by: Prakarsh <[email protected]> * return nil,err on git material fetch error (#4857) * removed code for gitops repo migration in devtron apps (#4838) Co-authored-by: Vikram <[email protected]> * fix: update argo app repo url in patch (#4876) * fix: injected app-serveice dependency into DeployedApplicationEventProcessor service (#4875) * fix: depandabot version upgrade (#4792) * dependabot version upgrade * dependabot version upgrade * code refactored * code refactored * code refactored * code refactored * code refactored * code refactored * argo assets deletion reverted * syncing specifig chart (#4631) * fix: use JoinCookie method (#4892) * chore: Resource mapping refactoring (#4813) * change sync * vars * refactor * fix: use JoinCookie method (#4892) * sql file merged --------- Co-authored-by: adi6859 <[email protected]> Co-authored-by: Gireesh Naidu <[email protected]> * fix: rbac fix in case of project in upper case (#4840) * lower case rbac objects * lower case * lower * chore: App Store refactoring v4 (#4647) * removed registerInArgo multiple impls * extracted app metrics code * migrated envLevel app metrics code to new service * chore: Removed unused jira and migration integration (#4498) * removed unsued jira integration * removed test-suite-code * db migration conf removal * chore: removed unused injection * chore: removed dead code * added: migration script --------- Co-authored-by: Ash-exp <[email protected]> * chore: App store dead code cleanup and restructuring (#4497) * moved chart-group in seperate code * removed unused dependency * removed dead code * extracted resource tree * moved notes * resource movement * removed unused code * removed unused dependency * commit methods * extracted status update * chore: clean up unused dead code * updated: EA mode docker file * updated: migration number --------- Co-authored-by: Ash-exp <[email protected]> * chart ref refactoring * removed infra metrics db calls * moved app metrics repositories from /internal to /pkg * moved: const and types to bean * removed: unused const * review comments * migrated some methods from chartService to chartRefService * added dt validation service interface * minor refactoring * moved validation method - 1 * wip * removed redundant appMetrics req obj * moved app metrics bindings to wireset * removed multiple dead code * remove redundant dependency * moved ChartGroup router and rest handler to respective folder * stage 1 * gitOps refactoring * moved gitClient code to a common wrapper service * chore: AppStoreDeployment Install flow refactoring * review changes * wip * fix for unsupported charts * refactoring: App Store deployment services * minor cleanup * renamed remote package to git * renamed gitOpsRemoteOpService If and impl * migrated usages of gitService to gitOperationService * shifted git service and all gitOps clients to pkg * gitops repository usages refactor * refactored gitOpsRepository usages * gitlab client creation refactoring * renamed util/ChartService * reverted renaming changes * reverted renaming changes * reverted renaming changes * wip * wip * removed typo * changes * changes * chore: App store services refactoring (#4596) * chore: fixed test file * chore: app store deployment services refactoring * updated todo * chore: dead code removal and app router & rest handler restructuring (#4595) (#4608) * prom code removal * removed test suites * chore: removed support for unused Prometheus and ArgoCd APIs * chore: app router and rest handler restructuring * removed redundant routings * fixed: sub path * Updated alias and added queries to AppList group router --------- Co-authored-by: nishant <[email protected]> * chore: sanity after ent sync * added: todo comment * added: todo comment * chore: fixed gitops auto fix operations in upgrade helm charts * added: nit pointer issue for argocd resource tree * fixed: nil poniter issue for gitops in upgrade deployment * chore: install Helm chart flow refactoring * removed: comments * chore: broken down AppStoreDeploymentService interface * fix: install apps audit logs * chore: update env name usgae * chore: fixed main merge changes * updated env var parsing * moved attribute const to bean * removed unused dependency injection * chore: updated alias name * updated: test file * updated wire file * fixed: nil pointer issue * fixed: pg no row issue * fixed: dependency injection * fix: adapter data provider methods * fix: data provider methods * wip * fix: helm app project link * fixed panic on bulk trigger chart group event * fixed gitops validations * fixed delpoyment histroy status for manifest download * App store chore refactoring v4 sync oss (#4778) * code refactored * code refactored * code refactored * code refactored * code refactored * code refactored * code refactored * code refactored --------- Co-authored-by: Ash-exp <[email protected]> --------- Co-authored-by: kartik-579 <[email protected]> Co-authored-by: Nishant <[email protected]> Co-authored-by: nishant <[email protected]> Co-authored-by: Shashwat Dadhich <[email protected]> * fix: deprecate latest in app store app version (#4896) * fix: deprecate latest flag from app_store application_version and increase varchar len for some columns * fix: deprecate latest flag from app_store application_version and increase varchar len for some columns * fix: remove digest column length update * chore: migration support for notification db changes (#4906) * migration support for notification db changes * updated query with internal flag * feat: Added the Devtron CI Trigger Plugin (#4902) (#4908) * Added the Devtron CI Trigger Plugin * Rename 235_devtron_ci_trigger_plugin.down.sql to 236_devtron_ci_trigger_plugin.down.sql * Rename 235_devtron_ci_trigger_plugin.up.sql to 236_devtron_ci_trigger_plugin.up.sql * Rename 236_devtron_ci_trigger_plugin.down.sql to 237_devtron_ci_trigger_plugin.down.sql * Rename 236_devtron_ci_trigger_plugin.up.sql to 237_devtron_ci_trigger_plugin.up.sql --------- Co-authored-by: Yashasvi17 <[email protected]> Co-authored-by: Prakarsh <[email protected]> Co-authored-by: Rajeev Ranjan <[email protected]> Co-authored-by: akshatsinha007 <[email protected]> Co-authored-by: Prakash <[email protected]> Co-authored-by: Vikram <[email protected]> Co-authored-by: Gireesh Naidu <[email protected]> Co-authored-by: Shashwat Dadhich <[email protected]> Co-authored-by: iamayushm <[email protected]> Co-authored-by: subhashish-devtron <[email protected]> Co-authored-by: adi6859 <[email protected]> Co-authored-by: Shivam Nagar <[email protected]> Co-authored-by: Asutosh Das <[email protected]> Co-authored-by: kartik-579 <[email protected]> Co-authored-by: Nishant <[email protected]> Co-authored-by: nishant <[email protected]> Co-authored-by: Kiran <[email protected]>
1 parent 7770d60 commit b218aaa

File tree

3 files changed

+42
-11
lines changed

3 files changed

+42
-11
lines changed

api/restHandler/CoreAppRestHandler.go

+9
Original file line numberDiff line numberDiff line change
@@ -1587,6 +1587,15 @@ func (handler CoreAppRestHandlerImpl) createWorkflows(ctx context.Context, appId
15871587
}
15881588

15891589
func (handler CoreAppRestHandlerImpl) createWorkflowInDb(workflowName string, appId int, userId int32) (int, error) {
1590+
//checking if workflow name already exist or not
1591+
ok, err := handler.appWorkflowService.IsWorkflowNameFound(workflowName, appId)
1592+
if err != nil {
1593+
return 0, err
1594+
}
1595+
// if workflow name already exists then we will assign a new name to the workflow
1596+
if ok {
1597+
workflowName = util.GenerateNewWorkflowName(workflowName)
1598+
}
15901599
wf := &appWorkflow2.AppWorkflow{
15911600
Name: workflowName,
15921601
AppId: appId,

pkg/appWorkflow/AppWorkflowService.go

+28-11
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package appWorkflow
2020
import (
2121
"errors"
2222
"fmt"
23+
util2 "github.com/devtron-labs/devtron/util"
2324
"time"
2425

2526
mapset "github.com/deckarep/golang-set"
@@ -59,7 +60,7 @@ type AppWorkflowService interface {
5960
FindAppWorkflowMappingByComponent(id int, compType string) ([]*appWorkflow.AppWorkflowMapping, error)
6061
CheckCdPipelineByCiPipelineId(id int) bool
6162
FindAppWorkflowByName(name string, appId int) (AppWorkflowDto, error)
62-
63+
IsWorkflowNameFound(workflowName string, appId int) (bool, error)
6364
FindAllWorkflowsComponentDetails(appId int) (*AllAppWorkflowComponentDetails, error)
6465
FindAppWorkflowsByEnvironmentId(request resourceGroup2.ResourceGroupingRequest, token string) ([]*AppWorkflowDto, error)
6566
FindAllWorkflowsForApps(request WorkflowNamesRequest) (*WorkflowNamesResponse, error)
@@ -178,7 +179,10 @@ func (impl AppWorkflowServiceImpl) CreateAppWorkflow(req AppWorkflowDto) (AppWor
178179
var wf *appWorkflow.AppWorkflow
179180
var savedAppWf *appWorkflow.AppWorkflow
180181
var err error
181-
182+
ok, err := impl.IsWorkflowNameFound(req.Name, req.AppId)
183+
if err != nil {
184+
return req, err
185+
}
182186
if req.Id != 0 {
183187
wf = &appWorkflow.AppWorkflow{
184188
Id: req.Id,
@@ -189,19 +193,20 @@ func (impl AppWorkflowServiceImpl) CreateAppWorkflow(req AppWorkflowDto) (AppWor
189193
UpdatedBy: req.UserId,
190194
},
191195
}
192-
savedAppWf, err = impl.appWorkflowRepository.UpdateAppWorkflow(wf)
193-
} else {
194-
workflow, err := impl.appWorkflowRepository.FindByNameAndAppId(req.Name, req.AppId)
195-
if err != nil && err != pg.ErrNoRows {
196-
impl.Logger.Errorw("error in finding workflow by app id and name", "name", req.Name, "appId", req.AppId)
197-
return req, err
198-
}
199-
if workflow.Id != 0 {
196+
// if workflow name already exists then we will not allow update workflow name with same name
197+
if ok {
200198
impl.Logger.Errorw("workflow with this name already exist", "err", err)
201199
return req, errors.New(bean2.WORKFLOW_EXIST_ERROR)
202200
}
201+
savedAppWf, err = impl.appWorkflowRepository.UpdateAppWorkflow(wf)
202+
} else {
203+
workflowName := req.Name
204+
// if workflow already exists then we will assign a new name to the workflow
205+
if ok {
206+
workflowName = util2.GenerateNewWorkflowName(workflowName)
207+
}
203208
wf := &appWorkflow.AppWorkflow{
204-
Name: req.Name,
209+
Name: workflowName,
205210
AppId: req.AppId,
206211
Active: true,
207212
AuditLog: sql.AuditLog{
@@ -911,3 +916,15 @@ func getMappingsFromIds(identifierToNodeMapping map[PipelineIdentifier]*AppWorkf
911916
}
912917
return result
913918
}
919+
920+
func (impl AppWorkflowServiceImpl) IsWorkflowNameFound(workflowName string, appId int) (bool, error) {
921+
workflow, err := impl.appWorkflowRepository.FindByNameAndAppId(workflowName, appId)
922+
if err != nil && !errors.Is(err, pg.ErrNoRows) && !errors.Is(err, pg.ErrMultiRows) {
923+
impl.Logger.Errorw("error in finding workflow by app id and name", "name", workflowName, "appId", appId)
924+
return false, err
925+
}
926+
if workflow.Id != 0 {
927+
return true, nil
928+
}
929+
return false, nil
930+
}

util/helper.go

+5
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ func Generate(size int) string {
135135
return str
136136
}
137137

138+
// Generates random name format name-clone-xyts
139+
func GenerateNewWorkflowName(name string) string {
140+
return fmt.Sprintf("%s-clone-%s", name, Generate(4))
141+
}
142+
138143
func HttpRequest(url string) (map[string]interface{}, error) {
139144
req, err := http.NewRequest(http.MethodGet, url, nil)
140145
if err != nil {

0 commit comments

Comments
 (0)