Skip to content

Commit 715be69

Browse files
committed
Fix serialization issue with teamcity:branchSpec for vcsRoot
1 parent 36ce0a2 commit 715be69

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

teamcity/git_vcs_root_options.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ type GitVcsRootOptions struct {
9595
//DefaultBranch indicates which main branch or tag to be monitored by the VCS Root. Requied.
9696
DefaultBranch string `prop:"branch"`
9797

98-
//BrancSpec are monitor besides the default one as a newline-delimited set of rules in the form of +|-:branch name (with the optional * placeholder)
98+
//BranchSpec are monitor besides the default one as a newline-delimited set of rules in the form of +|-:branch name (with the optional * placeholder)
9999
//Set separately, outside constructor.
100-
BranchSpec []string `prop:"teamcity:branchSpec" separator:"\\n"`
100+
BranchSpec []string `prop:"teamcity:branchSpec" separator:"\n"`
101101

102102
//FetchURL is used for fetching data from the repository. Required.
103103
FetchURL string `prop:"url"`
@@ -220,7 +220,7 @@ func (o *GitVcsRootOptions) properties() *Properties {
220220

221221
if len(o.BranchSpec) > 0 {
222222
// Some properties use \\r\\n to split. But this one only uses \\n, conversely
223-
p.AddOrReplaceValue("teamcity:branchSpec", strings.Join(o.BranchSpec, "\\n"))
223+
p.AddOrReplaceValue("teamcity:branchSpec", strings.Join(o.BranchSpec, "\n"))
224224
}
225225

226226
if o.EnableTagsInBranchSpec {

teamcity/git_vcs_root_options_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func Test_GitVcsRootOptionsVcsRootProperties_BranchSpec(t *testing.T) {
119119
actual.BranchSpec = []string{"+:refs/(pull/*)/head", "+:refs/heads/develop"}
120120
props := actual.properties()
121121

122-
propAssert.assertPropertyValue(props, "teamcity:branchSpec", "+:refs/(pull/*)/head\\n+:refs/heads/develop")
122+
propAssert.assertPropertyValue(props, "teamcity:branchSpec", "+:refs/(pull/*)/head\n+:refs/heads/develop")
123123
}
124124

125125
func Test_GitVcsRootOptionsVcsRootProperties_EnableTagsInBranchSpec(t *testing.T) {
@@ -160,7 +160,7 @@ func Test_PropertiesToGitVcsRootOptions(t *testing.T) {
160160
sut := NewProperties([]*Property{
161161
NewProperty("branch", "refs/head/master"),
162162
NewProperty("reportTagRevisions", "true"),
163-
NewProperty("teamcity:branchSpec", "+:refs/(pull/*)/head\\n+:refs/heads/develop"),
163+
NewProperty("teamcity:branchSpec", "+:refs/(pull/*)/head\n+:refs/heads/develop"),
164164
NewProperty("authMethod", string(GitAuthMethodPassword)),
165165
NewProperty("username", "admin"),
166166
NewProperty("submoduleCheckout", "CHECKOUT"),

teamcity/vcs_root_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func TestGitVcsRoot_Get(t *testing.T) {
3232
require.NotNil(actual.Project)
3333
assert.Equal(actual.Project.ID, actual.Project.ID)
3434
assert.Equal(actual.Name(), actual.Name())
35+
assert.ElementsMatch(actual.Options.BranchSpec, []string{"+:refs/heads/*", "-:refs/heads/*-ng-build"})
3536
}
3637

3738
func TestGitVcsRoot_Update(t *testing.T) {
@@ -152,6 +153,7 @@ func TestGitVcsRoot_Invariants(t *testing.T) {
152153

153154
func getTestVcsRootData(projectId string) teamcity.VcsRoot {
154155
opts, _ := teamcity.NewGitVcsRootOptionsDefaults("refs/head/master", "https://github.com/cvbarros/go-teamcity")
156+
opts.BranchSpec = []string{"+:refs/heads/*", "-:refs/heads/*-ng-build"}
155157
v, _ := teamcity.NewGitVcsRoot(projectId, "Application", opts)
156158
return v
157159
}

0 commit comments

Comments
 (0)