Skip to content

Commit

Permalink
Update the way of identifying the config-repo for a given pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilsbhat committed Sep 14, 2023
1 parent 5670919 commit 0c0ea8a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 24 deletions.
30 changes: 9 additions & 21 deletions cmd/pipelines.go
Original file line number Diff line number Diff line change
Expand Up @@ -912,35 +912,22 @@ func getPipelineMapping() *cobra.Command {
PreRunE: setCLIClient,
RunE: func(cmd *cobra.Command, args []string) error {
pipelineName := args[0]
var goCDConfigRepoName, goCDEnvironmentName string
var goCDConfigRepoName, goCDEnvironmentName, originGoCD string

cliLogger.Debugf("all configrepo's information would be fetched, to identify pipeline is part of which config repos")
configRepos, err := client.GetConfigRepos()
cliLogger.Debugf("fetching pipeline config to identify which config repo this pipeline is part of")
pipelineConfig, err := client.GetPipelineConfig(pipelineName)
if err != nil {
return err
}

cliLogger.Debugf("all configrepo's information was fetched successfully")
cliLogger.Debugf("pipeline config was retrieved successfully")

for _, configRepo := range configRepos {
cliLogger.Debugf("fetching config repo definition, to identify pipeline is part of which config repo")
configRepoDefinition, err := client.GetConfigRepoDefinitions(configRepo.ID)
if err != nil {
if !strings.Contains(err.Error(), "got 404 from GoCD") {
return err
}
}
for _, pipelineGroup := range configRepoDefinition.Groups {
for _, pipeline := range pipelineGroup.Pipelines {
if pipeline.Name == pipelineName {
goCDConfigRepoName = configRepo.ID
}
}
}
originGoCD = "true"
if pipelineConfig.Origin.Type != "gocd" {
goCDConfigRepoName = pipelineConfig.Origin.ID
originGoCD = "false"
}

cliLogger.Debugf("all GoCD environment information would be fetched, to identify pipeline is part of which environment")

environmentNames, err := client.GetEnvironments()
if err != nil {
return err
Expand All @@ -960,6 +947,7 @@ func getPipelineMapping() *cobra.Command {
"pipeline": pipelineName,
"config_repo": goCDConfigRepoName,
"environment": goCDEnvironmentName,
"origin_gocd": originGoCD,
}

if len(jsonQuery) != 0 {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21

require (
github.com/ghodss/yaml v1.0.0
github.com/nikhilsbhat/gocd-sdk-go v0.1.9-0.20230911084833-1ceb6cff8ea8
github.com/nikhilsbhat/gocd-sdk-go v0.1.9-0.20230914073201-732c431eb78e
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.6.1
github.com/stretchr/testify v1.8.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/nikhilsbhat/gocd-sdk-go v0.1.9-0.20230911084833-1ceb6cff8ea8 h1:64XraEHr9B9gUsBxjQq7BFQyfJwqViBnvq6t90Ks4H0=
github.com/nikhilsbhat/gocd-sdk-go v0.1.9-0.20230911084833-1ceb6cff8ea8/go.mod h1:ubwvA7YgcWDUXiCghrJGRKTdeVuXpDmNzIp6ZvVzdfk=
github.com/nikhilsbhat/gocd-sdk-go v0.1.9-0.20230914073201-732c431eb78e h1:mNeqFt0S4/j+1BEglKPspSH1PrD7jaA0TmcbE8MTQP4=
github.com/nikhilsbhat/gocd-sdk-go v0.1.9-0.20230914073201-732c431eb78e/go.mod h1:ubwvA7YgcWDUXiCghrJGRKTdeVuXpDmNzIp6ZvVzdfk=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down

0 comments on commit 0c0ea8a

Please sign in to comment.