From d7295b11a774b263900ba6d59d47a984698fbe5f Mon Sep 17 00:00:00 2001 From: Boris Modylevsky Date: Fri, 21 Apr 2017 12:53:38 +0300 Subject: [PATCH 1/6] Update README.md --- README.md | 91 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 65 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 74ce703..27cb5c4 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,10 @@ -[![build status](http://teamcity.codebetter.com/app/rest/builds/buildType:id:FluentTc/statusIcon)](http://teamcity.codebetter.com/viewType.html?buildTypeId=FluentTc&guest=1) [![code coverage](https://img.shields.io/teamcity/coverage/FluentTc.svg)](http://teamcity.codebetter.com/viewType.html?buildTypeId=FluentTc&guest=1) [![NuGet version](https://badge.fury.io/nu/FluentTc.svg)](https://badge.fury.io/nu/FluentTc) [![Chat on gitter](https://img.shields.io/gitter/room/QualiSystems/FluentTc.svg)](https://gitter.im/QualiSystems/FluentTc) [![Stories in Ready](https://badge.waffle.io/QualiSystems/FluentTc.png?label=ready&title=Ready)](https://waffle.io/QualiSystems/FluentTc) +[![build status](http://teamcity.codebetter.com/app/rest/builds/buildType:id:FluentTc/statusIcon)](http://teamcity.codebetter.com/viewType.html?buildTypeId=FluentTc&guest=1) [![code coverage](https://img.shields.io/teamcity/coverage/FluentTc.svg)](http://teamcity.codebetter.com/viewType.html?buildTypeId=FluentTc&guest=1) [![NuGet version](https://badge.fury.io/nu/FluentTc.svg)](https://badge.fury.io/nu/FluentTc) [![Stories in Ready](https://badge.waffle.io/QualiSystems/FluentTc.png?label=ready&title=Ready)](https://waffle.io/QualiSystems/FluentTc) # FluentTc -Easy-to-use, readable and comprehensive library for consuming TeamCity REST API. Written using real scenarios in mind, enables variuos range of queries and operation on TeamCity - -# Getting started - -Install __FluentTc__ nuget package from from Manage Nuget packages - -Or from Nuget Package Manager Console: -```PS -install-package FluentTc -``` - -# Example - -Connects to TeamCity using guest account and retrieves builds from the [FluentTc](http://teamcity.codebetter.com/viewType.html?buildTypeId=FluentTc_FluentTcDevelop) build configuration with all its branches, -with additional build properties, such as StatusText, StartDate and FinishDate; with paging taking 10 builds starting from the 30th build. +Integrate with TeamCity fluently +# Getting Started +Get TeamCity builds with branches, status, start and finish date and paging ```C# IList builds = new RemoteTc().Connect(h => h.ToHost("teamcity.codebetter.com").AsGuest()) @@ -28,22 +16,73 @@ IList builds = p => p.Start(30).Count(10)); ``` -For more examples and documentation read the [Wiki](https://github.com/QualiSystems/FluentTc/wiki) +Run custom build +```C# +IBuild build = new RemoteTc().Connect(h => h.ToHost("teamcity.codebetter.com").AsGuest()) + .RunBuildConfiguration( + buildConfiguration => buildConfiguration.Id("bt2"), + agent => agent.Name("Agent1"), + parameters => parameters + .Parameter("param1", "value1") + .Parameter("param2", "value2"), + custom => custom.OnBranch("develop") + .WithComment("personal build on develop") + .AsPersonal() + .QueueAtTop() + .RebuildAllDependencies() + .WithCleanSources(). + OnChange(change => change.Id(123456))); +``` + +Interact with TeamCity from within a build step without authentication +```C# +ILocalTc localTc = new LocalTc(); + +// Gets the current checkout directory +string agentWorkDir = localTc.TeamcityBuildCheckoutDir; + +// Gets the current parameter value +int param1 = localTc.GetBuildParameter("param1"); + +// Sets parameter value of the current build +localTc.SetBuildParameter("parameter.name", "value1"); + +// Gets list of files changed in the current build +IList changedFiles = localTc.ChangedFiles; + +// Determines whether the build is personal +bool isPersonal = localTc.IsPersonal; + +// Change status of the current build +localTc.ChangeBuildStatus(BuildStatus.Success); +``` + +# Dive In + +* For more examples and documentation read the [Wiki](https://github.com/QualiSystems/FluentTc/wiki) + +* For questions and discussions chat on Gitter: [![Chat on gitter](https://img.shields.io/gitter/room/QualiSystems/FluentTc.svg)](https://gitter.im/QualiSystems/FluentTc) -## Contributors -This project would not be possible with the support of [contributors](CONTRIBUTORS.md) + +# Download + +The easiest way to get __FluentTc__ is through Nuget +Manage Nuget packages or from Nuget Package Manager Console: +```PS +PM> install-package FluentTc +``` + +# Get Involved +* For reporting bugs, create an issue on [Github issues](https://github.com/QualiSystems/FluentTc/issues) +* For contribution read ## Versioning FluentTc adheres to [Semantic Versioning 2.0.0](http://semver.org/), basically means that there are no breaking changes unless the version is 0.x or major version is promoted. -## Project State -The project is stable and works in production in a few organizations. It has a growing community of users and contributors. -Although we are happy with its current state, we'd like to hear what you think. We are asking to spend a few minutes and fill this survey: -[FluentTc survey](http://goo.gl/forms/42U7MvVFStoieQaB3) - ## License -[Apache License 2.0](https://github.com/QualiSystems/FluentTc/blob/master/LICENSE) +FluentTc is released under [Apache License 2.0](https://github.com/QualiSystems/FluentTc/blob/master/LICENSE) ## Credits -[![Continuous Integration powered by TeamCity and CodeBetter](https://resources.jetbrains.com/assets/banners/jetbrains-com/Codebetter.png)](http://codebetter.com/codebetter-ci/) +This project would not be possible with the support of [contributors](https://github.com/QualiSystems/FluentTc/graphs/contributors) + From 8854fd9cdb7ae64e1750481856c175568143e5dd Mon Sep 17 00:00:00 2001 From: Boris Modylevsky Date: Fri, 21 Apr 2017 12:55:49 +0300 Subject: [PATCH 2/6] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 27cb5c4..b469ae1 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ PM> install-package FluentTc # Get Involved * For reporting bugs, create an issue on [Github issues](https://github.com/QualiSystems/FluentTc/issues) -* For contribution read +* For contribution fork and submit change via Pull Request ## Versioning FluentTc adheres to [Semantic Versioning 2.0.0](http://semver.org/), basically means that there are no breaking changes unless the version is 0.x or major version is promoted. From 7d3e4e791cac9ae3211313958d44dc85e20b8075 Mon Sep 17 00:00:00 2001 From: Boris Modylevsky Date: Fri, 21 Apr 2017 13:43:40 +0300 Subject: [PATCH 3/6] Update README.md --- README.md | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index b469ae1..7322109 100644 --- a/README.md +++ b/README.md @@ -8,12 +8,19 @@ Get TeamCity builds with branches, status, start and finish date and paging ```C# IList builds = new RemoteTc().Connect(h => h.ToHost("teamcity.codebetter.com").AsGuest()) - .GetBuilds(b => - b.BuildConfiguration(c => - c.Id("FluentTc_FluentTcDevelop")) + .GetBuilds( + having => having + .BuildConfiguration( + buildConfiguration => buildConfiguration + .Id("FluentTc_FluentTcDevelop")) .Branch(r => r.Branched()), - i => i.IncludeStatusText().IncludeStartDate().IncludeFinishDate(), - p => p.Start(30).Count(10)); + include => include + .IncludeStatusText() + .IncludeStartDate() + .IncludeFinishDate(), + paging => paging + .Start(30) + .Count(10)); ``` Run custom build @@ -25,13 +32,13 @@ IBuild build = new RemoteTc().Connect(h => h.ToHost("teamcity.codebetter.com").A parameters => parameters .Parameter("param1", "value1") .Parameter("param2", "value2"), - custom => custom.OnBranch("develop") +         options => options.OnBranch("develop") .WithComment("personal build on develop") .AsPersonal() .QueueAtTop() .RebuildAllDependencies() - .WithCleanSources(). - OnChange(change => change.Id(123456))); + .WithCleanSources() + .OnChange(change => change.Id(123456))); ``` Interact with TeamCity from within a build step without authentication @@ -66,15 +73,14 @@ localTc.ChangeBuildStatus(BuildStatus.Success); # Download -The easiest way to get __FluentTc__ is through Nuget -Manage Nuget packages or from Nuget Package Manager Console: +The easiest way to get __FluentTc__ is through Nuget: Visual Studio -> Manage Nuget packages or from Nuget Package Manager Console: ```PS PM> install-package FluentTc ``` # Get Involved * For reporting bugs, create an issue on [Github issues](https://github.com/QualiSystems/FluentTc/issues) -* For contribution fork and submit change via Pull Request +* For contribution fork and submit a change via Pull Request ## Versioning FluentTc adheres to [Semantic Versioning 2.0.0](http://semver.org/), basically means that there are no breaking changes unless the version is 0.x or major version is promoted. @@ -83,6 +89,6 @@ FluentTc adheres to [Semantic Versioning 2.0.0](http://semver.org/), basically m FluentTc is released under [Apache License 2.0](https://github.com/QualiSystems/FluentTc/blob/master/LICENSE) ## Credits -This project would not be possible with the support of [contributors](https://github.com/QualiSystems/FluentTc/graphs/contributors) +FluentTc project keeps growing with the support of growing comminity of [contributors](https://github.com/QualiSystems/FluentTc/graphs/contributors) From 6c47b4dbeac1da71b57e95b182664f957c63d131 Mon Sep 17 00:00:00 2001 From: Boris Modylevsky Date: Fri, 21 Apr 2017 13:47:09 +0300 Subject: [PATCH 4/6] Update README.md --- README.md | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 7322109..7459be7 100644 --- a/README.md +++ b/README.md @@ -7,13 +7,16 @@ Integrate with TeamCity fluently Get TeamCity builds with branches, status, start and finish date and paging ```C# IList builds = - new RemoteTc().Connect(h => h.ToHost("teamcity.codebetter.com").AsGuest()) + new RemoteTc() + .Connect(connect => connect + .ToHost("teamcity.jetbrains.com") + .AsGuest()) .GetBuilds( having => having .BuildConfiguration( buildConfiguration => buildConfiguration - .Id("FluentTc_FluentTcDevelop")) - .Branch(r => r.Branched()), + .Id("FluentTc")) + .Branch(branch => branch.Branched()), include => include .IncludeStatusText() .IncludeStartDate() @@ -25,9 +28,12 @@ IList builds = Run custom build ```C# -IBuild build = new RemoteTc().Connect(h => h.ToHost("teamcity.codebetter.com").AsGuest()) +IBuild build = new RemoteTc() + .Connect(connect => connect + .ToHost("teamcity.jetbrains.com") + .AsGuest()) .RunBuildConfiguration( - buildConfiguration => buildConfiguration.Id("bt2"), + buildConfiguration => buildConfiguration.Id("FluentTc"), agent => agent.Name("Agent1"), parameters => parameters .Parameter("param1", "value1") From be1fc6f69e374e3a77fa738b5bf8a71631878d35 Mon Sep 17 00:00:00 2001 From: Boris Modylevsky Date: Tue, 25 Dec 2018 09:27:48 +0200 Subject: [PATCH 5/6] add PublishArtifact method in LocalTc --- FluentTc.Tests/LocalTcTests.cs | 34 +++++++++++++++++++++ FluentTc/LocalTc.cs | 56 ++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) diff --git a/FluentTc.Tests/LocalTcTests.cs b/FluentTc.Tests/LocalTcTests.cs index a170a94..289bbfc 100644 --- a/FluentTc.Tests/LocalTcTests.cs +++ b/FluentTc.Tests/LocalTcTests.cs @@ -183,5 +183,39 @@ public void IsPersonal_False_False() // Assert isPersonal.Should().BeFalse(); } + + [Test] + public void PublishArtifact_FileName_Published() + { + // Arrange + var teamCityWriterFactory = A.Fake(); + var teamCityWriter = A.Fake(); + A.CallTo(() => teamCityWriterFactory.CreateTeamCityWriter()).Returns(teamCityWriter); + + var localTc = new LocalTc(A.Fake(), teamCityWriterFactory); + + // Act + localTc.PublishArtifact("file.txt"); + + // Assert + A.CallTo(()=>teamCityWriter.PublishArtifact("file.txt")).MustHaveHappened(); + } + + [Test] + public void PublishArtifact_FileNameAndTarget_Published() + { + // Arrange + var teamCityWriterFactory = A.Fake(); + var teamCityWriter = A.Fake(); + A.CallTo(() => teamCityWriterFactory.CreateTeamCityWriter()).Returns(teamCityWriter); + + var localTc = new LocalTc(A.Fake(), teamCityWriterFactory); + + // Act + localTc.PublishArtifact("file.txt", "dir"); + + // Assert + A.CallTo(()=>teamCityWriter.PublishArtifact("file.txt => dir")).MustHaveHappened(); + } } } \ No newline at end of file diff --git a/FluentTc/LocalTc.cs b/FluentTc/LocalTc.cs index 394c8dc..db41274 100644 --- a/FluentTc/LocalTc.cs +++ b/FluentTc/LocalTc.cs @@ -31,6 +31,31 @@ public interface ILocalTc bool IsTeamCityMode { get; } bool IsPersonal { get; } void SetBuildParameter(string parameterName, string parameterValue); + + /// + /// Attaches new artifact publishing rules as described in + /// http://confluence.jetbrains.net/display/TCD7/Build+Artifact + /// + /// + /// Filename to publish. The file name should be relative to the build checkout directory. + /// Directory name to publish all the files and subdirectories within the directory specified. The directory name should be a path relative to the build checkout directory. The files will be published preserving the directories structure under the directory specified (the directory itself will not be included). + /// + void PublishArtifact(string fileDirectoryName); + + /// + /// Attaches new artifact publishing rules as described in + /// http://confluence.jetbrains.net/display/TCD7/Build+Artifact + /// + /// + /// Filename to publish. The file name should be relative to the build checkout directory. + /// Directory name to publish all the files and subdirectories within the directory specified. The directory name should be a path relative to the build checkout directory. The files will be published preserving the directories structure under the directory specified (the directory itself will not be included). + /// + /// + /// Target directory - the directory in the resulting build's artifacts that will contain the files determined by the left part of the pattern. + /// Target archive - the path to the archive to be created by TeamCity by packing build artifacts. + /// TeamCity treats as archive whenever it ends with a supported archive extension, i.e. .zip, .jar, .tar.gz, or .tgz. + /// + void PublishArtifact(string fileDirectoryName, string targetDirectoryArchive); } public class LocalTc : ILocalTc @@ -173,5 +198,36 @@ public bool IsPersonal { get { return m_BuildParameters.IsPersonal; } } + + /// + /// Attaches new artifact publishing rules as described in + /// http://confluence.jetbrains.net/display/TCD7/Build+Artifact + /// + /// + /// Filename to publish. The file name should be relative to the build checkout directory. + /// Directory name to publish all the files and subdirectories within the directory specified. The directory name should be a path relative to the build checkout directory. The files will be published preserving the directories structure under the directory specified (the directory itself will not be included). + /// + public void PublishArtifact(string fileDirectoryName) + { + m_TeamCityWriter.PublishArtifact(fileDirectoryName); + } + + /// + /// Attaches new artifact publishing rules as described in + /// http://confluence.jetbrains.net/display/TCD7/Build+Artifact + /// + /// + /// Filename to publish. The file name should be relative to the build checkout directory. + /// Directory name to publish all the files and subdirectories within the directory specified. The directory name should be a path relative to the build checkout directory. The files will be published preserving the directories structure under the directory specified (the directory itself will not be included). + /// + /// + /// Target directory - the directory in the resulting build's artifacts that will contain the files determined by the left part of the pattern. + /// Target archive - the path to the archive to be created by TeamCity by packing build artifacts. + /// TeamCity treats as archive whenever it ends with a supported archive extension, i.e. .zip, .jar, .tar.gz, or .tgz. + /// + public void PublishArtifact(string fileDirectoryName, string targetDirectoryArchive) + { + m_TeamCityWriter.PublishArtifact($"{fileDirectoryName} => {targetDirectoryArchive}"); + } } } \ No newline at end of file From 8331221f5c9966c583e4cbe93ea32bfcc41d8037 Mon Sep 17 00:00:00 2001 From: Boris Modylevsky Date: Tue, 25 Dec 2018 10:23:47 +0200 Subject: [PATCH 6/6] do not use string interpolation --- FluentTc/LocalTc.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/FluentTc/LocalTc.cs b/FluentTc/LocalTc.cs index db41274..d72ec2d 100644 --- a/FluentTc/LocalTc.cs +++ b/FluentTc/LocalTc.cs @@ -227,7 +227,8 @@ public void PublishArtifact(string fileDirectoryName) /// public void PublishArtifact(string fileDirectoryName, string targetDirectoryArchive) { - m_TeamCityWriter.PublishArtifact($"{fileDirectoryName} => {targetDirectoryArchive}"); + // ReSharper disable once UseStringInterpolation + m_TeamCityWriter.PublishArtifact(string.Format("{0} => {1}", fileDirectoryName, targetDirectoryArchive)); } } } \ No newline at end of file