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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ All notable changes to `src-cli` are documented in this file.

### Changed

- The progress bar in `src campaign [preview|apply]` now shows when executing a step failed in a repository by styling the line red and displaying standard error output. [#355](https://github.com/sourcegraph/src-cli/pull/355)

### Fixed

## 3.21.2
Expand Down
20 changes: 18 additions & 2 deletions cmd/src/campaign_progress_printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,11 @@ func (p *campaignProgressPrinter) PrintStatuses(statuses []*campaigns.TaskStatus
// Log that this task completed, but only if there is no
// currently executing one in this bar, to avoid flicker.
if _, ok := p.statusBarRepo[idx]; !ok {
p.progress.StatusBarCompletef(idx, statusText)
if ts.Err != nil {
p.progress.StatusBarFailf(idx, statusText)
} else {
p.progress.StatusBarCompletef(idx, statusText)
}
}
delete(p.repoStatusBar, ts.RepoName)
}
Expand All @@ -161,12 +165,24 @@ func (p *campaignProgressPrinter) PrintStatuses(statuses []*campaigns.TaskStatus
}
}

type statusTexter interface {
StatusText() string
}

func taskStatusText(ts *campaigns.TaskStatus) (string, error) {
var statusText string

if ts.IsCompleted() {
if ts.ChangesetSpec == nil {
statusText = "No changes"
if ts.Err != nil {
if texter, ok := ts.Err.(statusTexter); ok {
statusText = texter.StatusText()
} else {
statusText = ts.Err.Error()
}
} else {
statusText = "No changes"
}
} else {
fileDiffs, err := diff.ParseMultiFileDiff([]byte(ts.ChangesetSpec.Commits[0].Diff))
if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions internal/campaigns/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ func (e TaskExecutionErr) Error() string {
)
}

func (e TaskExecutionErr) StatusText() string {
if stepErr, ok := e.Err.(stepFailedErr); ok {
return stepErr.SingleLineError()
}
return e.Err.Error()
}

type Executor interface {
AddTask(repo *graphql.Repository, steps []Step, template *ChangesetTemplate) *TaskStatus
LogFiles() []string
Expand Down
9 changes: 9 additions & 0 deletions internal/campaigns/run_steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,12 @@ func (e stepFailedErr) Error() string {

return out.String()
}

func (e stepFailedErr) SingleLineError() string {
out := e.Err.Error()
if len(e.Stderr) > 0 {
out = e.Stderr
}

return strings.Split(out, "\n")[0]
}
1 change: 1 addition & 0 deletions internal/output/progress_with_status_bars.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type ProgressWithStatusBars interface {

StatusBarUpdatef(i int, format string, args ...interface{})
StatusBarCompletef(i int, format string, args ...interface{})
StatusBarFailf(i int, format string, args ...interface{})
StatusBarResetf(i int, label, format string, args ...interface{})
}

Expand Down
10 changes: 10 additions & 0 deletions internal/output/progress_with_status_bars_simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ func (p *progressWithStatusBarsSimple) StatusBarCompletef(i int, format string,
}
}

func (p *progressWithStatusBarsSimple) StatusBarFailf(i int, format string, args ...interface{}) {
if p.statusBars[i] != nil {
wasCompleted := p.statusBars[i].completed
p.statusBars[i].Failf(format, args...)
if !wasCompleted {
writeStatusBar(p.Output, p.statusBars[i])
}
}
}

func (p *progressWithStatusBarsSimple) StatusBarResetf(i int, label, format string, args ...interface{}) {
if p.statusBars[i] != nil {
p.statusBars[i].Resetf(label, format, args...)
Expand Down
18 changes: 17 additions & 1 deletion internal/output/progress_with_status_bars_tty.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,17 @@ func (p *progressWithStatusBarsTTY) StatusBarCompletef(i int, format string, arg
p.drawInSitu()
}

func (p *progressWithStatusBarsTTY) StatusBarFailf(i int, format string, args ...interface{}) {
p.o.lock.Lock()
defer p.o.lock.Unlock()

if p.statusBars[i] != nil {
p.statusBars[i].Failf(format, args...)
}

p.drawInSitu()
}

func (p *progressWithStatusBarsTTY) draw() {
for _, bar := range p.bars {
p.writeBar(bar)
Expand Down Expand Up @@ -205,8 +216,13 @@ func (p *progressWithStatusBarsTTY) determineStatusBarLabelWidth() {
func (p *progressWithStatusBarsTTY) writeStatusBar(last bool, statusBar *StatusBar) {
style := StylePending
if statusBar.completed {
style = StyleSuccess
if statusBar.failed {
style = StyleWarning
} else {
style = StyleSuccess
}
}

box := "├── "
if last {
box = "└── "
Expand Down
8 changes: 8 additions & 0 deletions internal/output/status_bar.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "time"
// of a process.
type StatusBar struct {
completed bool
failed bool

label string
format string
Expand All @@ -24,10 +25,17 @@ func (sb *StatusBar) Completef(format string, args ...interface{}) {
sb.finishedAt = time.Now()
}

// Failf sets the StatusBar to completed and failed and updates its text.
func (sb *StatusBar) Failf(format string, args ...interface{}) {
sb.Completef(format, args...)
sb.failed = true
}

// Resetf sets the status of the StatusBar to incomplete and updates its label and text.
func (sb *StatusBar) Resetf(label, format string, args ...interface{}) {
sb.initialized = true
sb.completed = false
sb.failed = false
sb.label = label
sb.format = format
sb.args = args
Expand Down