github.com/jfrog/jfrog-cli-core/v2@v2.52.0/pipelines/commands/syncstatus.go (about) 1 package commands 2 3 import ( 4 "fmt" 5 "github.com/jfrog/jfrog-cli-core/v2/pipelines/manager" 6 "github.com/jfrog/jfrog-cli-core/v2/pipelines/status" 7 "github.com/jfrog/jfrog-cli-core/v2/utils/config" 8 "github.com/jfrog/jfrog-client-go/pipelines/services" 9 "github.com/jfrog/jfrog-client-go/utils/log" 10 ) 11 12 type SyncStatusCommand struct { 13 serverDetails *config.ServerDetails 14 branch string 15 repoPath string 16 } 17 18 const ( 19 PipeStatusFormat = "Status: %s\nIsSyncing: %t\nLastSyncStartedAt: %s\nLastSyncEndedAt: %s\n" + 20 "CommitSHA: %s\nCommitter: %s\nCommitMessage: %s\nSyncSummary: %s\n" 21 ) 22 23 func NewSyncStatusCommand() *SyncStatusCommand { 24 return &SyncStatusCommand{} 25 } 26 27 func (sc *SyncStatusCommand) ServerDetails() (*config.ServerDetails, error) { 28 return sc.serverDetails, nil 29 } 30 31 func (sc *SyncStatusCommand) SetServerDetails(serverDetails *config.ServerDetails) *SyncStatusCommand { 32 sc.serverDetails = serverDetails 33 return sc 34 } 35 36 func (sc *SyncStatusCommand) CommandName() string { 37 return "pl_sync_status" 38 } 39 40 func (sc *SyncStatusCommand) SetBranch(br string) *SyncStatusCommand { 41 sc.branch = br 42 return sc 43 } 44 45 func (sc *SyncStatusCommand) SetRepoPath(repo string) *SyncStatusCommand { 46 sc.repoPath = repo 47 return sc 48 } 49 50 func (sc *SyncStatusCommand) Run() error { 51 serviceManager, err := manager.CreateServiceManager(sc.serverDetails) 52 if err != nil { 53 return err 54 } 55 // Filter pipeline resources sync status with repository name and branch name 56 pipelineSyncStatuses, err := serviceManager.GetSyncStatusForPipelineResource(sc.repoPath, sc.branch) 57 if err != nil { 58 return err 59 } 60 sc.displaySyncStatus(pipelineSyncStatuses) 61 return nil 62 } 63 64 // displaySyncStatus outputs to stdout the sync status 65 func (sc *SyncStatusCommand) displaySyncStatus(pipelineSyncStatuses []services.PipelineSyncStatus) { 66 for index, pipeSyncStatus := range pipelineSyncStatuses { 67 pipeSyncStatusCode := status.GetPipelineStatus(pipeSyncStatus.LastSyncStatusCode) 68 if log.IsStdErrTerminal() && log.IsColorsSupported() { 69 colorCode := status.GetStatusColorCode(pipeSyncStatusCode) 70 log.Output(colorCode.Sprintf(PipeStatusFormat, pipeSyncStatusCode, *pipelineSyncStatuses[index].IsSyncing, 71 pipelineSyncStatuses[index].LastSyncStartedAt, pipelineSyncStatuses[index].LastSyncEndedAt, pipelineSyncStatuses[index].CommitData.CommitSha, 72 pipelineSyncStatuses[index].CommitData.Committer, pipelineSyncStatuses[index].CommitData.CommitMsg, pipelineSyncStatuses[index].LastSyncLogs)) 73 return 74 } 75 log.Output(fmt.Sprintf(PipeStatusFormat, pipeSyncStatusCode, *pipelineSyncStatuses[index].IsSyncing, pipelineSyncStatuses[index].LastSyncStartedAt, 76 pipelineSyncStatuses[index].LastSyncEndedAt, pipelineSyncStatuses[index].CommitData.CommitSha, pipelineSyncStatuses[index].CommitData.Committer, 77 pipelineSyncStatuses[index].CommitData.CommitMsg, pipelineSyncStatuses[index].LastSyncLogs)) 78 } 79 }