Skip to content

Commit

Permalink
Merge pull request #430 from Qovery/clean
Browse files Browse the repository at this point in the history
chore: Remove un-used function
  • Loading branch information
erebe authored Oct 21, 2024
2 parents db6afff + 1e315fa commit 1403feb
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 48 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.29.0
github.com/pkg/errors v0.9.1
github.com/qovery/qovery-client-go v0.0.0-20241007135818-bf9e7b0f2948
github.com/qovery/qovery-client-go v0.0.0-20241017091135-bcf628682c95
github.com/schollz/progressbar/v3 v3.13.0
github.com/sethvargo/go-envconfig v0.9.0
github.com/stretchr/testify v1.9.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,8 @@ github.com/qovery/qovery-client-go v0.0.0-20241004154827-4981e1991178 h1:FbsMQXG
github.com/qovery/qovery-client-go v0.0.0-20241004154827-4981e1991178/go.mod h1:9eHj5a4EtXGIyfbvVL3HVYW9k7Xmiwi00OqHrP4dc10=
github.com/qovery/qovery-client-go v0.0.0-20241007135818-bf9e7b0f2948 h1:53/bYmTzbGYxHsZRWrcZIDszTJHOd/0i0B7PWlHhWeg=
github.com/qovery/qovery-client-go v0.0.0-20241007135818-bf9e7b0f2948/go.mod h1:9eHj5a4EtXGIyfbvVL3HVYW9k7Xmiwi00OqHrP4dc10=
github.com/qovery/qovery-client-go v0.0.0-20241017091135-bcf628682c95 h1:yxpOzpRmdAuyhesNA+eKsMoGKvkJNvbS3ea21WxPJGA=
github.com/qovery/qovery-client-go v0.0.0-20241017091135-bcf628682c95/go.mod h1:9eHj5a4EtXGIyfbvVL3HVYW9k7Xmiwi00OqHrP4dc10=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.3 h1:utMvzDsuh3suAEnhH0RdHmoPbU648o6CvXxTx4SBMOw=
github.com/rivo/uniseg v0.4.3/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
Expand Down
2 changes: 0 additions & 2 deletions internal/domain/newdeployment/newdeployment_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ type EnvironmentRepository interface {
Stop(ctx context.Context, newDeployment Deployment) (*Deployment, error)
Restart(ctx context.Context, newDeployment Deployment) (*Deployment, error)
Delete(ctx context.Context, newDeployment Deployment) (*Deployment, error)
GetLastDeploymentId(ctx context.Context, environmentID uuid.UUID) (*string, error)
GetNextDeploymentId(ctx context.Context, environmentID uuid.UUID) (*string, error)
}

type DeploymentStatusRepository interface {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func newDomainEnvSecretFromQovery(v *qovery.VariableResponse) (*secret.Secret, e
func newQoveryEnvSecretEditRequestFromDomain(request secret.UpsertRequest) qovery.VariableEditRequest {
return qovery.VariableEditRequest{
Key: request.Key,
Value: request.Value,
Value: *qovery.NewNullableString(&request.Value),
Description: *qovery.NewNullableString(&request.Description),
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func newDomainEnvVariableFromQovery(v *qovery.VariableResponse) (*variable.Varia
func newQoveryEnvVariableEditRequestFromDomain(request variable.UpsertRequest) qovery.VariableEditRequest {
return qovery.VariableEditRequest{
Key: request.Key,
Value: request.Value,
Value: *qovery.NewNullableString(&request.Value),
Description: *qovery.NewNullableString(&request.Description),
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@ package qoveryapi

import (
"context"
"fmt"
"regexp"
"strconv"

"github.com/google/uuid"
"github.com/pkg/errors"
"github.com/qovery/qovery-client-go"

"github.com/qovery/terraform-provider-qovery/internal/domain/apierrors"
"github.com/qovery/terraform-provider-qovery/internal/domain/newdeployment"
)
Expand Down Expand Up @@ -67,40 +61,3 @@ func (c newNewDeploymentQoveryAPI) Delete(ctx context.Context, newDeployment new

return &newDeployment, nil
}

func (c newNewDeploymentQoveryAPI) GetLastDeploymentId(ctx context.Context, environmentID uuid.UUID) (*string, error) {
history, resp, err := c.client.EnvironmentDeploymentHistoryAPI.ListEnvironmentDeploymentHistory(ctx, environmentID.String()).Execute()
if err != nil || resp.StatusCode >= 400 {
return nil, apierrors.NewCreateAPIError(apierrors.APIResourceDeployment, environmentID.String(), resp, err)
}

deploymentHistory := history.GetResults()
if len(deploymentHistory) == 0 {
deploymentID := fmt.Sprintf("%s-0", environmentID)
return &deploymentID, nil
}

lastDeployment := deploymentHistory[len(deploymentHistory)-1]
ID := lastDeployment.Id
return &ID, nil
}

func (c newNewDeploymentQoveryAPI) GetNextDeploymentId(ctx context.Context, environmentID uuid.UUID) (*string, error) {
lastDeploymentID, err := c.GetLastDeploymentId(ctx, environmentID)
if err != nil {
return nil, err
}
re := regexp.MustCompile(`-(\d+)$`)
result := re.FindStringSubmatch(*lastDeploymentID)
if len(result) == 2 {
version, err := strconv.Atoi(result[1])
if err != nil {
return nil, err
}
// Simulate next deployment id: ${environment_id}-${version}
newVersion := fmt.Sprintf("%s-%d", environmentID.String(), version+1)
return &newVersion, nil
}

return nil, errors.New(fmt.Sprintf("Cannot compute next deployment id for environment id %s", environmentID))
}

0 comments on commit 1403feb

Please sign in to comment.