Skip to content

Commit

Permalink
Fix the error when the user did not fill in the .yml when creating th…
Browse files Browse the repository at this point in the history
…e pipeline (erda-project#2685)

* update projectID to projectId (erda-project#2534)

* Assuming that the user did not fill in the .yml suffix, it will be filled in automatically when creating

Co-authored-by: littlejian <17816869670@163.com>
  • Loading branch information
2 people authored and erda-bot committed Oct 29, 2021
1 parent e7b6ef2 commit 98f5a24
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 98f5a24

Please sign in to comment.