diff --git a/cmd/submitplan.go b/cmd/submitplan.go index d748d208..b555ae62 100644 --- a/cmd/submitplan.go +++ b/cmd/submitplan.go @@ -221,23 +221,53 @@ func SubmitPlan(signals chan os.Signal, ready chan bool) int { } client := AuthenticatedChangesClient(ctx) - createResponse, err := client.CreateChange(ctx, &connect.Request[sdp.CreateChangeRequest]{ - Msg: &sdp.CreateChangeRequest{ - Properties: &sdp.ChangeProperties{ - Title: viper.GetString("title"), - Description: viper.GetString("description"), - TicketLink: viper.GetString("ticket-link"), - Owner: viper.GetString("owner"), - // CcEmails: viper.GetString("cc-emails"), - }, + + var changeUUID *uuid.UUID + + changesList, err := client.ListChangesByStatus(ctx, &connect.Request[sdp.ListChangesByStatusRequest]{ + Msg: &sdp.ListChangesByStatusRequest{ + Status: sdp.ChangeStatus_CHANGE_STATUS_DEFINING, }, }) if err != nil { - log.WithContext(ctx).WithError(err).WithFields(lf).Error("failed to create change") + log.WithContext(ctx).WithError(err).WithFields(lf).Error("failed to searching for existing changes") return 1 } - lf["change"] = createResponse.Msg.Change.Metadata.GetUUIDParsed() + for _, c := range changesList.Msg.Changes { + if c.Properties.TicketLink == viper.GetString("ticket-link") { + changeUUID = c.Metadata.GetUUIDParsed() + if changeUUID != nil { + break + } + } + } + + if changeUUID == nil { + createResponse, err := client.CreateChange(ctx, &connect.Request[sdp.CreateChangeRequest]{ + Msg: &sdp.CreateChangeRequest{ + Properties: &sdp.ChangeProperties{ + Title: viper.GetString("title"), + Description: viper.GetString("description"), + TicketLink: viper.GetString("ticket-link"), + Owner: viper.GetString("owner"), + // CcEmails: viper.GetString("cc-emails"), + }, + }, + }) + if err != nil { + log.WithContext(ctx).WithError(err).WithFields(lf).Error("failed to create change") + return 1 + } + + changeUUID = createResponse.Msg.Change.Metadata.GetUUIDParsed() + if changeUUID == nil { + log.WithContext(ctx).WithError(err).WithFields(lf).Error("failed to read change id") + return 1 + } + } + + lf["change"] = changeUUID log.WithContext(ctx).WithFields(lf).Info("created a new change") receivedItems := []*sdp.Reference{} @@ -419,7 +449,7 @@ func SubmitPlan(signals chan os.Signal, ready chan bool) int { } resultStream, err := client.UpdateChangingItems(ctx, &connect.Request[sdp.UpdateChangingItemsRequest]{ Msg: &sdp.UpdateChangingItemsRequest{ - ChangeUUID: createResponse.Msg.Change.Metadata.UUID, + ChangeUUID: (*changeUUID)[:], ChangingItems: receivedItems, }, }) @@ -448,13 +478,13 @@ func SubmitPlan(signals chan os.Signal, ready chan bool) int { } } - changeUrl := fmt.Sprintf("%v/changes/%v", viper.GetString("frontend"), createResponse.Msg.Change.Metadata.GetUUIDParsed()) + changeUrl := fmt.Sprintf("%v/changes/%v", viper.GetString("frontend"), changeUUID) log.WithContext(ctx).WithFields(lf).WithField("change-url", changeUrl).Info("change ready") fmt.Println(changeUrl) fetchResponse, err := client.GetChange(ctx, &connect.Request[sdp.GetChangeRequest]{ Msg: &sdp.GetChangeRequest{ - UUID: createResponse.Msg.Change.Metadata.UUID, + UUID: (*changeUUID)[:], }, }) if err != nil { diff --git a/go.mod b/go.mod index 95f37be6..321e3a28 100644 --- a/go.mod +++ b/go.mod @@ -6,11 +6,12 @@ require ( github.com/bufbuild/connect-go v1.10.0 github.com/getsentry/sentry-go v0.22.0 github.com/google/uuid v1.3.0 - github.com/overmindtech/sdp-go v0.41.1 + github.com/overmindtech/sdp-go v0.43.0 github.com/sirupsen/logrus v1.9.3 github.com/spf13/cobra v1.7.0 github.com/spf13/viper v1.16.0 github.com/uptrace/opentelemetry-go-extra/otellogrus v0.2.2 + github.com/xiam/dig v0.0.0-20191116195832-893b5fb5093b go.opentelemetry.io/contrib/detectors/aws/ec2 v1.17.0 go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.42.0 go.opentelemetry.io/otel v1.16.0 @@ -41,7 +42,6 @@ require ( github.com/magiconair/properties v1.8.7 // indirect github.com/minio/highwayhash v1.0.2 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect - github.com/nats-io/jwt/v2 v2.4.1 // indirect github.com/nats-io/nats.go v1.28.0 // indirect github.com/nats-io/nkeys v0.4.4 // indirect github.com/nats-io/nuid v1.0.1 // indirect @@ -54,7 +54,6 @@ require ( github.com/spf13/pflag v1.0.5 // indirect github.com/subosito/gotenv v1.4.2 // indirect github.com/uptrace/opentelemetry-go-extra/otelutil v0.2.2 // indirect - github.com/xiam/dig v0.0.0-20191116195832-893b5fb5093b // indirect github.com/xiam/to v0.0.0-20191116183551-8328998fc0ed // indirect go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.16.0 // indirect go.opentelemetry.io/otel/metric v1.16.0 // indirect diff --git a/go.sum b/go.sum index bf81b433..7024cc11 100644 --- a/go.sum +++ b/go.sum @@ -44,8 +44,6 @@ github.com/auth0/go-jwt-middleware/v2 v2.1.0 h1:VU4LsC3aFPoqXVyEp8EixU6FNM+ZNIjE github.com/auth0/go-jwt-middleware/v2 v2.1.0/go.mod h1:CpzcJoleayAACpv+vt0AP8/aYn5TDngsqzLapV1nM4c= github.com/aws/aws-sdk-go v1.44.266 h1:MWd775dcYf7NrwgcHLtlsIbWoWkX8p4vomfNHr88zH0= github.com/aws/aws-sdk-go v1.44.266/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI= -github.com/bufbuild/connect-go v1.9.0 h1:JIgAeNuFpo+SUPfU19Yt5TcWlznsN5Bv10/gI/6Pjoc= -github.com/bufbuild/connect-go v1.9.0/go.mod h1:CAIePUgkDR5pAFaylSMtNK45ANQjp9JvpluG20rhpV8= github.com/bufbuild/connect-go v1.10.0 h1:QAJ3G9A1OYQW2Jbk3DeoJbkCxuKArrvZgDt47mjdTbg= github.com/bufbuild/connect-go v1.10.0/go.mod h1:CAIePUgkDR5pAFaylSMtNK45ANQjp9JvpluG20rhpV8= github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM= @@ -226,22 +224,15 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/nats-io/jwt/v2 v2.4.1 h1:Y35W1dgbbz2SQUYDPCaclXcuqleVmpbRa7646Jf2EX4= -github.com/nats-io/jwt/v2 v2.4.1/go.mod h1:24BeQtRwxRV8ruvC4CojXlx/WQ/VjuwlYiH+vu/+ibI= github.com/nats-io/nats-server/v2 v2.9.15 h1:MuwEJheIwpvFgqvbs20W8Ish2azcygjf4Z0liVu2I4c= -github.com/nats-io/nats.go v1.27.1 h1:OuYnal9aKVSnOzLQIzf7554OXMCG7KbaTkCSBHRcSoo= -github.com/nats-io/nats.go v1.27.1/go.mod h1:XpbWUlOElGwTYbMR7imivs7jJj9GtK7ypv321Wp6pjc= github.com/nats-io/nats.go v1.28.0 h1:Th4G6zdsz2d0OqXdfzKLClo6bOfoI/b1kInhRtFIy5c= github.com/nats-io/nats.go v1.28.0/go.mod h1:XpbWUlOElGwTYbMR7imivs7jJj9GtK7ypv321Wp6pjc= github.com/nats-io/nkeys v0.4.4 h1:xvBJ8d69TznjcQl9t6//Q5xXuVhyYiSos6RPtvQNTwA= github.com/nats-io/nkeys v0.4.4/go.mod h1:XUkxdLPTufzlihbamfzQ7mw/VGx6ObUs+0bN5sNvt64= github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= -github.com/overmindtech/sdp-go v0.36.2 h1:pIBMzuADDR1A10lZk0zQcroo2VzeNwmiYXpA/0h5Q3Q= -github.com/overmindtech/sdp-go v0.36.2/go.mod h1:LIUppm58V+JpNJsPCXiBOwlySgQ9uacsC+Hfl5D/zQo= -github.com/overmindtech/sdp-go v0.41.0 h1:eIBLblW2MDCCEk7ZSPk6sFo/1piMzba1+nUDa722vOo= -github.com/overmindtech/sdp-go v0.41.0/go.mod h1:fwGtzDA7h//c+QBnOhRa7KQRt1RFFWMPnVndH+39GLs= -github.com/overmindtech/sdp-go v0.41.1 h1:dm4keWKodQkomA3MVkFFCV1eLtFbaSEo9SFOYxF8LE0= -github.com/overmindtech/sdp-go v0.41.1/go.mod h1:s/CnUoFH5WfugwQ6+v8M+0JXvCMlq1/bz2ha2G7B92E= +github.com/overmindtech/sdp-go v0.43.0 h1:1BVry/jSKABqEYKmLMIC8XCJIcWt0iWDDHU7AVROJwE= +github.com/overmindtech/sdp-go v0.43.0/go.mod h1:s/CnUoFH5WfugwQ6+v8M+0JXvCMlq1/bz2ha2G7B92E= github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ= github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4= github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4=