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
38 changes: 36 additions & 2 deletions app/cli/cmd/workflow_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

func newWorkflowCreateCmd() *cobra.Command {
var workflowName, project, team, contract string
var skipRACreate bool

cmd := &cobra.Command{
Use: "create",
Expand Down Expand Up @@ -59,12 +60,41 @@ func newWorkflowCreateCmd() *cobra.Command {
Name: workflowName, Team: team, Project: project, ContractID: contract,
}

res, err := action.NewWorkflowCreate(actionOpts).Run(opts)
workflow, err := action.NewWorkflowCreate(actionOpts).Run(opts)
if err != nil {
return err
}

return encodeOutput([]*action.WorkflowItem{res}, WorkflowListTableOutput)
workflowRA := &action.WorkflowItemWithRobotAccount{
WorkflowItem: workflow,
}

// If the robot account creation is not skipped via --skip-robot-account-create , create a new one
if !skipRACreate {
ra, errRA := action.NewWorkflowRobotAccountCreate(actionOpts).Run(workflow.ID, "autogenerated")
if errRA != nil {
return errRA
}
workflowRA.RobotAccountKey = ra.Key
workflowRA.RobotAccountID = ra.ID
}

// Print the workflow JSON
if flagOutputFormat == formatJSON {
return encodeJSON(workflowRA)
}

// Print the workflow table
if err := encodeOutput([]*action.WorkflowItem{workflowRA.WorkflowItem}, WorkflowListTableOutput); err != nil {
return err
}

// Print the Robot Account Token
if workflowRA.RobotAccountID != "" {
fmt.Printf("\nThis is automatically generated Robot Account Token (ID: %s). Save the following token since it will not printed again: \n\n %s\n\n", workflowRA.RobotAccountID, workflowRA.RobotAccountKey)
}

return nil
},
}

Expand All @@ -79,6 +109,10 @@ func newWorkflowCreateCmd() *cobra.Command {
cmd.Flags().StringVar(&team, "team", "", "team name")
cmd.Flags().StringVar(&contract, "contract", "", "the ID of an existing contract or the path/URL to a contract file. If not provided an empty one will be created.")

cmd.Flags().BoolVarP(&skipRACreate, "skip-robot-account-create", "s", false, "Skip creating a Robot Account for this workflow.")

cmd.Flags().SortFlags = false
Copy link
Member

Choose a reason for hiding this comment

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

I didn't know about this option. Why did you disable it?

Copy link
Member Author

Choose a reason for hiding this comment

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

because if you don't, this is sorted and some options are shown below skip-robot...


return cmd
}

Expand Down
6 changes: 6 additions & 0 deletions app/cli/internal/action/workflow_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ type WorkflowItem struct {
LastRun *WorkflowRunItem `json:"lastRun,omitempty"`
}

type WorkflowItemWithRobotAccount struct {
*WorkflowItem
RobotAccountID string `json:"robotAccountID,omitempty"`
RobotAccountKey string `json:"robotAccountKey,omitempty"`
}

func NewWorkflowList(cfg *ActionsOpts) *WorkflowList {
return &WorkflowList{cfg}
}
Expand Down