Skip to content
This repository was archived by the owner on May 25, 2023. It is now read-only.

Commit a3c35ca

Browse files
author
Sam McGeown
committed
Fix: importYaml response parsing
1 parent 81b6d25 commit a3c35ca

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

cmd/api-func-shared.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/go-resty/resty/v2"
1414
log "github.com/sirupsen/logrus"
1515
"github.com/spf13/viper"
16+
"gopkg.in/yaml.v2"
1617
)
1718

1819
func ensureTargetConnection() error {
@@ -119,8 +120,17 @@ func importYaml(yamlPath, action string) error {
119120
SetAuthToken(targetConfig.accesstoken).
120121
SetError(&CodeStreamException{}).
121122
Post("https://" + targetConfig.server + "/pipeline/api/import")
123+
log.Debugln(queryResponse.Request.RawRequest.URL)
122124
if queryResponse.IsError() {
123125
return queryResponse.Error().(error)
124126
}
127+
var importResponse CodeStreamPipelineImportResponse
128+
err = yaml.Unmarshal(queryResponse.Body(), &importResponse)
129+
if importResponse.Status != "CREATED" && action == "create" {
130+
return errors.New(importResponse.Status + " - " + importResponse.StatusMessage)
131+
}
132+
if importResponse.Status != "UPDATED" && action == "apply" {
133+
return errors.New(importResponse.Status + " - " + importResponse.StatusMessage)
134+
}
125135
return nil
126136
}

cmd/api-struct.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,10 @@ type CodeStreamCustomIntegration struct {
231231
Status string `json:"status"`
232232
Yaml string `json:"yaml"`
233233
}
234+
235+
// CodeStreamException - Generic exception struct
236+
type CodeStreamPipelineImportResponse struct {
237+
Name string `yaml:"name"`
238+
Status string `yaml:"status"`
239+
StatusMessage string `yaml:"statusMessage"`
240+
}

0 commit comments

Comments
 (0)