Skip to content

Commit

Permalink
Add Deployment definition in SDK (#5611)
Browse files Browse the repository at this point in the history
* Add Deployment definition to SDK

Signed-off-by: Yoshiki Fujikane <[email protected]>

* Fix for failed test

Signed-off-by: Yoshiki Fujikane <[email protected]>

* Add comment

Signed-off-by: Yoshiki Fujikane <[email protected]>

---------

Signed-off-by: Yoshiki Fujikane <[email protected]>
  • Loading branch information
ffjlabo authored Feb 28, 2025
1 parent 42a9fd7 commit 93e9a27
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
35 changes: 35 additions & 0 deletions pkg/plugin/sdk/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ func executeStage[Config, DeployTargetConfig any](
StageConfig: request.GetInput().GetStageConfig(),
RunningDeploymentSource: newDeploymentSource(request.GetInput().GetRunningDeploymentSource()),
TargetDeploymentSource: newDeploymentSource(request.GetInput().GetTargetDeploymentSource()),
Deployment: newDeployment(request.GetInput().GetDeployment()),
},
Client: client,
Logger: logger,
Expand Down Expand Up @@ -560,6 +561,9 @@ type ExecuteStageRequest struct {

// TargetDeploymentSource is the source of the target deployment.
TargetDeploymentSource DeploymentSource

// The deployment that the stage is running.
Deployment Deployment
}

// DeploymentSource represents the source of the deployment.
Expand All @@ -585,6 +589,37 @@ func newDeploymentSource(source *common.DeploymentSource) DeploymentSource {
}
}

// Deployment represents the deployment that the stage is running. This is read-only.
type Deployment struct {
// ID is the unique identifier of the deployment.
ID string
// ApplicationID is the unique identifier of the application.
ApplicationID string
// ApplicationName is the name of the application.
ApplicationName string
// PipedID is the unique identifier of the piped that is running the deployment.
PipedID string
// ProjectID is the unique identifier of the project that the application belongs to.
ProjectID string
// TriggeredBy is the name of the entity that triggered the deployment.
TriggeredBy string
// CreatedAt is the time when the deployment was created.
CreatedAt int64
}

// newDeployment converts the model.Deployment to the internal representation.
func newDeployment(deployment *model.Deployment) Deployment {
return Deployment{
ID: deployment.GetId(),
ApplicationID: deployment.GetApplicationId(),
ApplicationName: deployment.GetApplicationName(),
PipedID: deployment.GetPipedId(),
ProjectID: deployment.GetProjectId(),
TriggeredBy: deployment.TriggeredBy(),
CreatedAt: deployment.GetCreatedAt(),
}
}

// ExecuteStageResponse is the response of the request to execute a stage.
type ExecuteStageResponse struct {
Status StageStatus
Expand Down
5 changes: 5 additions & 0 deletions pkg/plugin/sdk/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ func TestStagePluginServiceServer_ExecuteStage(t *testing.T) {
Stage: &model.PipelineStage{
Name: tt.stage,
},
Deployment: &model.Deployment{
Trigger: &model.DeploymentTrigger{
Commit: &model.Commit{},
},
},
},
}

Expand Down

0 comments on commit 93e9a27

Please sign in to comment.