-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
179 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace csmacnz.Coveralls.Data | ||
{ | ||
public class CommitSha | ||
{ | ||
private readonly string _value; | ||
|
||
public CommitSha(string value) | ||
{ | ||
_value = value; | ||
} | ||
|
||
public string Value => _value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
using csmacnz.Coveralls.Data; | ||
using Beefeater; | ||
using csmacnz.Coveralls.Data; | ||
|
||
namespace csmacnz.Coveralls.GitDataResolvers | ||
{ | ||
public interface IGitDataResolver | ||
{ | ||
bool CanProvideData(); | ||
|
||
GitData GenerateData(); | ||
Either<GitData, CommitSha> GenerateData(); | ||
|
||
string DisplayName { get; } | ||
} | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
src/csmacnz.Coveralls/GitDataResolvers/TeamCityGitDataResolver.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using BCLExtensions; | ||
using Beefeater; | ||
using csmacnz.Coveralls.Data; | ||
using csmacnz.Coveralls.Ports; | ||
|
||
namespace csmacnz.Coveralls.GitDataResolvers | ||
{ | ||
public class TeamCityGitDataResolver : IGitDataResolver | ||
{ | ||
private readonly IEnvironmentVariables _variables; | ||
private readonly IConsole _console; | ||
|
||
public TeamCityGitDataResolver(IEnvironmentVariables variables, IConsole console) | ||
{ | ||
_variables = variables; | ||
_console = console; | ||
} | ||
|
||
public string DisplayName => "Teamcity Environment Variables"; | ||
|
||
public bool CanProvideData() | ||
{ | ||
return _variables.GetBooleanVariable("TEAMCITY_VERSION"); | ||
} | ||
|
||
public Either<GitData, CommitSha> GenerateData() | ||
{ | ||
var customVariablesSha = _variables.GetEnvironmentVariable("TEAMCITY_BUILD_COMMIT"); | ||
|
||
if (customVariablesSha.IsNotNullOrWhitespace()) | ||
{ | ||
var generateData = new GitData | ||
{ | ||
Head = new GitHead | ||
{ | ||
Id = customVariablesSha, | ||
}, | ||
Branch = _variables.GetEnvironmentVariable("TEAMCITY_BUILD_BRANCH") ?? string.Empty | ||
}; | ||
|
||
return generateData; | ||
} | ||
else | ||
{ | ||
_console.WriteLine("Teamcity does not automatically make build parameters available as environment variables."); | ||
_console.WriteLine("Add the following environment parameters to the build configuration"); | ||
_console.WriteLine("env.TEAMCITY_BUILD_BRANCH = %teamcity.build.vcs.branch.<YOUR TEAMCITY VCS NAME>%"); | ||
_console.WriteLine("env.TEAMCITY_BUILD_COMMIT = %build.vcs.number%"); | ||
_console.WriteLine("env.TEAMCITY_BUILD_NUMBER = %build.counter%"); | ||
_console.WriteLine("env.TEAMCITY_PULL_REQUEST = %teamcity.build.branch%"); | ||
var noCustomVariablesSha = _variables.GetEnvironmentVariable("BUILD_VCS_NUMBER"); | ||
if (noCustomVariablesSha.IsNotNullOrWhitespace()) | ||
{ | ||
_console.WriteLine("Using env.BUILD_VCS_NUMBER to submit commit sha only"); | ||
return new CommitSha(noCustomVariablesSha); | ||
} | ||
else | ||
{ | ||
return Either<GitData, CommitSha>.OfResult1(null); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/csmacnz.Coveralls/MetaDataResolvers/TeamCityMetaDataResolver.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using BCLExtensions; | ||
using Beefeater; | ||
using csmacnz.Coveralls.Ports; | ||
|
||
namespace csmacnz.Coveralls.MetaDataResolvers | ||
{ | ||
public class TeamCityMetaDataResolver : IMetaDataResolver | ||
{ | ||
private readonly IEnvironmentVariables _variables; | ||
|
||
public TeamCityMetaDataResolver(IEnvironmentVariables variables) | ||
{ | ||
_variables = variables; | ||
} | ||
|
||
public bool IsActive() | ||
{ | ||
return _variables.GetBooleanVariable("TEAMCITY_VERSION"); | ||
} | ||
|
||
public Option<string> ResolveServiceName() | ||
{ | ||
return "teamcity"; | ||
} | ||
|
||
public Option<string> ResolveServiceJobId() | ||
{ | ||
return Option<string>.None; | ||
} | ||
|
||
public Option<string> ResolveServiceBuildNumber() | ||
{ | ||
// %build.counter% | ||
return GetFromVariable("TEAMCITY_BUILD_NUMBER"); | ||
} | ||
|
||
public Option<string> ResolvePullRequestId() | ||
{ | ||
var value = GetFromVariable("TEAMCITY_PULL_REQUEST"); | ||
|
||
// TODO: regex for `refs/pull/86/merge` && `refs/pull/86/head` | ||
return value.Match( | ||
val => bool.TryParse(val?.Trim(), out bool _) ? val : Option<string>.None, | ||
() => Option<string>.None); | ||
} | ||
|
||
private Option<string> GetFromVariable(string variableName) | ||
{ | ||
var prId = _variables.GetEnvironmentVariable(variableName); | ||
|
||
if (prId.IsNotNullOrWhitespace()) | ||
{ | ||
return prId; | ||
} | ||
|
||
return Option<string>.None; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters