Skip to content

Commit 36cf273

Browse files
committed
name suggestion util
1 parent 04e5177 commit 36cf273

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

api/restHandler/app/pipeline/configure/PipelineConfigRestHandler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
security2 "github.com/devtron-labs/devtron/pkg/policyGovernance/security/imageScanning"
3636
"github.com/devtron-labs/devtron/pkg/policyGovernance/security/imageScanning/read"
3737
read3 "github.com/devtron-labs/devtron/pkg/team/read"
38+
"github.com/devtron-labs/devtron/util/beHelper"
3839
"io"
3940
"net/http"
4041
"strconv"
@@ -60,7 +61,6 @@ import (
6061
"github.com/devtron-labs/devtron/pkg/bean"
6162
"github.com/devtron-labs/devtron/pkg/pipeline"
6263
"github.com/devtron-labs/devtron/pkg/team"
63-
util2 "github.com/devtron-labs/devtron/util"
6464
"github.com/devtron-labs/devtron/util/rbac"
6565
"github.com/gorilla/mux"
6666
"go.uber.org/zap"
@@ -663,7 +663,7 @@ func (handler *PipelineConfigRestHandlerImpl) PipelineNameSuggestion(w http.Resp
663663
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
664664
return
665665
}
666-
suggestedName := fmt.Sprintf("%s-%d-%s", pType, appId, util2.Generate(4))
666+
suggestedName := beHelper.GetPipelineNameByPipelineType(pType, appId)
667667
resourceName := handler.enforcerUtil.GetAppRBACName(app.AppName)
668668
ok := handler.enforcerUtil.CheckAppRbacForAppOrJob(token, resourceName, casbin.ActionGet)
669669
if !ok {

pkg/pipeline/CiCdPipelineOrchestrator.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import (
4040
constants3 "github.com/devtron-labs/devtron/pkg/pipeline/constants"
4141
util4 "github.com/devtron-labs/devtron/pkg/pipeline/util"
4242
"github.com/devtron-labs/devtron/pkg/plugin"
43+
"github.com/devtron-labs/devtron/util/beHelper"
4344
"github.com/devtron-labs/devtron/util/sliceUtil"
4445
"golang.org/x/exp/slices"
4546
"net/http"
@@ -2276,7 +2277,7 @@ func (impl CiCdPipelineOrchestratorImpl) AddPipelineToTemplate(createRequest *be
22762277
if createRequest.AppWorkflowId == 0 {
22772278
// create workflow
22782279
wf := &appWorkflow.AppWorkflow{
2279-
Name: fmt.Sprintf("wf-%d-%s", createRequest.AppId, util2.Generate(4)),
2280+
Name: beHelper.GetAppWorkflowName(createRequest.AppId),
22802281
AppId: createRequest.AppId,
22812282
Active: true,
22822283
AuditLog: sql.AuditLog{

pkg/pipeline/DeploymentPipelineConfigService.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ import (
7878
"github.com/devtron-labs/devtron/pkg/variables"
7979
repository3 "github.com/devtron-labs/devtron/pkg/variables/repository"
8080
globalUtil "github.com/devtron-labs/devtron/util"
81+
"github.com/devtron-labs/devtron/util/beHelper"
8182
"github.com/devtron-labs/devtron/util/rbac"
8283
"github.com/go-pg/pg"
8384
errors2 "github.com/juju/errors"
@@ -2024,7 +2025,7 @@ func (impl *CdPipelineConfigServiceImpl) createCdPipeline(ctx context.Context, a
20242025
if (pipeline.AppWorkflowId == 0 || pipeline.IsSwitchCiPipelineRequest()) && pipeline.ParentPipelineType == "WEBHOOK" {
20252026
if pipeline.AppWorkflowId == 0 {
20262027
wf := &appWorkflow.AppWorkflow{
2027-
Name: fmt.Sprintf("wf-%d-%s", app.Id, globalUtil.Generate(4)),
2028+
Name: beHelper.GetAppWorkflowName(app.Id),
20282029
AppId: app.Id,
20292030
Active: true,
20302031
AuditLog: sql.AuditLog{CreatedBy: userId, CreatedOn: time.Now(), UpdatedOn: time.Now(), UpdatedBy: userId},

util/beHelper/nameSuggestionUtil.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package beHelper
2+
3+
import (
4+
"fmt"
5+
"github.com/devtron-labs/common-lib/git-manager/util"
6+
util2 "github.com/devtron-labs/devtron/util"
7+
)
8+
9+
func GetCIPipelineName(appId int) string {
10+
return fmt.Sprintf("ci-%d-%s", appId, util2.Generate(4))
11+
}
12+
13+
func GetCDPipelineName(appId int) string {
14+
return fmt.Sprintf("cd-%d-%s", appId, util2.Generate(4))
15+
}
16+
17+
func GetAppWorkflowName(appId int) string {
18+
return fmt.Sprintf("wf-%d-%s", appId, util2.Generate(4))
19+
}
20+
21+
func GetPipelineNameByPipelineType(pipelineType string, appId int) string {
22+
return fmt.Sprintf("%s-%d-%s", pipelineType, appId, util.Generate(4))
23+
}

0 commit comments

Comments
 (0)