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

New JFrog Pipelines commands #1766

Merged
merged 25 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5ef67e7
Added pipelines run status and trigger run
bhanurp Nov 23, 2022
aea58a8
Moved pipelines commands to jfrog-cli-core
bhanurp Nov 24, 2022
2d21db6
Updated with multi branch details
bhanurp Dec 14, 2022
7271a60
Updated command pipelines short hand
bhanurp Dec 20, 2022
52a6ce1
Updated command pipelines short hand
bhanurp Dec 20, 2022
0a4f69c
Fixed possible review comments
bhanurp Dec 22, 2022
2abcb6d
Updated pipelines command
bhanurp Jan 1, 2023
9ddec8a
Updated cli core revision
bhanurp Jan 1, 2023
36c12ff
Merge branch 'dev' into v2
bhanurp Jan 2, 2023
7ed4c6b
Correct dependency conflict
bhanurp Jan 2, 2023
3e407b4
Updated logs and comments starting letter to upper case
bhanurp Jan 4, 2023
eb3168c
Updated pipelines command to pl
bhanurp Jan 4, 2023
b7af659
Updated with camel case
bhanurp Jan 4, 2023
6e1de6e
Removed notification feature
bhanurp Jan 5, 2023
72c4228
Updated pielines cli with docs
bhanurp Jan 13, 2023
37d2cc5
Updated to use commands exec
bhanurp Jan 14, 2023
2dc02ef
Updated comments to start with capital letter
bhanurp Jan 14, 2023
237b8cb
Added pipeline commands
bhanurp Jan 17, 2023
7e5d9d1
Updated pipelines commands arguments help doc
bhanurp Jan 17, 2023
2f5de1a
Updated pipelines commands arguments help doc
bhanurp Jan 17, 2023
31a0d2a
Opted to use err for error variable for possible redeclaration
bhanurp Jan 19, 2023
9cdf65e
Merge branch 'dev' into v2
bhanurp Jan 24, 2023
b7f2751
Relative changes to cli-core
bhanurp Jan 24, 2023
d8324ad
Refactored pipeline commands to cli
bhanurp Jan 26, 2023
31851a2
Changed sync status command to sync-status
bhanurp Jan 26, 2023
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
2 changes: 1 addition & 1 deletion docs/pipelines/status/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package status
var Usage = []string{"pl status"}

func GetDescription() string {
return "Fetch latest pipeline run status."
return "Fetch the latest pipeline run status."
}
2 changes: 1 addition & 1 deletion docs/pipelines/sync/help.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package sync

var Usage = []string{"pl sync <repository name>"}
var Usage = []string{"pl sync"}

func GetDescription() string {
return "Sync a pipeline resource."
Expand Down
2 changes: 1 addition & 1 deletion docs/pipelines/syncstatus/help.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package syncstatus

var Usage = []string{"pl syncstatus"}
var Usage = []string{"pl sync status"}
eyalbe4 marked this conversation as resolved.
Show resolved Hide resolved

func GetDescription() string {
return "Fetch pipeline resource sync status."
Expand Down
4 changes: 2 additions & 2 deletions docs/pipelines/trigger/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ func GetDescription() string {

func GetArguments() string {
return ` pipeline name
Pipeline name to trigger manual run.
Pipeline name to trigger the manual run on.
branch name
Branch name to trigger manual run.`
Branch name to trigger the manual run on.`
}
2 changes: 1 addition & 1 deletion docs/pipelines/version/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package version
var Usage = []string{"pl version"}

func GetDescription() string {
return "Get pipelines version."
return "Show the version of JFrog Pipelines."
}
126 changes: 124 additions & 2 deletions pipelines/cli.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
package pipelines

import (
"fmt"
"github.com/jfrog/jfrog-cli-core/v2/common/commands"
corecommon "github.com/jfrog/jfrog-cli-core/v2/docs/common"
pipelines "github.com/jfrog/jfrog-cli-core/v2/pipelines/commands"
coreConfig "github.com/jfrog/jfrog-cli-core/v2/utils/config"
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
"github.com/jfrog/jfrog-cli/docs/common"
"github.com/jfrog/jfrog-cli/docs/pipelines/status"
"github.com/jfrog/jfrog-cli/docs/pipelines/sync"
"github.com/jfrog/jfrog-cli/docs/pipelines/syncstatus"
"github.com/jfrog/jfrog-cli/docs/pipelines/trigger"
"github.com/jfrog/jfrog-cli/docs/pipelines/version"

"github.com/jfrog/jfrog-cli/utils/cliutils"
clientlog "github.com/jfrog/jfrog-client-go/utils/log"
"github.com/urfave/cli"
)

Expand Down Expand Up @@ -64,11 +71,11 @@ func GetCommands() []cli.Command {
},
},
{
Name: "syncstatus",
Name: "sync-status",
Flags: cliutils.GetCommandFlags(cliutils.SyncStatus),
Aliases: []string{"ss"},
Usage: syncstatus.GetDescription(),
HelpName: corecommon.CreateUsage("pl syncstatus", syncstatus.GetDescription(), syncstatus.Usage),
HelpName: corecommon.CreateUsage("pl sync-status", syncstatus.GetDescription(), syncstatus.Usage),
ArgsUsage: common.CreateEnvVars(),
BashComplete: corecommon.CreateBashCompletionFunc(),
Action: func(c *cli.Context) error {
Expand All @@ -77,3 +84,118 @@ func GetCommands() []cli.Command {
},
})
}
bhanurp marked this conversation as resolved.
Show resolved Hide resolved

// getMultiBranch parses singleBranch flag and computes whether multiBranch is set to true/false
func getMultiBranch(c *cli.Context) bool {
return !c.Bool("single-branch")
}

// createPipelinesDetailsByFlags creates pipelines configuration details
func createPipelinesDetailsByFlags(c *cli.Context) (*coreConfig.ServerDetails, error) {
plDetails, err := cliutils.CreateServerDetailsWithConfigOffer(c, true, cliutils.CmdPipelines)
if err != nil {
return nil, err
}
if plDetails.DistributionUrl == "" {
return nil, fmt.Errorf("the --pipelines-url option is mandatory")
}
return plDetails, nil
}

// fetchLatestPipelineRunStatus fetches pipeline run status and filters from pipeline-name and branch flags
func fetchLatestPipelineRunStatus(c *cli.Context) error {
clientlog.Info(coreutils.PrintTitle("Fetching pipeline run status"))

// Read flags for status command
pipName := c.String("pipeline-name")
notify := c.Bool("monitor")
branch := c.String("branch")
multiBranch := getMultiBranch(c)
serviceDetails, err := createPipelinesDetailsByFlags(c)
if err != nil {
return err
}
statusCommand := pipelines.NewStatusCommand()
statusCommand.SetBranch(branch).
SetPipeline(pipName).
SetNotify(notify).
SetMultiBranch(multiBranch)

// Set server details
statusCommand.SetServerDetails(serviceDetails)
return commands.Exec(statusCommand)
}

// syncPipelineResources sync pipelines resource
func syncPipelineResources(c *cli.Context) error {
// Get arguments repository name and branch name
repository := c.Args().Get(0)
branch := c.Args().Get(1)
clientlog.Info("Triggering pipeline sync on repository:", repository, "branch:", branch)
serviceDetails, err := createPipelinesDetailsByFlags(c)
if err != nil {
return err
}

// Create new sync command and add filters
syncCommand := pipelines.NewSyncCommand()
syncCommand.SetBranch(branch)
syncCommand.SetRepositoryFullName(repository)
syncCommand.SetServerDetails(serviceDetails)
return commands.Exec(syncCommand)
}

// getSyncPipelineResourcesStatus fetch sync status for a given repository path and branch name
func getSyncPipelineResourcesStatus(c *cli.Context) error {
branch := c.String("branch")
repository := c.String("repository")
clientlog.Info("Fetching pipeline sync status on repository:", repository, "branch:", branch)

// Fetch service details for authentication
serviceDetails, err := createPipelinesDetailsByFlags(c)
if err != nil {
return err
}

// Create sync status command and add filter params
syncStatusCommand := pipelines.NewSyncStatusCommand()
syncStatusCommand.SetBranch(branch)
syncStatusCommand.SetRepoPath(repository)
syncStatusCommand.SetServerDetails(serviceDetails)
return commands.Exec(syncStatusCommand)
}

// getVersion version command handler
func getVersion(c *cli.Context) error {
serviceDetails, err := createPipelinesDetailsByFlags(c)
if err != nil {
return err
}
versionCommand := pipelines.NewVersionCommand()
versionCommand.SetServerDetails(serviceDetails)
return commands.Exec(versionCommand)
}

// triggerNewRun triggers a new run for supplied flag values
func triggerNewRun(c *cli.Context) error {
// Read arguments pipeline name and branch to trigger pipeline run
pipelineName := c.Args().Get(0)
branch := c.Args().Get(1)
multiBranch := getMultiBranch(c)
coreutils.PrintTitle("Triggering pipeline run ")
clientlog.Info("Triggering on pipeline:", pipelineName, "for branch:", branch)

// Get service config details
serviceDetails, err := createPipelinesDetailsByFlags(c)
if err != nil {
return err
}

// Trigger a pipeline run using branch name and pipeline name
triggerCommand := pipelines.NewTriggerCommand()
triggerCommand.SetBranch(branch).
SetPipelineName(pipelineName).
SetServerDetails(serviceDetails).
SetMultiBranch(multiBranch)
return commands.Exec(triggerCommand)
}
25 changes: 0 additions & 25 deletions pipelines/config.go

This file was deleted.

33 changes: 0 additions & 33 deletions pipelines/runstatus.go

This file was deleted.

47 changes: 0 additions & 47 deletions pipelines/sync.go

This file was deleted.

18 changes: 0 additions & 18 deletions pipelines/systeminfo.go

This file was deleted.

33 changes: 0 additions & 33 deletions pipelines/triggerrun.go

This file was deleted.

4 changes: 2 additions & 2 deletions utils/cliutils/commandsflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ const (
repository = "repository"
singleBranch = "single-branch"
Sync = "sync"
SyncStatus = "syncstatus"
SyncStatus = "sync-status"

// *** TransferInstall Commands' flags ***
installPluginPrefix = "install-"
Expand Down Expand Up @@ -1480,7 +1480,7 @@ var flagsMap = map[string]cli.Flag{
singleBranch: cli.BoolFlag{
Name: singleBranch,
Usage: "[Default: false] Single branch to filter multi branches and single branch pipelines sources.` `",
},
},
Stop: cli.BoolFlag{
Name: Stop,
Usage: "[Default: false] Set to true to stop the transfer-files command currently in progress. Useful when running the transfer-files command in the background.` `",
Expand Down