Skip to content
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
7 changes: 4 additions & 3 deletions app/cli/cmd/workflow_contract_create.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2024 The Chainloop Authors.
// Copyright 2024-2025 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 All @@ -21,7 +21,7 @@ import (
)

func newWorkflowContractCreateCmd() *cobra.Command {
var name, description, contractPath string
var name, description, contractPath, projectName string

cmd := &cobra.Command{
Use: "create",
Expand All @@ -31,7 +31,7 @@ func newWorkflowContractCreateCmd() *cobra.Command {
if cmd.Flags().Changed("description") {
desc = &description
}
res, err := action.NewWorkflowContractCreate(actionOpts).Run(name, desc, contractPath)
res, err := action.NewWorkflowContractCreate(actionOpts).Run(name, desc, contractPath, projectName)
if err != nil {
return err
}
Expand All @@ -47,6 +47,7 @@ func newWorkflowContractCreateCmd() *cobra.Command {

cmd.Flags().StringVarP(&contractPath, "contract", "f", "", "path or URL to the contract schema")
cmd.Flags().StringVar(&description, "description", "", "description of the contract")
cmd.Flags().StringVar(&projectName, "project", "", "project name used to scope the contract, if not set the contract will be created in the organization")

return cmd
}
10 changes: 8 additions & 2 deletions app/cli/cmd/workflow_contract_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package cmd

import (
"fmt"
"time"

"github.com/chainloop-dev/chainloop/app/cli/internal/action"
Expand Down Expand Up @@ -48,9 +49,14 @@ func contractItemTableOutput(contract *action.WorkflowContractItem) error {
func contractListTableOutput(contracts []*action.WorkflowContractItem) error {
t := newTableWriter()

t.AppendHeader(table.Row{"Name", "Latest Revision", "Created At", "Updated At", "# Workflows"})
t.AppendHeader(table.Row{"Name", "Latest Revision", "Created At", "Updated At", "# Workflows", "Scope"})
for _, p := range contracts {
t.AppendRow(table.Row{p.Name, p.LatestRevision, p.CreatedAt.Format(time.RFC822), p.LatestRevisionCreatedAt.Format(time.RFC822), len(p.WorkflowRefs)})
scope := "org"
if p.ScopedEntity != nil {
scope = fmt.Sprintf("%s/%s", p.ScopedEntity.Type, p.ScopedEntity.Name)
}

t.AppendRow(table.Row{p.Name, p.LatestRevision, p.CreatedAt.Format(time.RFC822), p.LatestRevisionCreatedAt.Format(time.RFC822), len(p.WorkflowRefs), scope})
}

t.Render()
Expand Down
1 change: 1 addition & 0 deletions app/cli/documentation/cli-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2965,6 +2965,7 @@ Options
--description string description of the contract
-h, --help help for create
--name string contract name
--project string project name used to scope the contract, if not set the contract will be created in the organization
```

Options inherited from parent commands
Expand Down
8 changes: 7 additions & 1 deletion app/cli/internal/action/workflow_contract_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,19 @@ func NewWorkflowContractCreate(cfg *ActionsOpts) *WorkflowContractCreate {
return &WorkflowContractCreate{cfg}
}

func (action *WorkflowContractCreate) Run(name string, description *string, contractPath string) (*WorkflowContractItem, error) {
func (action *WorkflowContractCreate) Run(name string, description *string, contractPath string, projectName string) (*WorkflowContractItem, error) {
client := pb.NewWorkflowContractServiceClient(action.cfg.CPConnection)

request := &pb.WorkflowContractServiceCreateRequest{
Name: name, Description: description,
}

if projectName != "" {
request.ProjectReference = &pb.IdentityReference{
Name: &projectName,
}
}

if contractPath != "" {
rawContract, err := LoadFileOrURL(contractPath)
if err != nil {
Expand Down
19 changes: 18 additions & 1 deletion app/cli/internal/action/workflow_contract_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ type WorkflowContractItem struct {
CreatedAt *time.Time `json:"createdAt"`
Workflows []string `json:"workflows,omitempty"` // TODO: remove this field after all clients are updated
WorkflowRefs []*WorkflowRef `json:"workflowRefs,omitempty"`
ScopedEntity *ScopedEntity `json:"scopedEntity,omitempty"`
}

type ScopedEntity struct {
Type string `json:"type"`
ID string `json:"id"`
Name string `json:"name"`
}

type WorkflowRef struct {
Expand Down Expand Up @@ -82,7 +89,7 @@ func pbWorkflowContractItemToAction(in *pb.WorkflowContractItem) *WorkflowContra
for _, w := range in.WorkflowRefs {
workflowRefs = append(workflowRefs, pbWorkflowRefToAction(w))
}
return &WorkflowContractItem{
item := &WorkflowContractItem{
Name: in.GetName(),
ID: in.GetId(),
LatestRevision: int(in.GetLatestRevision()),
Expand All @@ -92,6 +99,16 @@ func pbWorkflowContractItemToAction(in *pb.WorkflowContractItem) *WorkflowContra
Description: in.GetDescription(),
LatestRevisionCreatedAt: toTimePtr(in.GetLatestRevisionCreatedAt().AsTime()),
}

if in.ScopedEntity != nil {
item.ScopedEntity = &ScopedEntity{
Type: in.ScopedEntity.Type,
ID: in.ScopedEntity.Id,
Name: in.ScopedEntity.Name,
}
}

return item
}

func pbWorkflowContractVersionItemToAction(in *pb.WorkflowContractVersionItem) *WorkflowContractVersionItem {
Expand Down
Loading
Loading