Skip to content

chore: Rename ProjectHistory to ProjectVersion #165

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 2 commits into from
Feb 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions coderd/coderd.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ func New(options *Options) http.Handler {
r.Get("/", api.parametersByProject)
r.Post("/", api.postParametersByProject)
})
r.Route("/history", func(r chi.Router) {
r.Get("/", api.projectHistoryByOrganization)
r.Post("/", api.postProjectHistoryByOrganization)
r.Route("/{projecthistory}", func(r chi.Router) {
r.Use(httpmw.ExtractProjectHistoryParam(api.Database))
r.Get("/", api.projectHistoryByOrganizationAndName)
r.Get("/parameters", api.projectHistoryParametersByOrganizationAndName)
r.Route("/versions", func(r chi.Router) {
r.Get("/", api.projectVersionsByOrganization)
r.Post("/", api.postProjectVersionByOrganization)
r.Route("/{projectversion}", func(r chi.Router) {
r.Use(httpmw.ExtractProjectVersionParam(api.Database))
r.Get("/", api.projectVersionByOrganizationAndName)
r.Get("/parameters", api.projectVersionParametersByOrganizationAndName)
})
})
})
Expand All @@ -91,7 +91,7 @@ func New(options *Options) http.Handler {
r.Route("/{workspace}", func(r chi.Router) {
r.Use(httpmw.ExtractWorkspaceParam(options.Database))
r.Get("/", api.workspaceByUser)
r.Route("/history", func(r chi.Router) {
r.Route("/version", func(r chi.Router) {
r.Post("/", api.postWorkspaceHistoryByUser)
r.Get("/", api.workspaceHistoryByUser)
r.Route("/{workspacehistory}", func(r chi.Router) {
Expand Down
52 changes: 26 additions & 26 deletions coderd/projectparameter/projectparameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
type Scope struct {
OrganizationID string
ProjectID uuid.UUID
ProjectHistoryID uuid.UUID
ProjectVersionID uuid.UUID
UserID string
WorkspaceID uuid.UUID
WorkspaceHistoryID uuid.UUID
Expand All @@ -40,21 +40,21 @@ func Compute(ctx context.Context, db database.Store, scope Scope) ([]Value, erro
compute := &compute{
db: db,
computedParameterByName: map[string]Value{},
projectHistoryParametersByName: map[string]database.ProjectParameter{},
projectVersionParametersByName: map[string]database.ProjectParameter{},
}

// All parameters for the project version!
projectHistoryParameters, err := db.GetProjectParametersByHistoryID(ctx, scope.ProjectHistoryID)
projectVersionParameters, err := db.GetProjectParametersByVersionID(ctx, scope.ProjectVersionID)
if errors.Is(err, sql.ErrNoRows) {
// This occurs when the project history has defined
// This occurs when the project version has defined
// no parameters, so we have nothing to compute!
return []Value{}, nil
}
if err != nil {
return nil, xerrors.Errorf("get project parameters: %w", err)
}
for _, projectHistoryParameter := range projectHistoryParameters {
compute.projectHistoryParametersByName[projectHistoryParameter.Name] = projectHistoryParameter
for _, projectVersionParameter := range projectVersionParameters {
compute.projectVersionParametersByName[projectVersionParameter.Name] = projectVersionParameter
}

// Organization parameters come first!
Expand All @@ -67,33 +67,33 @@ func Compute(ctx context.Context, db database.Store, scope Scope) ([]Value, erro
}

// Default project parameter values come second!
for _, projectHistoryParameter := range projectHistoryParameters {
if !projectHistoryParameter.DefaultSourceValue.Valid {
for _, projectVersionParameter := range projectVersionParameters {
if !projectVersionParameter.DefaultSourceValue.Valid {
continue
}
if !projectHistoryParameter.DefaultDestinationValue.Valid {
if !projectVersionParameter.DefaultDestinationValue.Valid {
continue
}

destinationScheme, err := convertDestinationScheme(projectHistoryParameter.DefaultDestinationScheme)
destinationScheme, err := convertDestinationScheme(projectVersionParameter.DefaultDestinationScheme)
if err != nil {
return nil, xerrors.Errorf("convert default destination scheme for project history parameter %q: %w", projectHistoryParameter.Name, err)
return nil, xerrors.Errorf("convert default destination scheme for project version parameter %q: %w", projectVersionParameter.Name, err)
}

switch projectHistoryParameter.DefaultSourceScheme {
switch projectVersionParameter.DefaultSourceScheme {
case database.ParameterSourceSchemeData:
compute.computedParameterByName[projectHistoryParameter.Name] = Value{
compute.computedParameterByName[projectVersionParameter.Name] = Value{
Proto: &proto.ParameterValue{
DestinationScheme: destinationScheme,
Name: projectHistoryParameter.DefaultDestinationValue.String,
Value: projectHistoryParameter.DefaultSourceValue.String,
Name: projectVersionParameter.DefaultDestinationValue.String,
Value: projectVersionParameter.DefaultSourceValue.String,
},
DefaultValue: true,
Scope: database.ParameterScopeProject,
ScopeID: scope.ProjectID.String(),
}
default:
return nil, xerrors.Errorf("unsupported source scheme for project history parameter %q: %q", projectHistoryParameter.Name, string(projectHistoryParameter.DefaultSourceScheme))
return nil, xerrors.Errorf("unsupported source scheme for project version parameter %q: %q", projectVersionParameter.Name, string(projectVersionParameter.DefaultSourceScheme))
}
}

Expand Down Expand Up @@ -124,13 +124,13 @@ func Compute(ctx context.Context, db database.Store, scope Scope) ([]Value, erro
return nil, err
}

for _, projectHistoryParameter := range compute.projectHistoryParametersByName {
if _, ok := compute.computedParameterByName[projectHistoryParameter.Name]; ok {
for _, projectVersionParameter := range compute.projectVersionParametersByName {
if _, ok := compute.computedParameterByName[projectVersionParameter.Name]; ok {
continue
}
return nil, NoValueError{
ParameterID: projectHistoryParameter.ID,
ParameterName: projectHistoryParameter.Name,
ParameterID: projectVersionParameter.ID,
ParameterName: projectVersionParameter.Name,
}
}

Expand All @@ -144,7 +144,7 @@ func Compute(ctx context.Context, db database.Store, scope Scope) ([]Value, erro
type compute struct {
db database.Store
computedParameterByName map[string]Value
projectHistoryParametersByName map[string]database.ProjectParameter
projectVersionParametersByName map[string]database.ProjectParameter
}

// Validates and computes the value for parameters; setting the value on "parameterByName".
Expand All @@ -158,8 +158,8 @@ func (c *compute) inject(ctx context.Context, scopeParams database.GetParameterV
}

for _, scopedParameter := range scopedParameters {
projectHistoryParameter, hasProjectHistoryParameter := c.projectHistoryParametersByName[scopedParameter.Name]
if !hasProjectHistoryParameter {
projectVersionParameter, hasProjectVersionParameter := c.projectVersionParametersByName[scopedParameter.Name]
if !hasProjectVersionParameter {
// Don't inject parameters that aren't defined by the project.
continue
}
Expand All @@ -169,7 +169,7 @@ func (c *compute) inject(ctx context.Context, scopeParams database.GetParameterV
// If a parameter already exists, check if this variable can override it.
// Injection hierarchy is the responsibility of the caller. This check ensures
// project parameters cannot be overridden if already set.
if !projectHistoryParameter.AllowOverrideSource && scopedParameter.Scope != database.ParameterScopeProject {
if !projectVersionParameter.AllowOverrideSource && scopedParameter.Scope != database.ParameterScopeProject {
continue
}
}
Expand All @@ -181,15 +181,15 @@ func (c *compute) inject(ctx context.Context, scopeParams database.GetParameterV

switch scopedParameter.SourceScheme {
case database.ParameterSourceSchemeData:
c.computedParameterByName[projectHistoryParameter.Name] = Value{
c.computedParameterByName[projectVersionParameter.Name] = Value{
Proto: &proto.ParameterValue{
DestinationScheme: destinationScheme,
Name: scopedParameter.SourceValue,
Value: scopedParameter.DestinationValue,
},
}
default:
return xerrors.Errorf("unsupported source scheme: %q", string(projectHistoryParameter.DefaultSourceScheme))
return xerrors.Errorf("unsupported source scheme: %q", string(projectVersionParameter.DefaultSourceScheme))
}
}
return nil
Expand Down
18 changes: 9 additions & 9 deletions coderd/projectparameter/projectparameter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ func TestCompute(t *testing.T) {
return projectparameter.Scope{
OrganizationID: uuid.New().String(),
ProjectID: uuid.New(),
ProjectHistoryID: uuid.New(),
ProjectVersionID: uuid.New(),
UserID: uuid.NewString(),
}
}
type projectParameterOptions struct {
AllowOverrideSource bool
AllowOverrideDestination bool
DefaultDestinationScheme database.ParameterDestinationScheme
ProjectHistoryID uuid.UUID
ProjectVersionID uuid.UUID
}
generateProjectParameter := func(t *testing.T, db database.Store, opts projectParameterOptions) database.ProjectParameter {
if opts.DefaultDestinationScheme == "" {
Expand All @@ -44,7 +44,7 @@ func TestCompute(t *testing.T) {
param, err := db.InsertProjectParameter(context.Background(), database.InsertProjectParameterParams{
ID: uuid.New(),
Name: name,
ProjectHistoryID: opts.ProjectHistoryID,
ProjectVersionID: opts.ProjectVersionID,
DefaultSourceScheme: database.ParameterSourceSchemeData,
DefaultSourceValue: sql.NullString{
String: sourceValue,
Expand All @@ -68,7 +68,7 @@ func TestCompute(t *testing.T) {
scope := generateScope()
parameter, err := db.InsertProjectParameter(context.Background(), database.InsertProjectParameterParams{
ID: uuid.New(),
ProjectHistoryID: scope.ProjectHistoryID,
ProjectVersionID: scope.ProjectVersionID,
Name: "hey",
})
require.NoError(t, err)
Expand All @@ -85,7 +85,7 @@ func TestCompute(t *testing.T) {
db := databasefake.New()
scope := generateScope()
parameter := generateProjectParameter(t, db, projectParameterOptions{
ProjectHistoryID: scope.ProjectHistoryID,
ProjectVersionID: scope.ProjectVersionID,
DefaultDestinationScheme: database.ParameterDestinationSchemeProvisionerVariable,
})
values, err := projectparameter.Compute(context.Background(), db, scope)
Expand All @@ -105,7 +105,7 @@ func TestCompute(t *testing.T) {
db := databasefake.New()
scope := generateScope()
parameter := generateProjectParameter(t, db, projectParameterOptions{
ProjectHistoryID: scope.ProjectHistoryID,
ProjectVersionID: scope.ProjectVersionID,
})
_, err := db.InsertParameterValue(context.Background(), database.InsertParameterValueParams{
ID: uuid.New(),
Expand All @@ -131,7 +131,7 @@ func TestCompute(t *testing.T) {
db := databasefake.New()
scope := generateScope()
parameter := generateProjectParameter(t, db, projectParameterOptions{
ProjectHistoryID: scope.ProjectHistoryID,
ProjectVersionID: scope.ProjectVersionID,
})
value, err := db.InsertParameterValue(context.Background(), database.InsertParameterValueParams{
ID: uuid.New(),
Expand All @@ -157,7 +157,7 @@ func TestCompute(t *testing.T) {
db := databasefake.New()
scope := generateScope()
parameter := generateProjectParameter(t, db, projectParameterOptions{
ProjectHistoryID: scope.ProjectHistoryID,
ProjectVersionID: scope.ProjectVersionID,
})
_, err := db.InsertParameterValue(context.Background(), database.InsertParameterValueParams{
ID: uuid.New(),
Expand All @@ -183,7 +183,7 @@ func TestCompute(t *testing.T) {
scope := generateScope()
parameter := generateProjectParameter(t, db, projectParameterOptions{
AllowOverrideSource: true,
ProjectHistoryID: scope.ProjectHistoryID,
ProjectVersionID: scope.ProjectVersionID,
})
_, err := db.InsertParameterValue(context.Background(), database.InsertParameterValueParams{
ID: uuid.New(),
Expand Down
8 changes: 4 additions & 4 deletions coderd/projects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,17 @@ func TestProjects(t *testing.T) {
},
}}, nil)
require.NoError(t, err)
history, err := server.Client.CreateProjectHistory(context.Background(), user.Organization, project.Name, coderd.CreateProjectHistoryRequest{
version, err := server.Client.CreateProjectVersion(context.Background(), user.Organization, project.Name, coderd.CreateProjectVersionRequest{
StorageMethod: database.ProjectStorageMethodInlineArchive,
StorageSource: data,
})
require.NoError(t, err)
require.Eventually(t, func() bool {
projectHistory, err := server.Client.ProjectHistory(context.Background(), user.Organization, project.Name, history.Name)
projectVersion, err := server.Client.ProjectVersion(context.Background(), user.Organization, project.Name, version.Name)
require.NoError(t, err)
return projectHistory.Import.Status.Completed()
return projectVersion.Import.Status.Completed()
}, 15*time.Second, 10*time.Millisecond)
params, err := server.Client.ProjectHistoryParameters(context.Background(), user.Organization, project.Name, history.Name)
params, err := server.Client.ProjectVersionParameters(context.Background(), user.Organization, project.Name, version.Name)
require.NoError(t, err)
require.Len(t, params, 1)
require.Equal(t, "example", params[0].Name)
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy