Skip to content

Commit fac5bb1

Browse files
authored
Fix skip errors flag (#539)
We didn't return the specs in case of an error, so we would ignore the error, but still have no changeset specs uploaded, which resulted in the generated batch spec in the preview being empty.
1 parent e791fe1 commit fac5bb1

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

internal/batches/executor/executor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func (x *executor) Wait(ctx context.Context) ([]*batches.ChangesetSpec, error) {
171171
case err := <-result:
172172
close(result)
173173
if err != nil {
174-
return nil, err
174+
return x.specs, err
175175
}
176176
}
177177

internal/batches/executor/executor_test.go

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ func TestExecutor_Integration(t *testing.T) {
8282
wantAuthorEmail string
8383

8484
wantErrInclude string
85+
// wantCacheHits overwrites the desired count of cache entries found after execution.
86+
wantCacheHits int
8587
}{
8688
{
8789
name: "success",
@@ -407,6 +409,36 @@ output4=integration-test-batch-change`,
407409
},
408410
},
409411
},
412+
{
413+
name: "skips errors",
414+
archives: []mock.RepoArchive{
415+
{Repo: srcCLIRepo, Files: map[string]string{
416+
"README.md": "# Welcome to the README\n",
417+
}},
418+
{Repo: sourcegraphRepo, Files: map[string]string{
419+
"README.md": "# Sourcegraph README\n",
420+
}},
421+
},
422+
steps: []batches.Step{
423+
{Run: `echo -e "foobar\n" >> README.md`},
424+
{
425+
Run: `exit 1`,
426+
If: fmt.Sprintf(`${{ eq repository.name %q }}`, sourcegraphRepo.Name),
427+
},
428+
},
429+
tasks: []*Task{
430+
{Repository: srcCLIRepo},
431+
{Repository: sourcegraphRepo},
432+
},
433+
wantFilesChanged: filesByRepository{
434+
srcCLIRepo.ID: filesByBranch{
435+
changesetTemplateBranch: []string{"README.md"},
436+
},
437+
sourcegraphRepo.ID: {},
438+
},
439+
wantErrInclude: "execution in github.com/sourcegraph/sourcegraph failed: run: exit 1",
440+
wantCacheHits: 1,
441+
},
410442
}
411443

412444
for _, tc := range tests {
@@ -488,11 +520,10 @@ output4=integration-test-batch-change`,
488520
if err == nil {
489521
t.Fatalf("expected error to include %q, but got no error", tc.wantErrInclude)
490522
} else {
491-
if !strings.Contains(err.Error(), tc.wantErrInclude) {
523+
if !strings.Contains(strings.ToLower(err.Error()), strings.ToLower(tc.wantErrInclude)) {
492524
t.Errorf("wrong error. have=%q want included=%q", err, tc.wantErrInclude)
493525
}
494526
}
495-
return
496527
}
497528

498529
wantSpecs := 0
@@ -578,6 +609,9 @@ output4=integration-test-batch-change`,
578609
if tc.wantErrInclude != "" {
579610
want = 0
580611
}
612+
if tc.wantCacheHits != 0 {
613+
want = tc.wantCacheHits
614+
}
581615

582616
// Verify that there is a cache entry for each repo.
583617
if have := cache.size(); have != want {

0 commit comments

Comments
 (0)