Skip to content

Commit a37eb86

Browse files
authored
feat(workflow-contract): Add contract name to revision item (#1276)
Signed-off-by: Javier Rodriguez <[email protected]>
1 parent b9e20b8 commit a37eb86

File tree

6 files changed

+174
-134
lines changed

6 files changed

+174
-134
lines changed

app/controlplane/api/controlplane/v1/response_messages.pb.go

+138-126
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/api/controlplane/v1/response_messages.proto

+3
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ message WorkflowContractVersionItem {
135135

136136
RawBody raw_contract = 5;
137137

138+
// The name of the contract used for this run
139+
string contract_name = 6;
140+
138141
message RawBody {
139142
bytes body = 1;
140143
Format format = 2 [(buf.validate.field).enum = {

app/controlplane/api/gen/frontend/controlplane/v1/response_messages.ts

+16-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/internal/service/workflowrun.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,15 @@ func (s *WorkflowRunService) View(ctx context.Context, req *pb.WorkflowRunServic
136136
return nil, handleUseCaseErr(err, s.log)
137137
}
138138

139-
contractVersion, err := s.workflowContractUseCase.FindVersionByID(ctx, run.ContractVersionID.String())
139+
contractAndVersion, err := s.workflowContractUseCase.FindVersionByID(ctx, run.ContractVersionID.String())
140140
if err != nil {
141141
return nil, handleUseCaseErr(err, s.log)
142142
}
143143

144144
wr := bizWorkFlowRunToPb(run)
145145
wr.Workflow = bizWorkflowToPb(run.Workflow)
146-
wr.ContractVersion = bizWorkFlowContractVersionToPb(contractVersion)
146+
wr.ContractVersion = bizWorkFlowContractVersionToPb(contractAndVersion.Version)
147+
wr.ContractVersion.ContractName = contractAndVersion.Contract.Name
147148
res := &pb.WorkflowRunServiceViewResponse_Result{
148149
WorkflowRun: wr,
149150
Attestation: attestation,

app/controlplane/pkg/biz/workflowcontract.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ type WorkflowContractRepo interface {
8080
FindByIDInOrg(ctx context.Context, orgID, ID uuid.UUID) (*WorkflowContract, error)
8181
FindByNameInOrg(ctx context.Context, orgID uuid.UUID, name string) (*WorkflowContract, error)
8282
Describe(ctx context.Context, orgID, contractID uuid.UUID, revision int) (*WorkflowContractWithVersion, error)
83-
FindVersionByID(ctx context.Context, versionID uuid.UUID) (*WorkflowContractVersion, error)
83+
FindVersionByID(ctx context.Context, versionID uuid.UUID) (*WorkflowContractWithVersion, error)
8484
Update(ctx context.Context, orgID uuid.UUID, name string, opts *ContractUpdateOpts) (*WorkflowContractWithVersion, error)
8585
SoftDelete(ctx context.Context, contractID uuid.UUID) error
8686
}
@@ -248,7 +248,7 @@ func (uc *WorkflowContractUseCase) Describe(ctx context.Context, orgID, contract
248248
return uc.repo.Describe(ctx, orgUUID, contractUUID, revision)
249249
}
250250

251-
func (uc *WorkflowContractUseCase) FindVersionByID(ctx context.Context, versionID string) (*WorkflowContractVersion, error) {
251+
func (uc *WorkflowContractUseCase) FindVersionByID(ctx context.Context, versionID string) (*WorkflowContractWithVersion, error) {
252252
versionUUID, err := uuid.Parse(versionID)
253253
if err != nil {
254254
return nil, err

app/controlplane/pkg/data/workflowcontract.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,24 @@ func (r *WorkflowContractRepo) Create(ctx context.Context, opts *biz.ContractCre
107107
return res, nil
108108
}
109109

110-
func (r *WorkflowContractRepo) FindVersionByID(ctx context.Context, versionID uuid.UUID) (*biz.WorkflowContractVersion, error) {
111-
version, err := r.data.DB.WorkflowContractVersion.Get(ctx, versionID)
110+
func (r *WorkflowContractRepo) FindVersionByID(ctx context.Context, versionID uuid.UUID) (*biz.WorkflowContractWithVersion, error) {
111+
// .Get(ctx, versionID) is an alias to .Query().Where(workflowcontractversion.ID(versionID)).Only(ctx)
112+
version, err := r.data.DB.WorkflowContractVersion.Query().Where(workflowcontractversion.ID(versionID)).WithContract().Only(ctx)
112113
if err != nil && !ent.IsNotFound(err) {
113114
return nil, err
114115
} else if version == nil {
115116
return nil, nil
116117
}
117118

118-
return entContractVersionToBizContractVersion(version)
119+
contractVersion, err := entContractVersionToBizContractVersion(version)
120+
if err != nil {
121+
return nil, err
122+
}
123+
124+
return &biz.WorkflowContractWithVersion{
125+
Contract: entContractToBizContract(version.Edges.Contract, version, nil),
126+
Version: contractVersion,
127+
}, nil
119128
}
120129

121130
func (r *WorkflowContractRepo) Describe(ctx context.Context, orgID, contractID uuid.UUID, revision int) (*biz.WorkflowContractWithVersion, error) {

0 commit comments

Comments
 (0)