-
Notifications
You must be signed in to change notification settings - Fork 894
refactor: workspace builds #7541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
80e5eb9
refactor workspace builds
spikecurtis bd2811f
make gen
spikecurtis c892e43
Remove ParameterResolver from typescript
spikecurtis 25aec4f
rename conversion -> database/db2sdk
spikecurtis 6d69277
tests for db2sdk
spikecurtis 817c28e
Tests for ParameterResolver
spikecurtis cee21de
wsbuilder tests
spikecurtis 510a1b0
Move parameter validation tests to richparameters_test.go
spikecurtis acd1243
Fix CI generation; rename mock->dbmock
spikecurtis 5cb2d2a
Fix test imports
spikecurtis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Package conversion provides common conversion routines from database types to codersdk types | ||
package conversion | ||
spikecurtis marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package conversion | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/coder/coder/coderd/database" | ||
"github.com/coder/coder/coderd/parameter" | ||
"github.com/coder/coder/codersdk" | ||
"github.com/coder/coder/provisionersdk/proto" | ||
) | ||
|
||
func WorkspaceBuildParameters(params []database.WorkspaceBuildParameter) []codersdk.WorkspaceBuildParameter { | ||
out := make([]codersdk.WorkspaceBuildParameter, len(params)) | ||
for i, p := range params { | ||
out[i] = WorkspaceBuildParameter(p) | ||
} | ||
return out | ||
} | ||
|
||
func WorkspaceBuildParameter(p database.WorkspaceBuildParameter) codersdk.WorkspaceBuildParameter { | ||
return codersdk.WorkspaceBuildParameter{ | ||
Name: p.Name, | ||
Value: p.Value, | ||
} | ||
} | ||
|
||
func TemplateVersionParameter(param database.TemplateVersionParameter) (codersdk.TemplateVersionParameter, error) { | ||
var protoOptions []*proto.RichParameterOption | ||
err := json.Unmarshal(param.Options, &protoOptions) | ||
if err != nil { | ||
return codersdk.TemplateVersionParameter{}, err | ||
} | ||
options := make([]codersdk.TemplateVersionParameterOption, 0) | ||
for _, option := range protoOptions { | ||
options = append(options, codersdk.TemplateVersionParameterOption{ | ||
Name: option.Name, | ||
Description: option.Description, | ||
Value: option.Value, | ||
Icon: option.Icon, | ||
}) | ||
} | ||
|
||
descriptionPlaintext, err := parameter.Plaintext(param.Description) | ||
if err != nil { | ||
return codersdk.TemplateVersionParameter{}, err | ||
} | ||
return codersdk.TemplateVersionParameter{ | ||
Name: param.Name, | ||
DisplayName: param.DisplayName, | ||
Description: param.Description, | ||
DescriptionPlaintext: descriptionPlaintext, | ||
Type: param.Type, | ||
Mutable: param.Mutable, | ||
DefaultValue: param.DefaultValue, | ||
Icon: param.Icon, | ||
Options: options, | ||
ValidationRegex: param.ValidationRegex, | ||
ValidationMin: param.ValidationMin, | ||
ValidationMax: param.ValidationMax, | ||
ValidationError: param.ValidationError, | ||
ValidationMonotonic: codersdk.ValidationMonotonicOrder(param.ValidationMonotonic), | ||
Required: param.Required, | ||
LegacyVariableName: param.LegacyVariableName, | ||
}, nil | ||
} | ||
|
||
func Parameters(params []database.ParameterValue) []codersdk.Parameter { | ||
out := make([]codersdk.Parameter, len(params)) | ||
for i, p := range params { | ||
out[i] = Parameter(p) | ||
} | ||
return out | ||
} | ||
|
||
func Parameter(parameterValue database.ParameterValue) codersdk.Parameter { | ||
return codersdk.Parameter{ | ||
ID: parameterValue.ID, | ||
CreatedAt: parameterValue.CreatedAt, | ||
UpdatedAt: parameterValue.UpdatedAt, | ||
Scope: codersdk.ParameterScope(parameterValue.Scope), | ||
ScopeID: parameterValue.ScopeID, | ||
Name: parameterValue.Name, | ||
SourceScheme: codersdk.ParameterSourceScheme(parameterValue.SourceScheme), | ||
DestinationScheme: codersdk.ParameterDestinationScheme(parameterValue.DestinationScheme), | ||
SourceValue: parameterValue.SourceValue, | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package conversion | ||
spikecurtis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
import ( | ||
"time" | ||
|
||
"github.com/coder/coder/coderd/database" | ||
"github.com/coder/coder/codersdk" | ||
) | ||
|
||
func ProvisionerJobStatus(provisionerJob database.ProvisionerJob) codersdk.ProvisionerJobStatus { | ||
switch { | ||
case provisionerJob.CanceledAt.Valid: | ||
if !provisionerJob.CompletedAt.Valid { | ||
return codersdk.ProvisionerJobCanceling | ||
} | ||
if provisionerJob.Error.String == "" { | ||
return codersdk.ProvisionerJobCanceled | ||
} | ||
return codersdk.ProvisionerJobFailed | ||
case !provisionerJob.StartedAt.Valid: | ||
return codersdk.ProvisionerJobPending | ||
case provisionerJob.CompletedAt.Valid: | ||
if provisionerJob.Error.String == "" { | ||
return codersdk.ProvisionerJobSucceeded | ||
} | ||
return codersdk.ProvisionerJobFailed | ||
case database.Now().Sub(provisionerJob.UpdatedAt) > 30*time.Second: | ||
provisionerJob.Error.String = "Worker failed to update job in time." | ||
return codersdk.ProvisionerJobFailed | ||
default: | ||
return codersdk.ProvisionerJobRunning | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍