Skip to content

Commit 566b5da

Browse files
committed
Implement re-using an existing change in submit-plan
The change has to be in DEFINING and have the same ticket link to be eligible for re-use. This will reduce the amount of abandoned Changes when using the github action.
1 parent c5feef1 commit 566b5da

File tree

3 files changed

+41
-27
lines changed

3 files changed

+41
-27
lines changed

cmd/submitplan.go

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -221,26 +221,50 @@ func SubmitPlan(signals chan os.Signal, ready chan bool) int {
221221
}
222222

223223
client := AuthenticatedChangesClient(ctx)
224-
createResponse, err := client.CreateChange(ctx, &connect.Request[sdp.CreateChangeRequest]{
225-
Msg: &sdp.CreateChangeRequest{
226-
Properties: &sdp.ChangeProperties{
227-
Title: viper.GetString("title"),
228-
Description: viper.GetString("description"),
229-
TicketLink: viper.GetString("ticket-link"),
230-
Owner: viper.GetString("owner"),
231-
// CcEmails: viper.GetString("cc-emails"),
232-
},
224+
225+
var changeUUID *uuid.UUID
226+
227+
changesList, err := client.ListChangesByStatus(ctx, &connect.Request[sdp.ListChangesByStatusRequest]{
228+
Msg: &sdp.ListChangesByStatusRequest{
229+
Status: sdp.ChangeStatus_CHANGE_STATUS_DEFINING,
233230
},
234231
})
235232
if err != nil {
236-
log.WithContext(ctx).WithError(err).WithFields(lf).Error("failed to create change")
233+
log.WithContext(ctx).WithError(err).WithFields(lf).Error("failed to searching for existing changes")
237234
return 1
238235
}
239236

240-
changeUUID := createResponse.Msg.Change.Metadata.GetUUIDParsed()
237+
for _, c := range changesList.Msg.Changes {
238+
if c.Properties.TicketLink == viper.GetString("ticket-link") {
239+
changeUUID = c.Metadata.GetUUIDParsed()
240+
if changeUUID != nil {
241+
break
242+
}
243+
}
244+
}
245+
241246
if changeUUID == nil {
242-
log.WithContext(ctx).WithError(err).WithFields(lf).Error("failed to read change id")
243-
return 1
247+
createResponse, err := client.CreateChange(ctx, &connect.Request[sdp.CreateChangeRequest]{
248+
Msg: &sdp.CreateChangeRequest{
249+
Properties: &sdp.ChangeProperties{
250+
Title: viper.GetString("title"),
251+
Description: viper.GetString("description"),
252+
TicketLink: viper.GetString("ticket-link"),
253+
Owner: viper.GetString("owner"),
254+
// CcEmails: viper.GetString("cc-emails"),
255+
},
256+
},
257+
})
258+
if err != nil {
259+
log.WithContext(ctx).WithError(err).WithFields(lf).Error("failed to create change")
260+
return 1
261+
}
262+
263+
changeUUID = createResponse.Msg.Change.Metadata.GetUUIDParsed()
264+
if changeUUID == nil {
265+
log.WithContext(ctx).WithError(err).WithFields(lf).Error("failed to read change id")
266+
return 1
267+
}
244268
}
245269

246270
lf["change"] = changeUUID

go.mod

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ require (
66
github.com/bufbuild/connect-go v1.10.0
77
github.com/getsentry/sentry-go v0.22.0
88
github.com/google/uuid v1.3.0
9-
github.com/overmindtech/sdp-go v0.41.1
9+
github.com/overmindtech/sdp-go v0.43.0
1010
github.com/sirupsen/logrus v1.9.3
1111
github.com/spf13/cobra v1.7.0
1212
github.com/spf13/viper v1.16.0
1313
github.com/uptrace/opentelemetry-go-extra/otellogrus v0.2.2
14+
github.com/xiam/dig v0.0.0-20191116195832-893b5fb5093b
1415
go.opentelemetry.io/contrib/detectors/aws/ec2 v1.17.0
1516
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.42.0
1617
go.opentelemetry.io/otel v1.16.0
@@ -41,7 +42,6 @@ require (
4142
github.com/magiconair/properties v1.8.7 // indirect
4243
github.com/minio/highwayhash v1.0.2 // indirect
4344
github.com/mitchellh/mapstructure v1.5.0 // indirect
44-
github.com/nats-io/jwt/v2 v2.4.1 // indirect
4545
github.com/nats-io/nats.go v1.28.0 // indirect
4646
github.com/nats-io/nkeys v0.4.4 // indirect
4747
github.com/nats-io/nuid v1.0.1 // indirect
@@ -54,7 +54,6 @@ require (
5454
github.com/spf13/pflag v1.0.5 // indirect
5555
github.com/subosito/gotenv v1.4.2 // indirect
5656
github.com/uptrace/opentelemetry-go-extra/otelutil v0.2.2 // indirect
57-
github.com/xiam/dig v0.0.0-20191116195832-893b5fb5093b // indirect
5857
github.com/xiam/to v0.0.0-20191116183551-8328998fc0ed // indirect
5958
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.16.0 // indirect
6059
go.opentelemetry.io/otel/metric v1.16.0 // indirect

go.sum

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ github.com/auth0/go-jwt-middleware/v2 v2.1.0 h1:VU4LsC3aFPoqXVyEp8EixU6FNM+ZNIjE
4444
github.com/auth0/go-jwt-middleware/v2 v2.1.0/go.mod h1:CpzcJoleayAACpv+vt0AP8/aYn5TDngsqzLapV1nM4c=
4545
github.com/aws/aws-sdk-go v1.44.266 h1:MWd775dcYf7NrwgcHLtlsIbWoWkX8p4vomfNHr88zH0=
4646
github.com/aws/aws-sdk-go v1.44.266/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
47-
github.com/bufbuild/connect-go v1.9.0 h1:JIgAeNuFpo+SUPfU19Yt5TcWlznsN5Bv10/gI/6Pjoc=
48-
github.com/bufbuild/connect-go v1.9.0/go.mod h1:CAIePUgkDR5pAFaylSMtNK45ANQjp9JvpluG20rhpV8=
4947
github.com/bufbuild/connect-go v1.10.0 h1:QAJ3G9A1OYQW2Jbk3DeoJbkCxuKArrvZgDt47mjdTbg=
5048
github.com/bufbuild/connect-go v1.10.0/go.mod h1:CAIePUgkDR5pAFaylSMtNK45ANQjp9JvpluG20rhpV8=
5149
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
226224
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
227225
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
228226
github.com/nats-io/jwt/v2 v2.4.1 h1:Y35W1dgbbz2SQUYDPCaclXcuqleVmpbRa7646Jf2EX4=
229-
github.com/nats-io/jwt/v2 v2.4.1/go.mod h1:24BeQtRwxRV8ruvC4CojXlx/WQ/VjuwlYiH+vu/+ibI=
230227
github.com/nats-io/nats-server/v2 v2.9.15 h1:MuwEJheIwpvFgqvbs20W8Ish2azcygjf4Z0liVu2I4c=
231-
github.com/nats-io/nats.go v1.27.1 h1:OuYnal9aKVSnOzLQIzf7554OXMCG7KbaTkCSBHRcSoo=
232-
github.com/nats-io/nats.go v1.27.1/go.mod h1:XpbWUlOElGwTYbMR7imivs7jJj9GtK7ypv321Wp6pjc=
233228
github.com/nats-io/nats.go v1.28.0 h1:Th4G6zdsz2d0OqXdfzKLClo6bOfoI/b1kInhRtFIy5c=
234229
github.com/nats-io/nats.go v1.28.0/go.mod h1:XpbWUlOElGwTYbMR7imivs7jJj9GtK7ypv321Wp6pjc=
235230
github.com/nats-io/nkeys v0.4.4 h1:xvBJ8d69TznjcQl9t6//Q5xXuVhyYiSos6RPtvQNTwA=
236231
github.com/nats-io/nkeys v0.4.4/go.mod h1:XUkxdLPTufzlihbamfzQ7mw/VGx6ObUs+0bN5sNvt64=
237232
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
238233
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
239-
github.com/overmindtech/sdp-go v0.36.2 h1:pIBMzuADDR1A10lZk0zQcroo2VzeNwmiYXpA/0h5Q3Q=
240-
github.com/overmindtech/sdp-go v0.36.2/go.mod h1:LIUppm58V+JpNJsPCXiBOwlySgQ9uacsC+Hfl5D/zQo=
241-
github.com/overmindtech/sdp-go v0.41.0 h1:eIBLblW2MDCCEk7ZSPk6sFo/1piMzba1+nUDa722vOo=
242-
github.com/overmindtech/sdp-go v0.41.0/go.mod h1:fwGtzDA7h//c+QBnOhRa7KQRt1RFFWMPnVndH+39GLs=
243-
github.com/overmindtech/sdp-go v0.41.1 h1:dm4keWKodQkomA3MVkFFCV1eLtFbaSEo9SFOYxF8LE0=
244-
github.com/overmindtech/sdp-go v0.41.1/go.mod h1:s/CnUoFH5WfugwQ6+v8M+0JXvCMlq1/bz2ha2G7B92E=
234+
github.com/overmindtech/sdp-go v0.43.0 h1:1BVry/jSKABqEYKmLMIC8XCJIcWt0iWDDHU7AVROJwE=
235+
github.com/overmindtech/sdp-go v0.43.0/go.mod h1:s/CnUoFH5WfugwQ6+v8M+0JXvCMlq1/bz2ha2G7B92E=
245236
github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ=
246237
github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4=
247238
github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4=

0 commit comments

Comments
 (0)