Skip to content

Commit bc76c3e

Browse files
Vadim Hatsuraarturcic
Vadim Hatsura
authored andcommitted
add support for drone
1 parent 6b3abd2 commit bc76c3e

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
namespace GitVersionCore.Tests.BuildServers
2+
{
3+
using System;
4+
using GitVersion;
5+
using NUnit.Framework;
6+
using Shouldly;
7+
8+
[TestFixture]
9+
public class DroneTests : TestBase
10+
{
11+
[Test]
12+
public void CanApplyToCurrentContext_ShouldBeTrue_WhenEnvironmentVariableIsSet()
13+
{
14+
// Arrange
15+
Environment.SetEnvironmentVariable("DRONE", "true");
16+
var buildServer = new Drone();
17+
18+
// Act
19+
var result = buildServer.CanApplyToCurrentContext();
20+
21+
// Assert
22+
result.ShouldBeTrue();
23+
}
24+
25+
[Test]
26+
public void CanApplyToCurrentContext_ShouldBeFalse_WhenEnvironmentVariableIsNotSet()
27+
{
28+
// Arrange
29+
Environment.SetEnvironmentVariable("DRONE", "");
30+
var buildServer = new Drone();
31+
32+
// Act
33+
var result = buildServer.CanApplyToCurrentContext();
34+
35+
// Assert
36+
result.ShouldBeFalse();
37+
}
38+
}
39+
}

src/GitVersionCore/BuildServers/BuildServerList.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace GitVersion
1+
namespace GitVersion
22
{
33
using System;
44
using System.Collections.Generic;
@@ -16,6 +16,7 @@ public static class BuildServerList
1616
new VsoAgent(),
1717
new TravisCI(),
1818
new EnvRun(),
19+
new Drone()
1920
};
2021

2122
public static IEnumerable<IBuildServer> GetApplicableBuildServers()
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
namespace GitVersion
2+
{
3+
using System;
4+
5+
public class Drone : BuildServerBase
6+
{
7+
public override bool CanApplyToCurrentContext()
8+
{
9+
return Environment.GetEnvironmentVariable("DRONE")?.Equals("true", StringComparison.OrdinalIgnoreCase) ?? false;
10+
}
11+
12+
public override string GenerateSetVersionMessage(VersionVariables variables)
13+
{
14+
return variables.FullSemVer;
15+
}
16+
17+
public override string[] GenerateSetParameterMessage(string name, string value)
18+
{
19+
return new[]
20+
{
21+
$"GitVersion_{name}={value}"
22+
};
23+
}
24+
25+
public override string GetCurrentBranch(bool usingDynamicRepos)
26+
{
27+
return Environment.GetEnvironmentVariable("DRONE_BRANCH");
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)