Skip to content

Commit

Permalink
Fix serialization issue with teamcity:branchSpec for vcsRoot
Browse files Browse the repository at this point in the history
  • Loading branch information
cvbarros committed Dec 10, 2019
1 parent 36ce0a2 commit 715be69
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions teamcity/git_vcs_root_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ type GitVcsRootOptions struct {
//DefaultBranch indicates which main branch or tag to be monitored by the VCS Root. Requied.
DefaultBranch string `prop:"branch"`

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

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

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

if o.EnableTagsInBranchSpec {
Expand Down
4 changes: 2 additions & 2 deletions teamcity/git_vcs_root_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func Test_GitVcsRootOptionsVcsRootProperties_BranchSpec(t *testing.T) {
actual.BranchSpec = []string{"+:refs/(pull/*)/head", "+:refs/heads/develop"}
props := actual.properties()

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

func Test_GitVcsRootOptionsVcsRootProperties_EnableTagsInBranchSpec(t *testing.T) {
Expand Down Expand Up @@ -160,7 +160,7 @@ func Test_PropertiesToGitVcsRootOptions(t *testing.T) {
sut := NewProperties([]*Property{
NewProperty("branch", "refs/head/master"),
NewProperty("reportTagRevisions", "true"),
NewProperty("teamcity:branchSpec", "+:refs/(pull/*)/head\\n+:refs/heads/develop"),
NewProperty("teamcity:branchSpec", "+:refs/(pull/*)/head\n+:refs/heads/develop"),
NewProperty("authMethod", string(GitAuthMethodPassword)),
NewProperty("username", "admin"),
NewProperty("submoduleCheckout", "CHECKOUT"),
Expand Down
2 changes: 2 additions & 0 deletions teamcity/vcs_root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func TestGitVcsRoot_Get(t *testing.T) {
require.NotNil(actual.Project)
assert.Equal(actual.Project.ID, actual.Project.ID)
assert.Equal(actual.Name(), actual.Name())
assert.ElementsMatch(actual.Options.BranchSpec, []string{"+:refs/heads/*", "-:refs/heads/*-ng-build"})
}

func TestGitVcsRoot_Update(t *testing.T) {
Expand Down Expand Up @@ -152,6 +153,7 @@ func TestGitVcsRoot_Invariants(t *testing.T) {

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

0 comments on commit 715be69

Please sign in to comment.