-
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
7 changed files
with
255 additions
and
64 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
42 changes: 42 additions & 0 deletions
42
src/csmacnz.Coveralls/GitDataResolvers/TravisGitDataResolver.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,42 @@ | ||
using csmacnz.Coveralls.Data; | ||
using csmacnz.Coveralls.Ports; | ||
|
||
namespace csmacnz.Coveralls.GitDataResolvers | ||
{ | ||
public class TravisGitDataResolver : IGitDataResolver | ||
{ | ||
private readonly IEnvironmentVariables _variables; | ||
|
||
public TravisGitDataResolver(IEnvironmentVariables variables) | ||
{ | ||
_variables = variables; | ||
} | ||
|
||
public string DisplayName => "Travis Environment Variables"; | ||
|
||
public bool CanProvideData() | ||
{ | ||
return bool.TryParse(_variables.GetEnvironmentVariable("TRAVIS"), out var result) && result; | ||
} | ||
|
||
public GitData GenerateData() | ||
{ | ||
var generateData = new GitData | ||
{ | ||
Head = new GitHead | ||
{ | ||
Id = _variables.GetEnvironmentVariable("TRAVIS_COMMIT") ?? string.Empty, | ||
AuthorName = _variables.GetEnvironmentVariable("REPO_COMMIT_AUTHOR") ?? string.Empty, | ||
AuthorEmail = _variables.GetEnvironmentVariable("REPO_COMMIT_AUTHOR_EMAIL") ?? string.Empty, | ||
CommitterName = _variables.GetEnvironmentVariable("REPO_COMMIT_AUTHOR") ?? string.Empty, | ||
ComitterEmail = | ||
_variables.GetEnvironmentVariable("REPO_COMMIT_AUTHOR_EMAIL") ?? string.Empty, | ||
Message = _variables.GetEnvironmentVariable("REPO_COMMIT_MESSAGE") ?? string.Empty | ||
}, | ||
Branch = _variables.GetEnvironmentVariable("TRAVIS_BRANCH") ?? string.Empty | ||
}; | ||
|
||
return generateData; | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/csmacnz.Coveralls/MetaDataResolvers/AppVeyorMetaDataResolver.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,54 @@ | ||
using BCLExtensions; | ||
using Beefeater; | ||
using csmacnz.Coveralls.Data; | ||
using csmacnz.Coveralls.Ports; | ||
|
||
namespace csmacnz.Coveralls.MetaDataResolvers | ||
{ | ||
public class AppVeyorMetaDataResolver : IMetaDataResolver | ||
{ | ||
private readonly IEnvironmentVariables _variables; | ||
|
||
public AppVeyorMetaDataResolver(IEnvironmentVariables variables) | ||
{ | ||
_variables = variables; | ||
} | ||
|
||
public bool IsActive() | ||
{ | ||
return bool.TryParse(_variables.GetEnvironmentVariable("APPVEYOR"), out var result) && result; | ||
} | ||
|
||
public Option<string> ResolveServiceName() | ||
{ | ||
return "appveyor"; | ||
} | ||
|
||
public Option<string> ResolveServiceJobId() | ||
{ | ||
return GetFromVariable("APPVEYOR_JOB_ID"); | ||
} | ||
|
||
public Option<string> ResolveServiceNumber() | ||
{ | ||
return GetFromVariable("APPVEYOR_BUILD_NUMBER"); | ||
} | ||
|
||
public Option<string> ResolvePullRequestId() | ||
{ | ||
return GetFromVariable("APPVEYOR_PULL_REQUEST_NUMBER"); | ||
} | ||
|
||
private Option<string> GetFromVariable(string variableName) | ||
{ | ||
var prId = _variables.GetEnvironmentVariable(variableName); | ||
|
||
if (prId.IsNotNullOrWhitespace()) | ||
{ | ||
return prId; | ||
} | ||
|
||
return Option<string>.None; | ||
} | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
src/csmacnz.Coveralls/MetaDataResolvers/CommandLineMetaDataResolver.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,61 @@ | ||
using BCLExtensions; | ||
using Beefeater; | ||
using csmacnz.Coveralls.Data; | ||
|
||
namespace csmacnz.Coveralls.MetaDataResolvers | ||
{ | ||
public class CommandLineMetaDataResolver : IMetaDataResolver | ||
{ | ||
private readonly MainArgs _args; | ||
|
||
public CommandLineMetaDataResolver(MainArgs args) | ||
{ | ||
_args = args; | ||
} | ||
|
||
public bool IsActive() | ||
{ | ||
return true; | ||
} | ||
|
||
public Option<string> ResolveServiceName() | ||
{ | ||
if (_args.IsProvided("--serviceName")) | ||
{ | ||
return _args.OptServicename ?? string.Empty; | ||
} | ||
|
||
return Option<string>.None; | ||
} | ||
|
||
public Option<string> ResolveServiceJobId() | ||
{ | ||
if (_args.IsProvided("--jobId")) | ||
{ | ||
return _args.OptJobid ?? string.Empty; | ||
} | ||
|
||
return Option<string>.None; | ||
} | ||
|
||
public Option<string> ResolveServiceNumber() | ||
{ | ||
if (_args.IsProvided("--serviceNumber")) | ||
{ | ||
return _args.OptServicenumber ?? string.Empty; | ||
} | ||
|
||
return Option<string>.None; | ||
} | ||
|
||
public Option<string> ResolvePullRequestId() | ||
{ | ||
if (_args.IsProvided("--pullRequest")) | ||
{ | ||
return _args.OptPullrequest ?? string.Empty; | ||
} | ||
|
||
return Option<string>.None; | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/csmacnz.Coveralls/MetaDataResolvers/IMetaDataResolver.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,17 @@ | ||
using Beefeater; | ||
|
||
namespace csmacnz.Coveralls.MetaDataResolvers | ||
{ | ||
public interface IMetaDataResolver | ||
{ | ||
bool IsActive(); | ||
|
||
Option<string> ResolveServiceName(); | ||
|
||
Option<string> ResolveServiceJobId(); | ||
|
||
Option<string> ResolveServiceNumber(); | ||
|
||
Option<string> ResolvePullRequestId(); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/csmacnz.Coveralls/MetaDataResolvers/TravisMetaDataResolver.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,57 @@ | ||
using BCLExtensions; | ||
using Beefeater; | ||
using csmacnz.Coveralls.Data; | ||
using csmacnz.Coveralls.Ports; | ||
|
||
namespace csmacnz.Coveralls.MetaDataResolvers | ||
{ | ||
public class TravisMetaDataResolver : IMetaDataResolver | ||
{ | ||
private readonly IEnvironmentVariables _variables; | ||
|
||
public TravisMetaDataResolver(IEnvironmentVariables variables) | ||
{ | ||
_variables = variables; | ||
} | ||
|
||
public bool IsActive() | ||
{ | ||
return bool.TryParse(_variables.GetEnvironmentVariable("TRAVIS"), out var result) && result; | ||
} | ||
|
||
public Option<string> ResolveServiceName() | ||
{ | ||
return "travis"; | ||
} | ||
|
||
public Option<string> ResolveServiceJobId() | ||
{ | ||
return GetFromVariable("TRAVIS_JOB_ID"); | ||
} | ||
|
||
public Option<string> ResolveServiceNumber() | ||
{ | ||
return GetFromVariable("TRAVIS_BUILD_NUMBER"); | ||
} | ||
|
||
public Option<string> ResolvePullRequestId() | ||
{ | ||
var value = GetFromVariable("TRAVIS_PULL_REQUEST"); | ||
return value.Match( | ||
val => val == "false" ? Option<string>.None : val, | ||
() => 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