Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Commit

Permalink
Merge branch 'feature/gh-101' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
AdmiringWorm committed Jun 10, 2020
2 parents 24d67dd + 5025e02 commit 89b457b
Show file tree
Hide file tree
Showing 13 changed files with 274 additions and 36 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ trim_trailing_whitespace = true
insert_final_newline = true
indent_style = space
indent_size = 4
charset = utf-8

[*.{yml,yaml}]
indent_size = 2
Expand All @@ -19,6 +20,9 @@ end_of_line = LF
[*.DotSettings]
end_of_line = LF

[*.ps1]
charset = utf-8-bom

[*.cs]
#### .NET Coding Conventions ####

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using Codecov.Services.ContinuousIntegrationServers;
using FluentAssertions;
using Moq;
Expand All @@ -14,6 +13,7 @@ public void Branch_Should_Be_Empty_When_Environment_Variable_Does_Not_Exist()
// Given
var ga = new Mock<GitHubAction>() { CallBase = true };
ga.Setup(s => s.GetEnvironmentVariable("GITHUB_REF")).Returns(string.Empty);
ga.Setup(s => s.GetEnvironmentVariable("GITHUB_HEAD_REF")).Returns(string.Empty);
var githubAction = ga.Object;

// When
Expand All @@ -23,12 +23,29 @@ public void Branch_Should_Be_Empty_When_Environment_Variable_Does_Not_Exist()
branch.Should().BeEmpty();
}

[Fact]
public void Branch_Should_Be_Set_From_Head_Ref_When_Environment_Variable_Exist()
{
// Given
var ga = new Mock<GitHubAction>() { CallBase = true };
ga.Setup(s => s.GetEnvironmentVariable("GITHUB_REF")).Returns("refs/pull/234/merge");
ga.Setup(s => s.GetEnvironmentVariable("GITHUB_HEAD_REF")).Returns("develop");
var githubAction = ga.Object;

// When
var branch = githubAction.Branch;

// Then
branch.Should().Be("develop");
}

[Fact]
public void Branch_Should_Be_Set_When_Enviornment_Variable_Exits()
{
// Given
var ga = new Mock<GitHubAction>() { CallBase = true };
ga.Setup(s => s.GetEnvironmentVariable("GITHUB_REF")).Returns("ref/heads/develop");
ga.Setup(s => s.GetEnvironmentVariable("GITHUB_REF")).Returns("refs/heads/develop");
ga.Setup(s => s.GetEnvironmentVariable("GITHUB_HEAD_REF")).Returns(string.Empty);
var githubAction = ga.Object;

// When
Expand All @@ -38,6 +55,84 @@ public void Branch_Should_Be_Set_When_Enviornment_Variable_Exits()
branch.Should().Be("develop");
}

[Fact]
public void Build_Should_Be_Empty_When_Environment_Variable_Does_Not_Exist()
{
// Given
var ga = new Mock<GitHubAction>() { CallBase = true };
ga.Setup(s => s.GetEnvironmentVariable("GITHUB_RUN_ID")).Returns(string.Empty);
var githubAction = ga.Object;

// When
var build = githubAction.Build;

// Then
build.Should().BeEmpty();
}

[Fact]
public void Build_Should_Be_Set_When_Enviornment_Variable_Exits()
{
// Given
var ga = new Mock<GitHubAction>() { CallBase = true };
ga.Setup(s => s.GetEnvironmentVariable("GITHUB_RUN_ID")).Returns("32402849");
var githubAction = ga.Object;

// When
var build = githubAction.Build;

// Then
build.Should().Be("32402849");
}

[Fact]
public void BuildUrl_Should_Be_Empty_When_Build_Is_Empty()
{
// Given
var ga = new Mock<GitHubAction>() { CallBase = true };
ga.Setup(s => s.GetEnvironmentVariable("GITHUB_REPOSITORY")).Returns("codecov/codecov-exe");
ga.Setup(s => s.GetEnvironmentVariable("GITHUB_RUN_ID")).Returns(string.Empty);
var githubAction = ga.Object;

// When
var buildUrl = githubAction.BuildUrl;

// Then
buildUrl.Should().BeEmpty();
}

[Fact]
public void BuildUrl_Should_Be_Empty_When_Slug_Is_Empty()
{
// Given
var ga = new Mock<GitHubAction>() { CallBase = true };
ga.Setup(s => s.GetEnvironmentVariable("GITHUB_REPOSITORY")).Returns(string.Empty);
ga.Setup(s => s.GetEnvironmentVariable("GITHUB_RUN_ID")).Returns("some-id");
var githubAction = ga.Object;

// When
var buildUrl = githubAction.BuildUrl;

// Then
buildUrl.Should().BeEmpty();
}

[Fact]
public void BuildUrl_Should_Not_Be_Empty_When_Environment_Variables_Exist()
{
// Given
var ga = new Mock<GitHubAction>() { CallBase = true };
ga.Setup(s => s.GetEnvironmentVariable("GITHUB_REPOSITORY")).Returns("codecov/codecov-exe");
ga.Setup(s => s.GetEnvironmentVariable("GITHUB_RUN_ID")).Returns("23432");
var githubAction = ga.Object;

// When
var buildUrl = githubAction.BuildUrl;

// Then
buildUrl.Should().Be("https://github.com/codecov/codecov-exe/actions/runs/23432");
}

[Fact]
public void Commit_Should_Be_Empty_String_When_Enviornment_Variable_Does_Not_Exits()
{
Expand Down Expand Up @@ -68,12 +163,29 @@ public void Commit_Should_Be_Set_When_Enviornment_Variable_Exits()
commit.Should().Be("123");
}

[Fact]
public void Detecter_Should_Be_False_When_Action_Environment_Variable_Is_Null_Or_Empty()
{
// Given
var ga = new Mock<GitHubAction>() { CallBase = true };
ga.Setup(s => s.GetEnvironmentVariable("GITHUB_ACTION")).Returns(string.Empty);
ga.Setup(s => s.GetEnvironmentVariable("GITHUB_ACTIONS")).Returns(string.Empty);
var githubAction = ga.Object;

// When
var detecter = githubAction.Detecter;

// Then
detecter.Should().BeFalse();
}

[Theory, InlineData(null), InlineData(""), InlineData("False"), InlineData("false"), InlineData("foo")]
public void Detecter_Should_Be_False_When_Actions_Environment_Variable_Does_Not_Exist_Or_Is_Not_True(string environmentData)
public void Detecter_Should_Be_False_When_Actions_And_Action_Environment_Variable_Does_Not_Exist_Or_Is_Not_True(string environmentData)
{
// Given
var ga = new Mock<GitHubAction>() { CallBase = true };
ga.Setup(s => s.GetEnvironmentVariable("GITHUB_ACTIONS")).Returns(environmentData);
ga.Setup(s => s.GetEnvironmentVariable("GITHUB_ACTION")).Returns(string.Empty);
var githubAction = ga.Object;

// When
Expand All @@ -83,12 +195,29 @@ public void Detecter_Should_Be_False_When_Actions_Environment_Variable_Does_Not_
detecter.Should().BeFalse();
}

[Fact]
public void Detecter_Should_Be_True_When_Action_Environment_Variable_Exist_And_Is_Not_Empty()
{
// Given
var ga = new Mock<GitHubAction>() { CallBase = true };
ga.Setup(s => s.GetEnvironmentVariable("GITHUB_ACTION")).Returns("my-awesome-github-action");
ga.Setup(s => s.GetEnvironmentVariable("GITHUB_ACTIONS")).Returns(string.Empty);
var githubActions = ga.Object;

// When
var detecter = githubActions.Detecter;

// Then
detecter.Should().BeTrue();
}

[Theory, InlineData("True"), InlineData("true")]
public void Detecter_Should_Be_True_When_Actions_Environment_Variable_Exist_And_Is_True(string environmentData)
{
// Given
var ga = new Mock<GitHubAction>() { CallBase = true };
ga.Setup(s => s.GetEnvironmentVariable("GITHUB_ACTIONS")).Returns(environmentData);
ga.Setup(s => s.GetEnvironmentVariable("GITHUB_ACTION")).Returns(string.Empty);
var githubAction = ga.Object;

// When
Expand All @@ -98,6 +227,39 @@ public void Detecter_Should_Be_True_When_Actions_Environment_Variable_Exist_And_
detecter.Should().BeTrue();
}

[Fact]
public void PR_Should_Not_Be_Empty_When_Environment_Variables_Exist()
{
// Given
var ga = new Mock<GitHubAction>() { CallBase = true };
ga.Setup(s => s.GetEnvironmentVariable("GITHUB_HEAD_REF")).Returns("patch-2");
ga.Setup(s => s.GetEnvironmentVariable("GITHUB_REF")).Returns("refs/pull/7/merge");
var githubAction = ga.Object;

// When
var pr = githubAction.Pr;
var branch = githubAction.Branch;

// Then
pr.Should().Be("7");
branch.Should().Be("patch-2");
}

[Fact]
public void PR_Should_Not_be_Set_If_Head_Ref_Is_Empyt()
{
// Given
var ga = new Mock<GitHubAction>() { CallBase = true };
ga.Setup(s => s.GetEnvironmentVariable("GITHUB_HEAD_REF")).Returns(string.Empty);
var githubAction = ga.Object;

// When
var pr = githubAction.Pr;

// THen
pr.Should().BeEmpty();
}

[Fact]
public void Service_Should_Be_Set_To_GitHubActions()
{
Expand Down
1 change: 1 addition & 0 deletions Source/Codecov.Tool/Codecov.Tool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<TargetFrameworks>netcoreapp2.1;netcoreapp3.0</TargetFrameworks>
<LangVersion>8.0</LangVersion>
<CodeAnalysisRuleSet>.\Codecov.ruleset</CodeAnalysisRuleSet>
<PackageId>Codecov.Tool</PackageId>
<ToolCommandName>codecov</ToolCommandName>
Expand Down
1 change: 1 addition & 0 deletions Source/Codecov/Codecov.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<PropertyGroup Condition="'$(TargetFrameworks)' == ''">
<TargetFramework>netcoreapp3.1</TargetFramework>
<RuntimeIdentifiers>win7-x64;win7-x86;linux-x64;osx-x64</RuntimeIdentifiers>
<LangVersion>8.0</LangVersion>
</PropertyGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System;
using System.Collections.Generic;
using Codecov.Services.ContinuousIntegrationServers;
using Codecov.Utilities;

namespace Codecov.Coverage.EnviornmentVariables
{
Expand Down Expand Up @@ -42,7 +43,7 @@ private IDictionary<string, string> LoadEnviornmentVariables()
var enviornmentVariables = new Dictionary<string, string>(ContinuousIntegrationServer.UserEnvironmentVariables);

const string codecovName = "CODECOV_ENV";
var codecovValue = Environment.GetEnvironmentVariable(codecovName);
var codecovValue = EnviornmentVariable.GetEnviornmentVariable(codecovName);
if (!string.IsNullOrWhiteSpace(codecovValue) && !enviornmentVariables.ContainsKey(codecovName))
{
enviornmentVariables[codecovName] = codecovValue;
Expand All @@ -56,13 +57,13 @@ private IDictionary<string, string> LoadEnviornmentVariables()
continue;
}

var value = Environment.GetEnvironmentVariable(enviornmentVariableName);
var value = EnviornmentVariable.GetEnviornmentVariable(enviornmentVariableName);
if (string.IsNullOrWhiteSpace(value))
{
continue;
}

enviornmentVariables[enviornmentVariableName] = Environment.GetEnvironmentVariable(enviornmentVariableName);
enviornmentVariables[enviornmentVariableName] = EnviornmentVariable.GetEnviornmentVariable(enviornmentVariableName);
}

return enviornmentVariables;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Linq;
using System.Linq;
using Codecov.Services.ContinuousIntegrationServers;

namespace Codecov.Factories
Expand All @@ -7,7 +7,7 @@ internal static class ContinuousIntegrationServerFactory
{
public static IContinuousIntegrationServer Create()
{
var continuousIntegrationServers = new IContinuousIntegrationServer[] { new AppVeyor(), new Travis(), new TeamCity(), new AzurePipelines(), new Jenkins() };
var continuousIntegrationServers = new IContinuousIntegrationServer[] { new AppVeyor(), new Travis(), new TeamCity(), new AzurePipelines(), new Jenkins(), new GitHubAction() };
var buildServer = continuousIntegrationServers.FirstOrDefault(x => x.Detecter);
return buildServer ?? new ContinuousIntegrationServer();
}
Expand Down
8 changes: 6 additions & 2 deletions Source/Codecov/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// This file is used by Code Analysis to maintain SuppressMessage attributes that are applied to this
// project. Project-level suppressions either have no target or are given a specific target and
// This file is used by Code Analysis to maintain SuppressMessage attributes that are applied to
// this project. Project-level suppressions either have no target or are given a specific target and
// scoped to a namespace, type, member, etc.

using System.Diagnostics.CodeAnalysis;

[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Wrong Usage", "DF0020:Marks undisposed objects assinged to a field, originated in an object creation.", Justification = "It gets disposed when application exits", Scope = "member", Target = "~M:Codecov.Upload.CodecovUploader.#cctor")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Wrong Usage", "DF0021:Marks undisposed objects assinged to a field, originated from method invocation.", Justification = "It gets disposed when application exits", Scope = "member", Target = "~M:Codecov.Logger.Log.Create(System.Boolean,System.Boolean)")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Wrong Usage", "DF0022:Marks undisposed objects assinged to a property, originated in an object creation.", Justification = "It gets disposed when parent is disposed", Scope = "member", Target = "~M:Codecov.Upload.CodecovUploader.CreateResponse(System.Net.Http.HttpRequestMessage)~System.Net.Http.HttpResponseMessage")]
[assembly: SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "We want to catch the general exception for logging purposes.", Scope = "member", Target = "~M:Codecov.Program.Run.Runner(System.Collections.Generic.IEnumerable{System.String})~System.Int32")]
[assembly: SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "In theory an exception should not happen here, but catch it just in case.", Scope = "member", Target = "~M:Codecov.Program.Program.Main(System.String[])~System.Int32")]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;

namespace Codecov.Services.ContinuousIntegrationServers
Expand Down Expand Up @@ -44,6 +44,9 @@ public AppVeyor()

public override string Slug => _slug.Value;

private static bool IsNullOrEmpty(params string[] parameters)
=> parameters.Any(x => string.IsNullOrEmpty(x));

private string LoadBuild()
{
var build = GetEnvironmentVariable("APPVEYOR_JOB_ID");
Expand Down Expand Up @@ -81,8 +84,5 @@ private string LoadJob()

return job;
}

private static bool IsNullOrEmpty(params string[] parameters)
=> parameters.Any(x => string.IsNullOrEmpty(x));
}
}
Loading

0 comments on commit 89b457b

Please sign in to comment.