Skip to content

Commit

Permalink
chore: add contract name (#1048)
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>
  • Loading branch information
migmartri committed Jun 27, 2024
1 parent b6fb604 commit f4cebf8
Show file tree
Hide file tree
Showing 10 changed files with 267 additions and 263 deletions.
4 changes: 2 additions & 2 deletions app/cli/cmd/workflow_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func WorkflowListTableOutput(workflows []*action.WorkflowItem) error {
}

headerRow := table.Row{"Name", "Project", "Public", "Runner", "Last Run status", "Created At"}
headerRowFull := table.Row{"Name", "Description", "Project", "Team", "Public", "Runner", "Last Run status", "Contract ID", "Created At"}
headerRowFull := table.Row{"Name", "Description", "Project", "Team", "Public", "Runner", "Last Run status", "Contract", "Created At"}

t := newTableWriter()
if full {
Expand All @@ -82,7 +82,7 @@ func WorkflowListTableOutput(workflows []*action.WorkflowItem) error {
row = table.Row{
p.Name, p.Description, p.Project, p.Team, p.Public,
lastRunRunner, lastRunState,
p.ContractID,
p.ContractName,
p.CreatedAt.Format(time.RFC822),
}
}
Expand Down
6 changes: 3 additions & 3 deletions app/cli/internal/action/workflow_list.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2023 The Chainloop Authors.
// Copyright 2024 The Chainloop Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -35,7 +35,7 @@ type WorkflowItem struct {
Project string `json:"project,omitempty"`
CreatedAt *time.Time `json:"createdAt"`
RunsCount int32 `json:"runsCount"`
ContractID string `json:"contractID,omitempty"`
ContractName string `json:"contractName,omitempty"`
ContractRevisionLatest int32 `json:"contractRevisionLatest,omitempty"`
LastRun *WorkflowRunItem `json:"lastRun,omitempty"`
// A public workflow means that any user can
Expand Down Expand Up @@ -71,7 +71,7 @@ func pbWorkflowItemToAction(wf *pb.WorkflowItem) *WorkflowItem {
res := &WorkflowItem{
Name: wf.Name, ID: wf.Id, CreatedAt: toTimePtr(wf.CreatedAt.AsTime()),
Project: wf.Project, Team: wf.Team, RunsCount: wf.RunsCount,
ContractID: wf.ContractId,
ContractName: wf.ContractName,
ContractRevisionLatest: wf.ContractRevisionLatest,
LastRun: pbWorkflowRunItemToAction(wf.LastRun),
Public: wf.Public,
Expand Down
490 changes: 245 additions & 245 deletions app/controlplane/api/controlplane/v1/response_messages.pb.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions app/controlplane/api/controlplane/v1/response_messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ message WorkflowItem {
int32 runs_count = 6;

WorkflowRunItem last_run = 7;
string contract_id = 8;
string contract_name = 8;
// Current, latest revision of the contract
int32 contract_revision_latest = 11;
// A public workflow means that any user can
Expand Down Expand Up @@ -196,4 +196,4 @@ enum UserWithNoMembershipError {
option (errors.default_code) = 500;
USER_WITH_NO_MEMBERSHIP_ERROR_UNSPECIFIED = 0;
USER_WITH_NO_MEMBERSHIP_ERROR_NOT_IN_ORG = 1 [(errors.code) = 403];
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/controlplane/internal/service/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func bizWorkflowToPb(wf *biz.Workflow) *pb.WorkflowItem {
}

if wf.ContractID != uuid.Nil {
item.ContractId = wf.ContractID.String()
item.ContractName = wf.ContractName
}

if wf.LastRun != nil {
Expand Down
2 changes: 1 addition & 1 deletion app/controlplane/internal/service/workflowcontract.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (s *WorkflowContractService) Describe(ctx context.Context, req *pb.Workflow
return nil, errors.NotFound("not found", "contract not found")
}

contractWithVersion, err := s.contractUseCase.Describe(ctx, currentOrg.ID, contract.Name, int(req.GetRevision()))
contractWithVersion, err := s.contractUseCase.Describe(ctx, currentOrg.ID, contract.ID.String(), int(req.GetRevision()))
if err != nil {
return nil, handleUseCaseErr(err, s.log)
} else if contractWithVersion == nil {
Expand Down
1 change: 1 addition & 0 deletions app/controlplane/pkg/biz/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Workflow struct {
RunsCounter int
LastRun *WorkflowRun
ID, ContractID, OrgID uuid.UUID
ContractName string
// Latest available contract revision
ContractRevisionLatest int
// Public means that the associated workflow runs, attestations and materials
Expand Down
4 changes: 3 additions & 1 deletion app/controlplane/pkg/biz/workflow_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ func (s *workflowIntegrationTestSuite) TestCreate() {
s.Equal(tc.opts.Description, got.Description)
s.Equal(tc.opts.Team, got.Team)
s.Equal(tc.opts.Project, got.Project)
s.NotEmpty(got.ContractID)
s.NotEmpty(got.ContractName)
})
}
}
Expand Down Expand Up @@ -293,7 +295,7 @@ func (s *workflowIntegrationTestSuite) TestUpdate() {
s.NoError(err)

if diff := cmp.Diff(tc.want, got,
cmpopts.IgnoreFields(biz.Workflow{}, "Name", "CreatedAt", "ID", "OrgID", "ContractID", "ContractRevisionLatest"),
cmpopts.IgnoreFields(biz.Workflow{}, "Name", "CreatedAt", "ID", "OrgID", "ContractName", "ContractID", "ContractRevisionLatest"),
); diff != "" {
s.Failf("mismatch (-want +got):\n%s", diff)
}
Expand Down
1 change: 1 addition & 0 deletions app/controlplane/pkg/data/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ func entWFToBizWF(w *ent.Workflow, r *ent.WorkflowRun) (*biz.Workflow, error) {

if contract := w.Edges.Contract; contract != nil {
wf.ContractID = contract.ID
wf.ContractName = contract.Name
lv, err := latestVersion(context.Background(), contract)
if err != nil {
return nil, fmt.Errorf("finding contract version: %w", err)
Expand Down

0 comments on commit f4cebf8

Please sign in to comment.