Skip to content
This repository was archived by the owner on Feb 12, 2019. It is now read-only.

Commit 30a33a8

Browse files
committed
find changes by changelocator
1 parent 5440a71 commit 30a33a8

File tree

5 files changed

+170
-0
lines changed

5 files changed

+170
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ Each area has its own list of methods available
153153
Change ByChangeId(string id);
154154
Change LastChangeDetailByBuildConfigId(string buildConfigId);
155155
List<Change> ByBuildConfigId(string buildConfigId);
156+
List<Change> ByLocator(ChangeLocator changeLocator);
156157

157158
###BuildArtifacts
158159
void DownloadArtifactsByBuildId(string buildId, Action<string> downloadHandler);

src/TeamCitySharp/ActionTypes/Changes.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Linq;
33
using TeamCitySharp.Connection;
44
using TeamCitySharp.DomainEntities;
5+
using TeamCitySharp.Locators;
56

67
namespace TeamCitySharp.ActionTypes
78
{
@@ -42,5 +43,14 @@ public Change LastChangeDetailByBuildConfigId(string buildConfigId)
4243
return changes.FirstOrDefault();
4344
}
4445

46+
public List<Change> ByLocator(ChangeLocator locator)
47+
{
48+
var changeWrapper = _caller.GetFormat<ChangeWrapper>("/app/rest/changes?locator={0}", locator);
49+
if (changeWrapper.Change.Count > 0)
50+
{
51+
return changeWrapper.Change;
52+
}
53+
return new List<Change>();
54+
}
4555
}
4656
}

src/TeamCitySharp/ActionTypes/IChanges.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Collections.Generic;
22
using TeamCitySharp.DomainEntities;
3+
using TeamCitySharp.Locators;
34

45
namespace TeamCitySharp.ActionTypes
56
{
@@ -9,5 +10,6 @@ public interface IChanges
910
Change ByChangeId(string id);
1011
Change LastChangeDetailByBuildConfigId(string buildConfigId);
1112
List<Change> ByBuildConfigId(string buildConfigId);
13+
List<Change> ByLocator(ChangeLocator locator);
1214
}
1315
}
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace TeamCitySharp.Locators
7+
{
8+
public class ChangeLocator
9+
{
10+
public static ChangeLocator WithId(string id)
11+
{
12+
return new ChangeLocator() {Id = id};
13+
}
14+
15+
public static ChangeLocator WithBuildId(long id)
16+
{
17+
return new ChangeLocator {Build = BuildLocator.WithId(id)};
18+
}
19+
20+
public static ChangeLocator WithDimensions(string id,
21+
string project = null,
22+
BuildTypeLocator buildType = null,
23+
BuildLocator build = null,
24+
string vcsRoot = null,
25+
string vcsRootInstance = null,
26+
string userName = null,
27+
UserLocator user = null,
28+
string version = null,
29+
string internalVersion = null,
30+
string comment = null,
31+
string file = null,
32+
ChangeLocator sinceChange = null,
33+
int? maxResults = null,
34+
int? startIndex = null
35+
)
36+
{
37+
return new ChangeLocator
38+
{
39+
Build = build,
40+
BuildType = buildType,
41+
Comment = comment,
42+
File = file,
43+
Id = id,
44+
InternalVersion = internalVersion,
45+
MaxResults = maxResults,
46+
Project = project,
47+
SinceChange = sinceChange,
48+
StartIndex = startIndex,
49+
Version = version,
50+
VcsRoot = vcsRoot,
51+
VcsRootInstance = vcsRootInstance,
52+
User = user,
53+
UserName = userName
54+
};
55+
}
56+
57+
public string Id { get; private set; }
58+
public string Project { get; private set; }
59+
public BuildTypeLocator BuildType { get; private set; }
60+
public BuildLocator Build { get; private set; }
61+
public string VcsRoot { get; private set; }
62+
public string VcsRootInstance { get; private set; }
63+
public string UserName { get; private set; }
64+
public UserLocator User { get; private set; }
65+
public string Version { get; private set; }
66+
public string InternalVersion { get; private set; }
67+
public string Comment { get; private set; }
68+
public string File { get; private set; }
69+
public ChangeLocator SinceChange { get; private set; }
70+
public int? MaxResults { get; private set; }
71+
public int? StartIndex { get; private set; }
72+
73+
public override string ToString()
74+
{
75+
if (Id != null)
76+
{
77+
return "id:" + Id;
78+
}
79+
80+
var locatorFields = new List<string>();
81+
82+
if (BuildType != null)
83+
{
84+
locatorFields.Add("buildType:(" + BuildType + ")");
85+
}
86+
87+
if (Build != null)
88+
{
89+
locatorFields.Add("build:(" + Build + ")");
90+
}
91+
92+
if (User != null)
93+
{
94+
locatorFields.Add("user:(" + User + ")");
95+
}
96+
97+
if (SinceChange != null)
98+
{
99+
locatorFields.Add("sinceChange:(" + SinceChange + ")");
100+
}
101+
102+
if (!String.IsNullOrEmpty(Project))
103+
{
104+
locatorFields.Add("project:" + Project);
105+
}
106+
107+
if (!String.IsNullOrEmpty(VcsRoot))
108+
{
109+
locatorFields.Add("vcsRoot:" + VcsRoot);
110+
}
111+
112+
if (!String.IsNullOrEmpty(VcsRootInstance))
113+
{
114+
locatorFields.Add("vcsRootInstance:" + VcsRootInstance);
115+
}
116+
117+
if (!String.IsNullOrEmpty(UserName))
118+
{
119+
locatorFields.Add("userName:" + UserName);
120+
}
121+
122+
if (!String.IsNullOrEmpty(Version))
123+
{
124+
locatorFields.Add("version:" + Version);
125+
}
126+
127+
if (!String.IsNullOrEmpty(InternalVersion))
128+
{
129+
locatorFields.Add("internalVersion:" + InternalVersion);
130+
}
131+
132+
if (!String.IsNullOrEmpty(Comment))
133+
{
134+
locatorFields.Add("comment:" + Comment);
135+
}
136+
137+
if (!String.IsNullOrEmpty(File))
138+
{
139+
locatorFields.Add("file:" + File);
140+
}
141+
142+
if (MaxResults.HasValue)
143+
{
144+
locatorFields.Add("count:" + MaxResults.Value.ToString());
145+
}
146+
147+
if (StartIndex.HasValue)
148+
{
149+
locatorFields.Add("start:" + StartIndex.Value.ToString());
150+
}
151+
152+
return string.Join(",", locatorFields.ToArray());
153+
}
154+
}
155+
}

src/TeamCitySharp/TeamCitySharp.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
</Reference>
4343
<Reference Include="System" />
4444
<Reference Include="System.Core" />
45+
<Reference Include="System.Web" />
4546
<Reference Include="System.Xml.Linq" />
4647
<Reference Include="System.Data.DataSetExtensions" />
4748
<Reference Include="Microsoft.CSharp" />
@@ -67,6 +68,7 @@
6768
<Compile Include="ActionTypes\Projects.cs" />
6869
<Compile Include="ActionTypes\ServerInformation.cs" />
6970
<Compile Include="Connection\ITeamCityCaller.cs" />
71+
<Compile Include="Locators\ChangeLocator.cs" />
7072
<Compile Include="TeamCityClient.cs" />
7173
<Compile Include="ActionTypes\Users.cs" />
7274
<Compile Include="ActionTypes\VcsRoots.cs" />

0 commit comments

Comments
 (0)