diff --git a/src/GitVersionCore.Tests/BuildServers/DroneTests.cs b/src/GitVersionCore.Tests/BuildServers/DroneTests.cs new file mode 100644 index 0000000000..66d047b769 --- /dev/null +++ b/src/GitVersionCore.Tests/BuildServers/DroneTests.cs @@ -0,0 +1,50 @@ +namespace GitVersionCore.Tests.BuildServers +{ + using System; + using GitVersion; + using NUnit.Framework; + using Shouldly; + + [TestFixture] + public class DroneTests : TestBase + { + [SetUp] + public void SetUp() + { + Environment.SetEnvironmentVariable("DRONE", "true"); + } + + [TearDown] + public void TearDown() + { + Environment.SetEnvironmentVariable("DRONE", null); + } + + [Test] + public void CanApplyToCurrentContext_ShouldBeTrue_WhenEnvironmentVariableIsSet() + { + // Arrange + var buildServer = new Drone(); + + // Act + var result = buildServer.CanApplyToCurrentContext(); + + // Assert + result.ShouldBeTrue(); + } + + [Test] + public void CanApplyToCurrentContext_ShouldBeFalse_WhenEnvironmentVariableIsNotSet() + { + // Arrange + Environment.SetEnvironmentVariable("DRONE", ""); + var buildServer = new Drone(); + + // Act + var result = buildServer.CanApplyToCurrentContext(); + + // Assert + result.ShouldBeFalse(); + } + } +} diff --git a/src/GitVersionCore/BuildServers/BuildServerList.cs b/src/GitVersionCore/BuildServers/BuildServerList.cs index 98aba5429b..cde10874c0 100644 --- a/src/GitVersionCore/BuildServers/BuildServerList.cs +++ b/src/GitVersionCore/BuildServers/BuildServerList.cs @@ -1,4 +1,4 @@ -namespace GitVersion +namespace GitVersion { using System; using System.Collections.Generic; @@ -16,6 +16,7 @@ public static class BuildServerList new VsoAgent(), new TravisCI(), new EnvRun(), + new Drone() }; public static IEnumerable GetApplicableBuildServers() diff --git a/src/GitVersionCore/BuildServers/Drone.cs b/src/GitVersionCore/BuildServers/Drone.cs new file mode 100644 index 0000000000..193478fb91 --- /dev/null +++ b/src/GitVersionCore/BuildServers/Drone.cs @@ -0,0 +1,30 @@ +namespace GitVersion +{ + using System; + + public class Drone : BuildServerBase + { + public override bool CanApplyToCurrentContext() + { + return Environment.GetEnvironmentVariable("DRONE")?.Equals("true", StringComparison.OrdinalIgnoreCase) ?? false; + } + + public override string GenerateSetVersionMessage(VersionVariables variables) + { + return variables.FullSemVer; + } + + public override string[] GenerateSetParameterMessage(string name, string value) + { + return new[] + { + $"GitVersion_{name}={value}" + }; + } + + public override string GetCurrentBranch(bool usingDynamicRepos) + { + return Environment.GetEnvironmentVariable("DRONE_BRANCH"); + } + } +}