From 4a645548f921a260e81b8a1b584bbccc5415ca92 Mon Sep 17 00:00:00 2001 From: Noah Fontes Date: Tue, 4 Apr 2023 12:08:17 -0700 Subject: [PATCH] Make configuration versions useful for workspaces This adds the current configuration version ID to the workspace model and also includes the current VCS revision information on a given configuration version. This makes the configuration version information useful for workspaces that are VCS-backed. --- configuration_version.go | 16 +++++++++++++--- workspace.go | 16 +++++++++------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/configuration_version.go b/configuration_version.go index fee4c3c..2f54cc5 100644 --- a/configuration_version.go +++ b/configuration_version.go @@ -29,7 +29,7 @@ type configurationVersions struct { // ConfigurationStatus represents a configuration version status. type ConfigurationStatus string -//List all available configuration version statuses. +// List all available configuration version statuses. const ( ConfigurationErrored ConfigurationStatus = "errored" ConfigurationPending ConfigurationStatus = "pending" @@ -43,7 +43,8 @@ type ConfigurationVersion struct { ID string `jsonapi:"primary,configuration-versions"` Status ConfigurationStatus `jsonapi:"attr,status"` // Relations - Workspace *Workspace `jsonapi:"relation,workspace"` + Workspace *Workspace `jsonapi:"relation,workspace"` + VcsRevision *VcsRevision `jsonapi:"relation,vcs-revision,omitempty"` } // ConfigurationVersionCreateOptions represents the options for creating a @@ -52,6 +53,10 @@ type ConfigurationVersionCreateOptions struct { // For internal use only! ID string `jsonapi:"primary,configuration-versions"` + // Indicates if a run should automatically be queued when the configuration + // has been uploaded. + AutoQueueRuns *bool `jsonapi:"attr,auto-queue-runs,omitempty"` + Workspace *Workspace `jsonapi:"relation,workspace"` } @@ -94,8 +99,13 @@ func (s *configurationVersions) Read(ctx context.Context, cvID string) (*Configu return nil, errors.New("invalid value for configuration version ID") } + options := struct { + Include string `url:"include"` + }{ + Include: "vcs-revision", + } u := fmt.Sprintf("configuration-versions/%s", url.QueryEscape(cvID)) - req, err := s.client.newRequest("GET", u, nil) + req, err := s.client.newRequest("GET", u, options) if err != nil { return nil, err } diff --git a/workspace.go b/workspace.go index 9387391..4cdc632 100644 --- a/workspace.go +++ b/workspace.go @@ -93,13 +93,15 @@ type Workspace struct { VarFiles []string `jsonapi:"attr,var-files"` // Relations - CurrentRun *Run `jsonapi:"relation,current-run"` - Environment *Environment `jsonapi:"relation,environment"` - CreatedBy *User `jsonapi:"relation,created-by"` - VcsProvider *VcsProvider `jsonapi:"relation,vcs-provider"` - AgentPool *AgentPool `jsonapi:"relation,agent-pool"` - ModuleVersion *ModuleVersion `jsonapi:"relation,module-version,omitempty"` - Tags []*Tag `jsonapi:"relation,tags"` + CurrentRun *Run `jsonapi:"relation,current-run"` + Environment *Environment `jsonapi:"relation,environment"` + CreatedBy *User `jsonapi:"relation,created-by"` + VcsProvider *VcsProvider `jsonapi:"relation,vcs-provider"` + AgentPool *AgentPool `jsonapi:"relation,agent-pool"` + ModuleVersion *ModuleVersion `jsonapi:"relation,module-version,omitempty"` + ConfigurationVersion *ConfigurationVersion `jsonapi:"relation,configuration-version,omitempty"` + LatestConfigurationVersion *ConfigurationVersion `jsonapi:"relation,latest-configuration-version,omitempty"` + Tags []*Tag `jsonapi:"relation,tags"` } // Hooks contains the custom hooks field.