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

Simple fix for Create project in TC 8.x #63

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/repositories.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
<repositories>
<repository path="..\src\Samples\TeamCitySharp.BuildMonitor\packages.config" />
<repository path="..\src\TeamCitySharp\packages.config" />
<repository path="..\src\Tests\IntegrationTests\packages.config" />
<repository path="..\src\Tests\UnitTests\packages.config" />
</repositories>
20 changes: 18 additions & 2 deletions src/TeamCitySharp/ActionTypes/Agents.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.IO;
using TeamCitySharp.Connection;
using TeamCitySharp.DomainEntities;

Expand All @@ -13,11 +14,26 @@ internal Agents(TeamCityCaller caller)
_caller = caller;
}

public List<Agent> All()
public List<Agent> All(bool includeDisconnected = true, bool includeUnauthorized = true)
{
var agentWrapper = _caller.Get<AgentWrapper>("/app/rest/agents");
var url = string.Format("/app/rest/agents?includeDisconnected={0}&includeUnauthorized={1}",
includeDisconnected.ToString().ToLower(), includeUnauthorized.ToString().ToLower());

var agentWrapper = _caller.Get<AgentWrapper>(url);

return agentWrapper.Agent;
}

private string AddqueryString(string url, string queryString)
{
if (url.Contains("?"))
url += "&";
else
url += "?";

url += queryString;

return url;
}
}
}
18 changes: 18 additions & 0 deletions src/TeamCitySharp/ActionTypes/BuildConfigs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,24 @@ public void PostRawBuildTrigger(BuildTypeLocator locator, string rawXml)
_caller.PostFormat(rawXml, HttpContentTypes.ApplicationXml, "/app/rest/buildTypes/{0}/triggers", locator);
}

public void SetArtifactDependency(BuildTypeLocator locator, ArtifactDependency dependency)
{
_caller.PostFormat<ArtifactDependency>(dependency, HttpContentTypes.ApplicationJson,
HttpContentTypes.ApplicationJson, "/app/rest/buildTypes/{0}/artifact-dependencies", locator);
}

public void SetSnapshotDependency(BuildTypeLocator locator, SnapshotDependency dependency)
{
_caller.PostFormat<SnapshotDependency>(dependency, HttpContentTypes.ApplicationJson,
HttpContentTypes.ApplicationJson, "/app/rest/buildTypes/{0}/snapshot-dependencies", locator);
}

public void SetTrigger(BuildTypeLocator locator, BuildTrigger trigger)
{
_caller.PostFormat<BuildTrigger>(trigger, HttpContentTypes.ApplicationJson, HttpContentTypes.ApplicationJson,
"/app/rest/buildTypes/{0}/triggers", locator);
}

public void SetConfigurationParameter(BuildTypeLocator locator, string key, string value)
{
_caller.PutFormat(value, HttpContentTypes.TextPlain, "/app/rest/buildTypes/{0}/parameters/{1}", locator, key);
Expand Down
7 changes: 7 additions & 0 deletions src/TeamCitySharp/ActionTypes/Builds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ public Build LastErrorBuildByBuildConfigId(string buildConfigId)
return builds != null ? builds.FirstOrDefault() : new Build();
}

public Build ById(string id)
{
var build = _caller.GetFormat<Build>("/app/rest/builds/id:{0}", id);

return build ?? new Build();
}

public List<Build> ByBuildConfigId(string buildConfigId)
{
return ByBuildLocator(BuildLocator.WithDimensions(BuildTypeLocator.WithId(buildConfigId)
Expand Down
2 changes: 1 addition & 1 deletion src/TeamCitySharp/ActionTypes/IAgents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ namespace TeamCitySharp.ActionTypes
{
public interface IAgents
{
List<Agent> All();
List<Agent> All(bool includeDisconnected = false, bool includeUnauthorized = false);
}
}
7 changes: 7 additions & 0 deletions src/TeamCitySharp/ActionTypes/IBuildConfigs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@ public interface IBuildConfigs
void SetConfigurationSetting(BuildTypeLocator locator, string settingName, string settingValue);
bool GetConfigurationPauseStatus(BuildTypeLocator locator);
void SetConfigurationPauseStatus(BuildTypeLocator locator, bool isPaused);

void PostRawArtifactDependency(BuildTypeLocator locator, string rawXml);
void SetArtifactDependency(BuildTypeLocator locator, ArtifactDependency dependency);

void PostRawBuildStep(BuildTypeLocator locator, string rawXml);

void PostRawBuildTrigger(BuildTypeLocator locator, string rawXml);
void SetTrigger(BuildTypeLocator locator, BuildTrigger trigger);

void SetConfigurationParameter(BuildTypeLocator locator, string key, string value);
void PostRawAgentRequirement(BuildTypeLocator locator, string rawXml);
void DeleteBuildStep(BuildTypeLocator locator, string buildStepId);
Expand Down Expand Up @@ -62,6 +68,7 @@ public interface IBuildConfigs
/// ]]></code>
/// </summary>
void PostRawSnapshotDependency(BuildTypeLocator locator, XmlElement rawXml);
void SetSnapshotDependency(BuildTypeLocator locator, SnapshotDependency dependency);

/// <summary>
/// <para>Locates a build type by its locator.</para>
Expand Down
1 change: 1 addition & 0 deletions src/TeamCitySharp/ActionTypes/IBuilds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public interface IBuilds
Build LastBuildByBuildConfigId(string buildConfigId);
List<Build> ErrorBuildsByBuildConfigId(string buildConfigId);
Build LastErrorBuildByBuildConfigId(string buildConfigId);
Build ById(string id);
List<Build> ByBuildConfigId(string buildConfigId);
List<Build> ByConfigIdAndTag(string buildConfigId, string tag);
List<Build> ByUserName(string userName);
Expand Down
23 changes: 22 additions & 1 deletion src/TeamCitySharp/ActionTypes/Projects.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System.Collections.Generic;
using System.Text.RegularExpressions;
using EasyHttp.Http;
using TeamCitySharp.Connection;
using TeamCitySharp.DomainEntities;
using TeamCitySharp.Locators;

namespace TeamCitySharp.ActionTypes
{
Expand Down Expand Up @@ -42,7 +44,20 @@ public Project Details(Project project)

public Project Create(string projectName)
{
return _caller.Post<Project>(projectName, HttpContentTypes.ApplicationXml, "/app/rest/projects/", string.Empty);
return Create(projectName, "_Root");
}

public Project Create(string projectName, string rootProjectId)
{
var project = new NewProjectDescription
{
Name = projectName,
Id = GenerateId(projectName),
ParentProject = new ParentProjectWrapper(ProjectLocator.WithId(rootProjectId))
};

return _caller.Post<Project>(project, HttpContentTypes.ApplicationJson, "/app/rest/projects/",
HttpContentTypes.ApplicationJson);
}

public void Delete(string projectName)
Expand All @@ -59,5 +74,11 @@ public void SetProjectParameter(string projectName, string settingName, string s
{
_caller.PutFormat(settingValue, "/app/rest/projects/name:{0}/parameters/{1}", projectName, settingName);
}

public string GenerateId(string projectName)
{
projectName = Regex.Replace(projectName, @"[^\p{L}\p{N}]+", "");
return projectName;
}
}
}
2 changes: 1 addition & 1 deletion src/TeamCitySharp/Connection/ITeamCityCaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal interface ITeamCityCaller

void Get(string urlPart);

T Post<T>(string data, string contenttype, string urlPart, string accept);
T Post<T>(object data, string contenttype, string urlPart, string accept);

bool Authenticate(string urlPart);

Expand Down
8 changes: 4 additions & 4 deletions src/TeamCitySharp/Connection/TeamCityCaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ public void GetFormat(string urlPart, params object[] parts)

public T PostFormat<T>(object data, string contenttype, string accept, string urlPart, params object[] parts)
{
return Post<T>(data.ToString(), contenttype, string.Format(urlPart, parts), accept);
return Post<T>(data, contenttype, string.Format(urlPart, parts), accept);
}

public void PostFormat(object data, string contenttype, string urlPart, params object[] parts)
{
Post(data.ToString(), contenttype, string.Format(urlPart, parts), string.Empty);
Post(data, contenttype, string.Format(urlPart, parts), string.Empty);
}

public void PutFormat(object data, string contenttype, string urlPart, params object[] parts)
{
Put(data.ToString(), contenttype, string.Format(urlPart, parts), string.Empty);
Put(data, contenttype, string.Format(urlPart, parts), string.Empty);
}

public void DeleteFormat(string urlPart, params object[] parts)
Expand Down Expand Up @@ -143,7 +143,7 @@ private HttpResponse GetResponse(string urlPart)
return response;
}

public T Post<T>(string data, string contenttype, string urlPart, string accept)
public T Post<T>(object data, string contenttype, string urlPart, string accept)
{
return Post(data, contenttype, urlPart, accept).StaticBody<T>();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
using System.Collections.Generic;
using System.IO;
using EasyHttp.Codecs;
using EasyHttp.Codecs.JsonFXExtensions;
using EasyHttp.Configuration;
using JsonFx.IO;
using JsonFx.Json;
using JsonFx.Model;
using JsonFx.Serialization;
using JsonFx.Serialization.Filters;

namespace TeamCitySharp.Connection
{
public class TeamcityJsonEncoderDecoderConfiguration : IEncoderDecoderConfiguration
{
public IEncoder GetEncoder()
{
var jsonWriter = new JsonWriter(new DataWriterSettings(DefaultEncoderDecoderConfiguration.CombinedResolverStrategy()
var jsonWriter = new CamelCaseJsonWriter(new DataWriterSettings(DefaultEncoderDecoderConfiguration.CombinedResolverStrategy()
, new TeamCityDateFilter()), new[] { "application/.*json", "text/.*json" });

var writers = new List<IDataWriter> { jsonWriter };
Expand All @@ -29,4 +33,39 @@ public IDecoder GetDecoder()
return new DefaultDecoder(dataReaderProvider);
}
}

public class CamelCaseJsonWriter : JsonWriter
{
public CamelCaseJsonWriter(DataWriterSettings settings, params string[] contentTypes)
: base(settings, contentTypes)
{}

protected override ITextFormatter<ModelTokenType> GetFormatter()
{
return new CamelCaseJsonFormatter(this.Settings);
}
}

public class CamelCaseJsonFormatter : JsonWriter.JsonFormatter
{
public CamelCaseJsonFormatter(DataWriterSettings settings)
: base(settings)
{}

protected override void WritePropertyName(TextWriter writer, string propertyName)
{
base.WritePropertyName(writer, CamelCase(propertyName));
}

private static string CamelCase(string input)
{
if (string.IsNullOrEmpty(input))
return input;

var chars = input.ToCharArray();
chars[0] = chars[0].ToString().ToLower().ToCharArray()[0];

return new string(chars);
}
}
}
30 changes: 28 additions & 2 deletions src/TeamCitySharp/DomainEntities/ArtifactDependency.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,40 @@
using JsonFx.Json;

namespace TeamCitySharp.DomainEntities
{
public class ArtifactDependency
{
public ArtifactDependency()
{
Properties = new Properties();
Type = "artifact_dependency";
}
public override string ToString()
{
return "artifact_dependency";
return Type;
}

public string Id { get; set; }
public string Type { get; set; }
public Properties Properties { get; set; }
[JsonName("source-buildType")]
public SourceBuildType SourceBuildType { get; set; }
public string Type { get; set; }

public static ArtifactDependency Default(string dependsOnbuildId)
{
var dependency = new ArtifactDependency();

dependency.Properties.Add("cleanDestinationDirectory", "true");
dependency.Properties.Add("pathRules", "* => Temp");
dependency.Properties.Add("revisionName", "sameChainOrLastFinished");
dependency.Properties.Add("revisionValue", "latest.sameChainOrLastFinished");

dependency.SourceBuildType = new SourceBuildType
{
Id = dependsOnbuildId
};

return dependency;
}
}
}
18 changes: 18 additions & 0 deletions src/TeamCitySharp/DomainEntities/BuildTrigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ namespace TeamCitySharp.DomainEntities
{
public class BuildTrigger
{
public BuildTrigger()
{
Properties = new Properties();
}

public override string ToString()
{
return "trigger";
Expand All @@ -10,5 +15,18 @@ public override string ToString()
public string Id { get; set; }
public string Type { get; set; }
public Properties Properties { get; set; }

public static BuildTrigger FinishBuildTrigger(string dependsOnbuildId)
{
var trigger = new BuildTrigger
{
Type = "buildDependencyTrigger"
};

trigger.Properties.Add("afterSuccessfulBuildOnly", "true");
trigger.Properties.Add("dependsOn", dependsOnbuildId);

return trigger;
}
}
}
16 changes: 16 additions & 0 deletions src/TeamCitySharp/DomainEntities/NewProjectDescription.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using JsonFx.Json;
using TeamCitySharp.Locators;

namespace TeamCitySharp.DomainEntities
{
public class NewProjectDescription
{
public string Name { get; set; }
public string Id { get; set; }
public ParentProjectWrapper ParentProject { get; set; }
}
}
20 changes: 20 additions & 0 deletions src/TeamCitySharp/DomainEntities/ParentProjectWrapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TeamCitySharp.Locators;

namespace TeamCitySharp.DomainEntities
{
public class ParentProjectWrapper
{
private readonly ProjectLocator _locator;

public ParentProjectWrapper(ProjectLocator locator)
{
_locator = locator;
}

public string Locator { get { return _locator.ToString(); } }
}
}
Loading