Skip to content

Commit

Permalink
Assuming that the user did not fill in the .yml suffix, it will be fi…
Browse files Browse the repository at this point in the history
…lled in automatically when creating
  • Loading branch information
kakj-go committed Oct 29, 2021
1 parent 41b9878 commit e0fb2a5
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"strings"

"github.com/erda-project/erda/apistructs"
protocol "github.com/erda-project/erda/modules/openapi/component-protocol"
Expand Down Expand Up @@ -109,14 +110,20 @@ func (a *ComponentNodeFormModal) handlerSubmitOperation(ctxBdl protocol.ContextB
if formData.Branch == "" || formData.Name == "" {
return fmt.Errorf("name %s or branch %s error: value is empty", formData.Name, formData.Branch)
}
if formData.Name == "pipeline.yml" {
if formData.Name == "pipeline.yml" || formData.Name == "pipeline" || formData.Name == "pipeline.yaml" {
return fmt.Errorf("can not add pipeline.yml yml already exists")
} else {
pinode := fmt.Sprintf("%s/%s/tree/%s/.dice/pipelines", inParams.ProjectId, inParams.AppId, formData.Branch)
var req apistructs.UnifiedFileTreeNodeCreateRequest
req.Scope = apistructs.FileTreeScopeProjectApp
req.ScopeID = inParams.ProjectId
req.Name = formData.Name

// assuming that the user did not fill in the .yml suffix, it will be filled in automatically when creating
req.Name = strings.TrimSuffix(req.Name, ".yaml")
if !strings.HasSuffix(req.Name, ".yml") {
req.Name += ".yml"
}
req.UserID = ctxBdl.Identity.UserID
req.Type = apistructs.UnifiedFileTreeNodeTypeFile
req.Pinode = base64.StdEncoding.EncodeToString([]byte(pinode))
Expand Down

0 comments on commit e0fb2a5

Please sign in to comment.