Skip to content
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

Add Deployment definition in SDK #5611

Merged
merged 3 commits into from
Feb 28, 2025
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
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
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should add comment to describe what this function does/use for (like we did in L582). The name newXXX is too confusing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@khanhtc1202
Thanks, added comment
9661323

// 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