diff --git a/cmd/status.go b/cmd/status.go index 873d6a0d..e169b483 100644 --- a/cmd/status.go +++ b/cmd/status.go @@ -387,22 +387,27 @@ type statusWorkspaceEventModel struct { publishPackageRegistryName *string publishPackageURL *string publishPackageVersion *string + lastPublishCreatedAt time.Time success bool } -func newStatusWorkspaceEventModel(event shared.CliEvent) *statusWorkspaceEventModel { +func newStatusWorkspaceEventModel(target shared.TargetSDK) *statusWorkspaceEventModel { result := &statusWorkspaceEventModel{ - continuousIntegrationEnvironment: event.ContinuousIntegrationEnvironment, - createdAt: event.CreatedAt, - ghActionRunLink: event.GhActionRunLink, - gitUserEmail: event.GitUserEmail, - gitUserName: event.GitUserName, - hostname: event.Hostname, - publishPackageName: event.PublishPackageName, - publishPackageRegistryName: event.PublishPackageRegistryName, - publishPackageURL: event.PublishPackageURL, - publishPackageVersion: event.PublishPackageVersion, - success: event.Success, + continuousIntegrationEnvironment: target.ContinuousIntegrationEnvironment, + createdAt: target.LastEventCreatedAt, + ghActionRunLink: target.GhActionRunLink, + gitUserEmail: target.GitUserEmail, + gitUserName: target.GitUserName, + hostname: target.Hostname, + publishPackageName: target.PublishPackageName, + publishPackageRegistryName: target.PublishPackageRegistryName, + publishPackageURL: target.PublishPackageURL, + publishPackageVersion: target.PublishPackageVersion, + success: target.Success != nil && *target.Success, + } + + if target.LastPublishCreatedAt != nil { + result.lastPublishCreatedAt = *target.LastPublishCreatedAt } return result @@ -447,7 +452,7 @@ func (m statusWorkspaceEventModel) PublishInfo() string { result.WriteString("locally at ") } - result.WriteString(m.createdAt.Format(time.RFC3339)) + result.WriteString(m.lastPublishCreatedAt.Format(time.RFC3339)) result.WriteString(" by ") if m.ghActionRunLink != nil { @@ -489,13 +494,7 @@ type statusWorkspaceTargetModel struct { lastEventCreatedAt time.Time success *bool - // Generate events - generateLastEvent *statusWorkspaceEventModel - generateLastSuccessEvent *statusWorkspaceEventModel - - // Publish events - publishLastEvent *statusWorkspaceEventModel - publishLastSuccessEvent *statusWorkspaceEventModel + workspaceEventCompilation *statusWorkspaceEventModel // Speakeasy URL speakeasyURL string @@ -532,58 +531,7 @@ func newStatusWorkspaceTargetModel(ctx context.Context, client *speakeasyclients result.upgradeDocumentationURL = &upgradeURL } - lastGenerateEvent, err := searchWorkspaceTargetLastEvent(ctx, client, workspace.id, target.ID, shared.InteractionTypeTargetGenerate, false) - - if err != nil { - return result, fmt.Errorf("error searching last Speakeasy target generate event: %w", err) - } - - if lastGenerateEvent != nil { - result.generateLastEvent = newStatusWorkspaceEventModel(*lastGenerateEvent) - - if lastGenerateEvent.Success { - result.generateLastSuccessEvent = result.generateLastEvent - } - } - - if result.generateLastSuccessEvent == nil { - lastGenerateSuccessEvent, err := searchWorkspaceTargetLastEvent(ctx, client, workspace.id, target.ID, shared.InteractionTypeTargetGenerate, true) - - if err != nil { - return result, fmt.Errorf("error searching last Speakeasy target generate success event: %w", err) - } - - if lastGenerateSuccessEvent != nil { - result.generateLastSuccessEvent = newStatusWorkspaceEventModel(*lastGenerateSuccessEvent) - } - } - - lastPublishEvent, err := searchWorkspaceTargetLastEvent(ctx, client, workspace.id, target.ID, shared.InteractionTypePublish, false) - - if err != nil { - return result, fmt.Errorf("error searching last Speakeasy target publish event: %w", err) - } - - if lastPublishEvent != nil { - result.publishLastEvent = newStatusWorkspaceEventModel(*lastPublishEvent) - - if lastPublishEvent.Success { - result.publishLastSuccessEvent = result.publishLastEvent - } - } - - if result.publishLastSuccessEvent == nil { - lastPublishSuccessEvent, err := searchWorkspaceTargetLastEvent(ctx, client, workspace.id, target.ID, shared.InteractionTypePublish, true) - - if err != nil { - return result, fmt.Errorf("error searching last Speakeasy target publish success event: %w", err) - } - - if lastPublishSuccessEvent != nil { - result.publishLastSuccessEvent = newStatusWorkspaceEventModel(*lastPublishSuccessEvent) - } - } - + result.workspaceEventCompilation = newStatusWorkspaceEventModel(target) return result, nil } @@ -628,15 +576,7 @@ func (m statusWorkspaceTargetModel) RepositoryURL() string { } func (m statusWorkspaceTargetModel) Success() bool { - if event := m.publishLastEvent; event != nil && !event.success { - return false - } - - if event := m.generateLastEvent; event != nil && !event.success { - return false - } - - return true + return m.workspaceEventCompilation.success } func (m statusWorkspaceTargetModel) TargetHeading() string { @@ -653,7 +593,7 @@ func (m statusWorkspaceTargetModel) TargetHeading() string { result.WriteString("Unconfigured") } - if event := m.publishLastSuccessEvent; event != nil && event.publishPackageName != nil && event.publishPackageVersion != nil { + if event := m.workspaceEventCompilation; event != nil && event.publishPackageName != nil && event.publishPackageVersion != nil { result.WriteString(": ") result.WriteString(*event.publishPackageVersion) } else if m.generateConfigPostVersion != nil { @@ -671,28 +611,14 @@ func (m statusWorkspaceTargetModel) TargetHeading() string { func (m statusWorkspaceTargetModel) TargetInfo(ctx context.Context) []string { var result []string - - if m.publishLastEvent != nil && !m.publishLastEvent.success { - var message strings.Builder - - message.WriteString(renderAlertErrorText("✖ Last Publish Failed")) - - if m.publishLastEvent.ghActionRunLink != nil { - message.WriteString(renderAlertErrorText(": ")) - message.WriteString(renderAlertErrorURL(links.Shorten(ctx, *m.publishLastEvent.ghActionRunLink))) - } - - result = append(result, message.String()) - } - - if m.generateLastEvent != nil && !m.generateLastEvent.success { + if m.workspaceEventCompilation != nil && !m.workspaceEventCompilation.success { var message strings.Builder message.WriteString(renderAlertErrorText("✖ Last Generate Failed")) - if m.generateLastEvent.ghActionRunLink != nil { + if m.workspaceEventCompilation.ghActionRunLink != nil { message.WriteString(renderAlertErrorText(": ")) - message.WriteString(renderAlertErrorURL(links.Shorten(ctx, *m.generateLastEvent.ghActionRunLink))) + message.WriteString(renderAlertErrorURL(links.Shorten(ctx, *m.workspaceEventCompilation.ghActionRunLink))) } result = append(result, message.String()) @@ -702,8 +628,8 @@ func (m statusWorkspaceTargetModel) TargetInfo(ctx context.Context) []string { result = append(result, renderAlertWarningText("⚠ Target Upgrade Available: ")+renderAlertWarningURL(*m.upgradeDocumentationURL)) } - if m.publishLastSuccessEvent != nil && m.publishLastSuccessEvent.publishPackageURL != nil { - result = append(result, renderInfoText("Publish URL: ")+renderInfoURL(*m.publishLastSuccessEvent.publishPackageURL)) + if m.workspaceEventCompilation != nil && m.workspaceEventCompilation.publishPackageURL != nil { + result = append(result, renderInfoText("Publish URL: ")+renderInfoURL(*m.workspaceEventCompilation.publishPackageURL)) } if m.RepositoryURL() != "" { @@ -712,33 +638,11 @@ func (m statusWorkspaceTargetModel) TargetInfo(ctx context.Context) []string { result = append(result, renderInfoText("Speakeasy URL: "+renderInfoURL(m.speakeasyURL))) - if m.publishLastEvent != nil { - if !m.publishLastEvent.success { - result = append(result, renderInfoText("Last Publish Attempt: "+m.publishLastEvent.PublishInfo())) - - if m.publishLastSuccessEvent != nil { - result = append(result, renderInfoText("Last Publish Success: "+m.publishLastSuccessEvent.GenerateInfo())) - } else { - result = append(result, renderInfoText("Last Publish Success: Unknown")) - } - } else { - result = append(result, renderInfoText("Last Publish: "+m.publishLastEvent.PublishInfo())) - } + if m.workspaceEventCompilation != nil && m.workspaceEventCompilation.publishPackageName != nil { + result = append(result, renderInfoText("Last Publish: "+m.workspaceEventCompilation.PublishInfo())) } - if m.generateLastEvent != nil { - if !m.generateLastEvent.success { - result = append(result, renderInfoText("Last Generate Attempt: "+m.generateLastEvent.GenerateInfo())) - - if m.generateLastSuccessEvent != nil { - result = append(result, renderInfoText("Last Generate Success: "+m.generateLastSuccessEvent.GenerateInfo())) - } else { - result = append(result, renderInfoText("Last Generate Success: Unknown")) - } - } else { - result = append(result, renderInfoText("Last Generate: "+m.generateLastEvent.GenerateInfo())) - } - } else { + if m.workspaceEventCompilation != nil { result = append(result, renderInfoText("Last Generate: "+m.GenerateInfo())) } diff --git a/go.mod b/go.mod index 13445309..642dd888 100644 --- a/go.mod +++ b/go.mod @@ -26,8 +26,8 @@ require ( github.com/speakeasy-api/openapi-generation/v2 v2.483.1 github.com/speakeasy-api/openapi-overlay v0.9.0 github.com/speakeasy-api/sdk-gen-config v1.29.1 - github.com/speakeasy-api/speakeasy-client-sdk-go/v3 v3.17.0 - github.com/speakeasy-api/speakeasy-core v0.17.5 + github.com/speakeasy-api/speakeasy-client-sdk-go/v3 v3.18.1 + github.com/speakeasy-api/speakeasy-core v0.17.6 github.com/speakeasy-api/speakeasy-proxy v0.0.2 github.com/spf13/cobra v1.8.1 github.com/spf13/pflag v1.0.5 diff --git a/go.sum b/go.sum index 7448275e..85474fdb 100644 --- a/go.sum +++ b/go.sum @@ -583,10 +583,10 @@ github.com/speakeasy-api/openapi-overlay v0.9.0 h1:Wrz6NO02cNlLzx1fB093lBlYxSI54 github.com/speakeasy-api/openapi-overlay v0.9.0/go.mod h1:f5FloQrHA7MsxYg9djzMD5h6dxrHjVVByWKh7an8TRc= github.com/speakeasy-api/sdk-gen-config v1.29.1 h1:oi//Zx9cIdL2KClrySYgNVU/ta4oYt8okies5bcQ+wI= github.com/speakeasy-api/sdk-gen-config v1.29.1/go.mod h1:e9PjnCRHGa4K4EFKVU+kKmihOZjJ2V4utcU+274+bnQ= -github.com/speakeasy-api/speakeasy-client-sdk-go/v3 v3.17.0 h1:Yk5pTcbpjbdUbGM9T+xfMu3n2L5Cq0hNav8TUj4mPcE= -github.com/speakeasy-api/speakeasy-client-sdk-go/v3 v3.17.0/go.mod h1:k9JD6Rj0+Iizc5COoLZHyRIOGGITpKZ2qBuFFO8SqNI= -github.com/speakeasy-api/speakeasy-core v0.17.5 h1:hce3XR3laPsGRJ+Nw8G1kvtm118tGI0JC3k3UlBLVjI= -github.com/speakeasy-api/speakeasy-core v0.17.5/go.mod h1:0U4gDvmCjWVzteXXPhdKcktzTwggyHBSU8EvBpgTA7I= +github.com/speakeasy-api/speakeasy-client-sdk-go/v3 v3.18.1 h1:6yMA7JQmBrkjsZbP9yEPCKq2xZfieHS47nKCI9DgWVo= +github.com/speakeasy-api/speakeasy-client-sdk-go/v3 v3.18.1/go.mod h1:k9JD6Rj0+Iizc5COoLZHyRIOGGITpKZ2qBuFFO8SqNI= +github.com/speakeasy-api/speakeasy-core v0.17.6 h1:+BglRNsWuwvdWkcuUCsa9k2UrqRXdbUAheZLvSJmLDE= +github.com/speakeasy-api/speakeasy-core v0.17.6/go.mod h1:iwQqMncf0XfZ6tWLL3F+L4BIdkIZMNzkPw9Zf9e02rE= github.com/speakeasy-api/speakeasy-go-sdk v1.8.1 h1:atzohw12oQ5ipaLb1q7ntTu4vvAgKDJsrvaUoOu6sw0= github.com/speakeasy-api/speakeasy-go-sdk v1.8.1/go.mod h1:XbzaM0sMjj8bGooz/uEtNkOh1FQiJK7RFuNG3LPBSAU= github.com/speakeasy-api/speakeasy-proxy v0.0.2 h1:u4rQ8lXvuYRCSxiLQGb5JxkZRwNIDlyh+pMFYD6OGjA=