Skip to content

Commit 54fa2d9

Browse files
fix: git material url sanitised (#4742)
* fix: git material url sanitised * renamed method --------- Co-authored-by: ShashwatDadhich <[email protected]>
1 parent 1f7e4ba commit 54fa2d9

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

pkg/bean/app.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
bean3 "github.com/devtron-labs/devtron/pkg/deployment/trigger/devtronApps/bean"
3030
"github.com/devtron-labs/devtron/pkg/pipeline/bean"
3131
"github.com/devtron-labs/devtron/pkg/pipeline/repository"
32+
"strings"
3233
"time"
3334
)
3435

@@ -81,6 +82,13 @@ type GitMaterial struct {
8182
FilterPattern []string `json:"filterPattern"`
8283
}
8384

85+
// UpdateSanitisedGitRepoUrl will remove all trailing slashes from git repository url
86+
func (m *GitMaterial) UpdateSanitisedGitRepoUrl() {
87+
for strings.HasSuffix(m.Url, "/") {
88+
m.Url = strings.TrimSuffix(m.Url, "/")
89+
}
90+
}
91+
8492
type CiMaterial struct {
8593
Source *SourceTypeConfig `json:"source,omitempty" validate:"dive,required"` //branch for ci
8694
Path string `json:"path,omitempty"` // defaults to root of git repo

pkg/pipeline/CiCdPipelineOrchestrator.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,6 +1291,7 @@ func (impl CiCdPipelineOrchestratorImpl) CreateMaterials(createMaterialRequest *
12911291
}
12921292
var materials []*bean.GitMaterial
12931293
for _, inputMaterial := range createMaterialRequest.Material {
1294+
inputMaterial.UpdateSanitisedGitRepoUrl()
12941295
m, err := impl.createMaterial(inputMaterial, createMaterialRequest.AppId, createMaterialRequest.UserId)
12951296
inputMaterial.Id = m.Id
12961297
if err != nil {
@@ -1481,6 +1482,7 @@ func (impl CiCdPipelineOrchestratorImpl) updateMaterial(updateMaterialDTO *bean.
14811482
impl.logger.Errorw("validation err", "err", err)
14821483
return nil, validationErr
14831484
}
1485+
updateMaterialDTO.Material.UpdateSanitisedGitRepoUrl()
14841486
currentMaterial.Url = updateMaterialDTO.Material.Url
14851487
basePath := path.Base(updateMaterialDTO.Material.Url)
14861488
basePath = strings.TrimSuffix(basePath, ".git")

0 commit comments

Comments
 (0)