Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: stack72/TeamCitySharp
base: master
...
head fork: Haemoglobin/TeamCitySharp
compare: TeamCity_Write_API
Checking mergeability… Don’t worry, you can still create the pull request.
  • 1 commit
  • 21 files changed
  • 0 commit comments
  • 1 contributor
Commits on Apr 16, 2012
Hamish Graham Add support for the TeamCity 7.0 write API.
Still not 100% API complete and still requires some tidy up (i.e currently accepting raw XML for some calls instead of strongly typed objects to serialize).
9dddb1b
Showing with 511 additions and 33 deletions.
  1. +88 −8 src/TeamCitySharp/Connection/TeamCityCaller.cs
  2. +16 −0 src/TeamCitySharp/DomainEntities/AgentRequirement.cs
  3. +14 −0 src/TeamCitySharp/DomainEntities/AgentRequirements.cs
  4. +17 −0 src/TeamCitySharp/DomainEntities/ArtifactDependencies.cs
  5. +21 −0 src/TeamCitySharp/DomainEntities/ArtifactDependency.cs
  6. +12 −0 src/TeamCitySharp/DomainEntities/BuildConfig.cs
  7. +25 −0 src/TeamCitySharp/DomainEntities/BuildStep.cs
  8. +19 −0 src/TeamCitySharp/DomainEntities/BuildSteps.cs
  9. +16 −0 src/TeamCitySharp/DomainEntities/BuildTrigger.cs
  10. +16 −0 src/TeamCitySharp/DomainEntities/BuildTriggers.cs
  11. +17 −0 src/TeamCitySharp/DomainEntities/Parameters.cs
  12. +2 −0  src/TeamCitySharp/DomainEntities/Project.cs
  13. +16 −0 src/TeamCitySharp/DomainEntities/Properties.cs
  14. +19 −0 src/TeamCitySharp/DomainEntities/Property.cs
  15. +19 −17 src/TeamCitySharp/DomainEntities/VcsRoot.cs
  16. +17 −0 src/TeamCitySharp/DomainEntities/VcsRootEntries.cs
  17. +21 −0 src/TeamCitySharp/DomainEntities/VcsRootEntry.cs
  18. +9 −0 src/TeamCitySharp/DomainEntities/VcsRootField.cs
  19. +20 −1 src/TeamCitySharp/ITeamCityClient.cs
  20. +108 −2 src/TeamCitySharp/TeamCityClient.cs
  21. +19 −5 src/TeamCitySharp/TeamCitySharp.csproj
View
96 src/TeamCitySharp/Connection/TeamCityCaller.cs
@@ -32,28 +32,108 @@ public T GetFormat<T>(string urlPart, params object[] parts)
return Get<T>(string.Format(urlPart, parts));
}
- public T Get<T>(string urlPart)
+ public T PostFormat<T>(object data, string urlPart, params object[] parts)
{
- if (CheckForUserNameAndPassword())
- throw new ArgumentException("If you are not acting as a guest you must supply userName and password");
+ return Post<T>(data.ToString(), string.Format(urlPart, parts));
+ }
+
+ public void PostFormat(object data, string urlPart, params object[] parts)
+ {
+ Post(data.ToString(), string.Format(urlPart, parts));
+ }
+
+ public void PutFormat(object data, string urlPart, params object[] parts)
+ {
+ Put(data.ToString(), string.Format(urlPart, parts));
+ }
+ public void DeleteFormat(string urlPart, params object[] parts)
+ {
+ Delete(string.Format(urlPart, parts));
+ }
+
+ private string GetUrl(string urlPart)
+ {
if (string.IsNullOrEmpty(urlPart))
throw new ArgumentException("Url must be specfied");
+
+ return CreateUrl(urlPart);
+ }
+
+ private HttpClient GetRequest()
+ {
+ if (CheckForUserNameAndPassword())
+ throw new ArgumentException("If you are not acting as a guest you must supply userName and password");
+
+ var request = CreateHttpRequest(_configuration.UserName, _configuration.Password);
+ return request;
+ }
+
+ private bool CheckForUserNameAndPassword()
+ {
+ return !_configuration.ActAsGuest && string.IsNullOrEmpty(_configuration.UserName) && string.IsNullOrEmpty(_configuration.Password);
+ }
- var url = CreateUrl(urlPart);
- var response = CreateHttpRequest(_configuration.UserName, _configuration.Password).Get(url);
+ private void ProcessError(HttpResponse response, string url)
+ {
if (IsHttpError(response))
{
throw new HttpException(response.StatusCode, string.Format("Error {0}: Thrown with URL {1}", response.StatusDescription, url));
}
+ }
+ public T Get<T>(string urlPart)
+ {
+ var request = GetRequest();
+ var url = GetUrl(urlPart);
+ var response = request.Get(url);
+ ProcessError(response, url);
return response.StaticBody<T>();
}
- private bool CheckForUserNameAndPassword()
+ public void Put(string data, string urlPart)
{
- return !_configuration.ActAsGuest && string.IsNullOrEmpty(_configuration.UserName) && string.IsNullOrEmpty(_configuration.Password);
+ var request = GetRequest();
+ request.Request.Accept = HttpContentTypes.TextPlain;
+ var url = GetUrl(urlPart);
+ var response = request.Put(url, data, GetContentType(data));
+ ProcessError(response, url);
+ }
+
+ public T Post<T>(string data, string urlPart)
+ {
+ return PostInternal(data, urlPart).StaticBody<T>();
+ }
+
+ public void Post(string data, string urlPart)
+ {
+ PostInternal(data, urlPart);
+ }
+
+ private HttpResponse PostInternal(string data, string urlPart)
+ {
+ var request = GetRequest();
+ var url = GetUrl(urlPart);
+ var response = request.Post(url, data, GetContentType(data));
+ ProcessError(response, url);
+ return response;
+ }
+
+ public void Delete(string urlPart)
+ {
+ var request = GetRequest();
+ request.Request.Accept = HttpContentTypes.TextPlain;
+ var url = GetUrl(urlPart);
+ var response = request.Delete(url);
+ ProcessError(response, url);
+ }
+
+ private string GetContentType(string data)
+ {
+ if (data.StartsWith("<"))
+ return HttpContentTypes.ApplicationXml;
+ return HttpContentTypes.TextPlain;
}
private bool IsHttpError(HttpResponse response)
@@ -102,4 +182,4 @@ public bool Authenticate(string urlPart)
}
}
}
-}
+}
View
16 src/TeamCitySharp/DomainEntities/AgentRequirement.cs
@@ -0,0 +1,16 @@
+namespace TeamCitySharp.DomainEntities
+{
+ public class AgentRequirement
+ {
+ public override string ToString()
+ {
+ return "agent_requirement";
+ }
+
+ public string Id { get; set; }
+
+ public string Type { get; set; }
+
+ public Properties Properties { get; set; }
+ }
+}
View
14 src/TeamCitySharp/DomainEntities/AgentRequirements.cs
@@ -0,0 +1,14 @@
+using System.Collections.Generic;
+
+namespace TeamCitySharp.DomainEntities
+{
+ public class AgentRequirements
+ {
+ public override string ToString()
+ {
+ return "agent-requirements";
+ }
+
+ public List<AgentRequirement> AgentRequirement { get; set; }
+ }
+}
View
17 src/TeamCitySharp/DomainEntities/ArtifactDependencies.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace TeamCitySharp.DomainEntities
+{
+ public class ArtifactDependencies
+ {
+ public override string ToString()
+ {
+ return "artifact-dependencies";
+ }
+
+ public List<ArtifactDependency> ArtifactDependency { get; set; }
+ }
+}
View
21 src/TeamCitySharp/DomainEntities/ArtifactDependency.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace TeamCitySharp.DomainEntities
+{
+ public class ArtifactDependency
+ {
+ public override string ToString()
+ {
+ return "artifact_dependency";
+ }
+
+ public string Id { get; set; }
+
+ public string Type { get; set; }
+
+ public Properties Properties { get; set; }
+ }
+}
View
12 src/TeamCitySharp/DomainEntities/BuildConfig.cs
@@ -16,5 +16,17 @@ public override string ToString()
public string WebUrl { get; set; }
public Project Project { get; set; }
+
+ public Parameters Parameters { get; set; }
+
+ public ArtifactDependencies ArtifactDependencies { get; set; }
+
+ public VcsRootEntries VcsRootEntries { get; set; }
+
+ public BuildSteps Steps { get; set; }
+
+ public AgentRequirements AgentRequirements { get; set; }
+
+ public BuildTriggers Triggers { get; set; }
}
}
View
25 src/TeamCitySharp/DomainEntities/BuildStep.cs
@@ -0,0 +1,25 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace TeamCitySharp.DomainEntities
+{
+ public class BuildStep
+ {
+ public override string ToString()
+ {
+ return "step";
+ }
+
+ public string Id { get; set; }
+
+ public string Name { get; set; }
+
+ public string Type { get; set; }
+
+ public string Disabled { get; set; }
+
+ public Properties Properties { get; set; }
+ }
+}
View
19 src/TeamCitySharp/DomainEntities/BuildSteps.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace TeamCitySharp.DomainEntities
+{
+ public class BuildSteps
+ {
+ public override string ToString()
+ {
+ return "steps";
+ }
+ /// <summary>
+ /// Lists of all the build steps.
+ /// </summary>
+ public List<BuildStep> Step { get; set; }
+ }
+}
View
16 src/TeamCitySharp/DomainEntities/BuildTrigger.cs
@@ -0,0 +1,16 @@
+namespace TeamCitySharp.DomainEntities
+{
+ public class BuildTrigger
+ {
+ public override string ToString()
+ {
+ return "trigger";
+ }
+
+ public string Id { get; set; }
+
+ public string Type { get; set; }
+
+ public Properties Properties { get; set; }
+ }
+}
View
16 src/TeamCitySharp/DomainEntities/BuildTriggers.cs
@@ -0,0 +1,16 @@
+using System.Collections.Generic;
+
+namespace TeamCitySharp.DomainEntities
+{
+ public class BuildTriggers
+ {
+ public override string ToString()
+ {
+ return "triggers";
+ }
+ /// <summary>
+ /// Lists of all the build triggers
+ /// </summary>
+ public List<BuildTrigger> Trigger { get; set; }
+ }
+}
View
17 src/TeamCitySharp/DomainEntities/Parameters.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace TeamCitySharp.DomainEntities
+{
+ public class Parameters
+ {
+ public override string ToString()
+ {
+ return "parameters";
+ }
+
+ public List<Property> Property { get; set; }
+ }
+}
View
2  src/TeamCitySharp/DomainEntities/Project.cs
@@ -15,5 +15,7 @@ public override string ToString()
public string WebUrl { get; set; }
public BuildTypeWrapper BuildTypes { get; set; }
+
+ public Parameters Parameters { get; set; }
}
}
View
16 src/TeamCitySharp/DomainEntities/Properties.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace TeamCitySharp.DomainEntities
+{
+ public class Properties
+ {
+ public override string ToString()
+ {
+ return "properties";
+ }
+ public List<Property> Property { get; set; }
+ }
+}
View
19 src/TeamCitySharp/DomainEntities/Property.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace TeamCitySharp.DomainEntities
+{
+ public class Property
+ {
+ public override string ToString()
+ {
+ return Name;
+ }
+
+ public string Name { get; set; }
+ public string Value { get; set; }
+ }
+}
+
View
36 src/TeamCitySharp/DomainEntities/VcsRoot.cs
@@ -1,20 +1,22 @@
using System;
-namespace TeamCitySharp.DomainEntities
-{
- public class VcsRoot
- {
- public string Id { get; set; }
- public string vcsName { get; set; }
- public string Href { get; set; }
- public string Name { get; set; }
- public string Version { get; set; }
- public string Status { get; set; }
- public DateTime lastChecked { get; set; }
-
- public override string ToString()
- {
- return vcsName;
- }
- }
+namespace TeamCitySharp.DomainEntities
+{
+ public class VcsRoot
+ {
+ public string Id { get; set; }
+ public string vcsName { get; set; }
+ public string Href { get; set; }
+ public string Name { get; set; }
+ public string Version { get; set; }
+ public string Status { get; set; }
+ public DateTime lastChecked { get; set; }
+
+ public override string ToString()
+ {
+ return Name;
+ }
+
+ public Properties Properties { get; set; }
+ }
}
View
17 src/TeamCitySharp/DomainEntities/VcsRootEntries.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace TeamCitySharp.DomainEntities
+{
+ public class VcsRootEntries
+ {
+ public override string ToString()
+ {
+ return "vcs-root-entries";
+ }
+
+ public List<VcsRootEntry> VcsRootEntry { get; set; }
+ }
+}
View
21 src/TeamCitySharp/DomainEntities/VcsRootEntry.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace TeamCitySharp.DomainEntities
+{
+ public class VcsRootEntry
+ {
+ public override string ToString()
+ {
+ return "vcs-root-entry";
+ }
+
+ public VcsRoot VcsRoot { get; set; }
+
+ public string CheckoutRules { get; set; }
+
+ }
+
+}
View
9 src/TeamCitySharp/DomainEntities/VcsRootField.cs
@@ -0,0 +1,9 @@
+namespace TeamCitySharp.DomainEntities
+{
+ public enum VcsRootField
+ {
+ Name,
+ Shared,
+ ProjectId
+ }
+}
View
21 src/TeamCitySharp/ITeamCityClient.cs
@@ -54,5 +54,24 @@ public interface ITeamCityClient
List<Build> NonSuccessfulBuildsForUser(string userName);
T CallByUrl<T>(string urlPart);
+ Project CreateProject(string projectName);
+ void DeleteProject(string projectName);
+ BuildConfig CreateConfiguration(string projectName, string configurationName);
+ void SetConfigurationSetting(BuildTypeLocator locator, string settingName, string settingValue);
+ VcsRoot AttachVcsRoot(BuildTypeLocator locator, VcsRoot vcsRoot);
+ void SetVcsRootField(VcsRoot vcsRoot, VcsRootField field, object value);
+ void PostRawArtifactDependency(BuildTypeLocator locator, string rawXml);
+ void PostRawBuildStep(BuildTypeLocator locator, string rawXml);
+ void PostRawBuildTrigger(BuildTypeLocator locator, string rawXml);
+ void SetProjectParameter(string projectName, string settingName, string settingValue);
+ void SetConfigurationParameter(BuildTypeLocator locator, string key, string value);
+ void PostRawAgentRequirement(BuildTypeLocator locator, string rawXml);
+ void DetachVcsRoot(BuildTypeLocator locator, string vcsRootId);
+ void DeleteBuildStep(BuildTypeLocator locator, string buildStepId);
+ void DeleteArtifactDependency(BuildTypeLocator locator, string artifactDependencyId);
+ void DeleteAgentRequirement(BuildTypeLocator locator, string agentRequirementId);
+ void DeleteParameter(BuildTypeLocator locator, string parameterName);
+ void DeleteProjectParameter(string projectName, string parameterName);
+ void DeleteBuildTrigger(BuildTypeLocator locator, string buildTriggerId);
}
-}
+}
View
110 src/TeamCitySharp/TeamCityClient.cs
@@ -206,14 +206,14 @@ public BuildConfig BuildConfigByProjectIdAndConfigurationId(string projectId, st
public List<BuildConfig> BuildConfigsByProjectId(string projectId)
{
var buildWrapper = _caller.GetFormat<BuildTypeWrapper>("/app/rest/projects/id:{0}/buildTypes", projectId);
-
+ if (buildWrapper == null || buildWrapper.BuildType == null) return new List<BuildConfig>();
return buildWrapper.BuildType;
}
public List<BuildConfig> BuildConfigsByProjectName(string projectName)
{
var buildWrapper = _caller.GetFormat<BuildTypeWrapper>("/app/rest/projects/name:{0}/buildTypes", projectName);
-
+ if (buildWrapper == null || buildWrapper.BuildType == null) return new List<BuildConfig>();
return buildWrapper.BuildType;
}
@@ -227,6 +227,112 @@ public List<Build> BuildsByBuildLocator(BuildLocator locator)
return new List<Build>();
}
+ public Project CreateProject(string projectName)
+ {
+ return _caller.Post<Project>(projectName, "/app/rest/projects/");
+ }
+
+ public void DeleteProject(string projectName)
+ {
+ _caller.DeleteFormat("/app/rest/projects/name:{0}", projectName);
+ }
+
+ public BuildConfig CreateConfiguration(string projectName, string configurationName)
+ {
+ return _caller.PostFormat<BuildConfig>(configurationName, "/app/rest/projects/name:{0}/buildTypes", projectName);
+ }
+
+ public void SetConfigurationSetting(BuildTypeLocator locator, string settingName, string settingValue)
+ {
+ _caller.PutFormat(settingValue, "/app/rest/buildTypes/{0}/settings/{1}", locator, settingName);
+ }
+
+ public VcsRoot AttachVcsRoot(BuildTypeLocator locator, VcsRoot vcsRoot)
+ {
+ string xml = string.Format(@"<vcs-root-entry><vcs-root id=""{0}""/></vcs-root-entry>", vcsRoot.Id);
+ return _caller.PostFormat<VcsRoot>(xml, "/app/rest/buildTypes/{0}/vcs-root-entries", locator);
+ }
+
+ public void SetVcsRootField(VcsRoot vcsRoot, VcsRootField field, object value)
+ {
+ _caller.PutFormat(value, "/app/rest/vcs-roots/id:{0}/{1}", vcsRoot.Id, ToCamelCase(field.ToString()));
+ }
+
+ public void PostRawArtifactDependency(BuildTypeLocator locator, string rawXml)
+ {
+ _caller.PostFormat<ArtifactDependency>(rawXml, "/app/rest/buildTypes/{0}/artifact-dependencies", locator);
+ }
+
+ public void PostRawBuildStep(BuildTypeLocator locator, string rawXml)
+ {
+ _caller.PostFormat<BuildConfig>(rawXml, "/app/rest/buildTypes/{0}/steps", locator);
+ }
+
+ public void PostRawBuildTrigger(BuildTypeLocator locator, string rawXml)
+ {
+ _caller.PostFormat(rawXml, "/app/rest/buildTypes/{0}/triggers", locator);
+ }
+
+ public void SetProjectParameter(string projectName, string settingName, string settingValue)
+ {
+ _caller.PutFormat(settingValue, "/app/rest/projects/name:{0}/parameters/{1}", projectName, settingName);
+ }
+
+ public void SetConfigurationParameter(BuildTypeLocator locator, string key, string value)
+ {
+ _caller.PutFormat(value, "/app/rest/buildTypes/{0}/parameters/{1}", locator, key);
+ }
+
+ public void DeleteConfiguration(BuildTypeLocator locator)
+ {
+ _caller.DeleteFormat("/app/rest/buildTypes/{0}", locator);
+ }
+
+ public void PostRawAgentRequirement(BuildTypeLocator locator, string rawXml)
+ {
+ _caller.PostFormat(rawXml, "/app/rest/buildTypes/{0}/agent-requirements", locator);
+ }
+
+ public void DetachVcsRoot(BuildTypeLocator locator, string vcsRootId)
+ {
+ _caller.DeleteFormat("/app/rest/buildTypes/{0}/vcs-root-entries/{1}", locator, vcsRootId);
+ }
+
+ public void DeleteBuildStep(BuildTypeLocator locator, string buildStepId)
+ {
+ _caller.DeleteFormat("/app/rest/buildTypes/{0}/steps/{1}", locator, buildStepId);
+ }
+
+ public void DeleteArtifactDependency(BuildTypeLocator locator, string artifactDependencyId)
+ {
+ _caller.DeleteFormat("/app/rest/buildTypes/{0}/artifact-dependencies/{1}", locator, artifactDependencyId);
+ }
+
+ public void DeleteAgentRequirement(BuildTypeLocator locator, string agentRequirementId)
+ {
+ _caller.DeleteFormat("/app/rest/buildTypes/{0}/agent-requirements/{1}", locator, agentRequirementId);
+ }
+
+ public void DeleteParameter(BuildTypeLocator locator, string parameterName)
+ {
+ _caller.DeleteFormat("/app/rest/buildTypes/{0}/parameters/{1}", locator, parameterName);
+ }
+
+ public void DeleteProjectParameter(string projectName, string parameterName)
+ {
+ _caller.DeleteFormat("/app/rest/projects/name:{0}/parameters/{1}", projectName, parameterName);
+ }
+
+ public void DeleteBuildTrigger(BuildTypeLocator locator, string buildTriggerId)
+ {
+ _caller.DeleteFormat("/app/rest/buildTypes/{0}/triggers/{1}", locator, buildTriggerId);
+ }
+
+ private string ToCamelCase(string s)
+ {
+ return Char.ToLower(s.ToCharArray()[0]) + s.Substring(1);
+ }
+
public Build LastBuildByAgent(string agentName)
{
return BuildsByBuildLocator(BuildLocator.WithDimensions(
View
24 src/TeamCitySharp/TeamCitySharp.csproj
@@ -49,6 +49,20 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="DomainEntities\AgentRequirement.cs" />
+ <Compile Include="DomainEntities\AgentRequirements.cs" />
+ <Compile Include="DomainEntities\ArtifactDependencies.cs" />
+ <Compile Include="DomainEntities\ArtifactDependency.cs" />
+ <Compile Include="DomainEntities\BuildStep.cs" />
+ <Compile Include="DomainEntities\BuildSteps.cs" />
+ <Compile Include="DomainEntities\BuildTrigger.cs" />
+ <Compile Include="DomainEntities\BuildTriggers.cs" />
+ <Compile Include="DomainEntities\Parameters.cs" />
+ <Compile Include="DomainEntities\Properties.cs" />
+ <Compile Include="DomainEntities\Property.cs" />
+ <Compile Include="DomainEntities\VcsRootEntries.cs" />
+ <Compile Include="DomainEntities\VcsRootEntry.cs" />
+ <Compile Include="DomainEntities\VcsRootField.cs" />
<Compile Include="Locators\BuildLocator.cs" />
<Compile Include="Locators\BuildTypeLocator.cs" />
<Compile Include="Connection\IClientConnection.cs" />
@@ -89,10 +103,10 @@
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
- <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
- Other similar extension points exist, see Microsoft.Common.targets.
-
- <Target Name="AfterBuild">
- </Target>
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+
+ <Target Name="AfterBuild">
+ </Target>
-->
</Project>

No commit comments for this range

Something went wrong with that request. Please try again.