Skip to content

Commit 2fe9661

Browse files
authored
batches: correctly fallback to nil for unmatched published fields (#564)
See sourcegraph/batch-change-utils#12 for more context.
1 parent 0968c73 commit 2fe9661

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ require (
1818
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4
1919
github.com/pkg/errors v0.9.1
2020
github.com/rivo/uniseg v0.2.0 // indirect
21-
github.com/sourcegraph/batch-change-utils v0.0.0-20210309183117-206c057cc03e
21+
github.com/sourcegraph/batch-change-utils v0.0.0-20210708162152-c9f35b905d94
2222
github.com/sourcegraph/go-diff v0.6.1
2323
github.com/sourcegraph/jsonx v0.0.0-20200629203448-1a936bd500cf
2424
github.com/sourcegraph/sourcegraph/lib v0.0.0-20210628190057-faa35110fad5

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ github.com/shurcooL/go-goon v0.0.0-20210110234559-7585751d9a17/go.mod h1:N5mDOms
237237
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
238238
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
239239
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
240-
github.com/sourcegraph/batch-change-utils v0.0.0-20210309183117-206c057cc03e h1:8dpmTar1H4dS4f3WWTtG6FSK/GbjQl7alHRJlzNY0lo=
241-
github.com/sourcegraph/batch-change-utils v0.0.0-20210309183117-206c057cc03e/go.mod h1:kKNRPN6dxuXwC4UUhPVcAJsvz4EVEfI0jyN5HUJsazA=
240+
github.com/sourcegraph/batch-change-utils v0.0.0-20210708162152-c9f35b905d94 h1:Yzs0ABVo9TXlfhIJZlHbj+T5a/e2lGyxH0bTTF1OtSE=
241+
github.com/sourcegraph/batch-change-utils v0.0.0-20210708162152-c9f35b905d94/go.mod h1:kKNRPN6dxuXwC4UUhPVcAJsvz4EVEfI0jyN5HUJsazA=
242242
github.com/sourcegraph/go-diff v0.6.1 h1:hmA1LzxW0n1c3Q4YbrFgg4P99GSnebYa3x8gr0HZqLQ=
243243
github.com/sourcegraph/go-diff v0.6.1/go.mod h1:iBszgVvyxdc8SFZ7gm69go2KDdt3ag071iBaWPF6cjs=
244244
github.com/sourcegraph/jsonx v0.0.0-20200629203448-1a936bd500cf h1:oAdWFqhStsWiiMP/vkkHiMXqFXzl1XfUNOdxKJbd6bI=

internal/batches/executor/changeset_specs.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ func createChangesetSpecs(task *Task, result executionResult, features batches.F
7272
var published interface{} = nil
7373
if task.Template.Published != nil {
7474
published = task.Template.Published.ValueWithSuffix(repo, branch)
75+
76+
// Backward compatibility: before optional published fields were
77+
// allowed, ValueWithSuffix() would fall back to false, not nil. We
78+
// need to replicate this behaviour here.
79+
if published == nil && !features.AllowOptionalPublished {
80+
published = false
81+
}
7582
} else if !features.AllowOptionalPublished {
7683
return nil, errOptionalPublishedUnsupported
7784
}

internal/batches/executor/changeset_specs_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,21 @@ func TestCreateChangesetSpecs(t *testing.T) {
125125
}),
126126
features: featuresAllEnabled(),
127127
result: defaultResult,
128+
want: []*batches.ChangesetSpec{
129+
specWith(defaultChangesetSpec, func(s *batches.ChangesetSpec) {
130+
s.Published = nil
131+
}),
132+
},
133+
wantErr: "",
134+
},
135+
{
136+
name: "publish by branch not matching on an old Sourcegraph version",
137+
task: taskWith(defaultTask, func(task *Task) {
138+
published := `[{"github.com/sourcegraph/*@another-branch-name": true}]`
139+
task.Template.Published = parsePublishedFieldString(t, published)
140+
}),
141+
features: featuresWithoutOptionalPublished,
142+
result: defaultResult,
128143
want: []*batches.ChangesetSpec{
129144
specWith(defaultChangesetSpec, func(s *batches.ChangesetSpec) {
130145
s.Published = false

0 commit comments

Comments
 (0)