diff --git a/src/Agoda.DevFeedback.Common/Agoda.DevFeedback.Common.csproj b/src/Agoda.DevFeedback.Common/Agoda.DevFeedback.Common.csproj index 820895b..fba6728 100644 --- a/src/Agoda.DevFeedback.Common/Agoda.DevFeedback.Common.csproj +++ b/src/Agoda.DevFeedback.Common/Agoda.DevFeedback.Common.csproj @@ -7,6 +7,7 @@ + diff --git a/src/Agoda.DevFeedback.Common/GitContextReader.cs b/src/Agoda.DevFeedback.Common/GitContextReader.cs index f9a50e0..0e71b64 100644 --- a/src/Agoda.DevFeedback.Common/GitContextReader.cs +++ b/src/Agoda.DevFeedback.Common/GitContextReader.cs @@ -21,6 +21,7 @@ public static GitContext GetGitContext() throw new GitContextException("Unable to get git branch."); } + url = CleanGitlabCIToken(url); return new GitContext { RepositoryUrl = url, @@ -59,7 +60,7 @@ static string RunCommand(string args) return process.StandardOutput.ReadLine(); } - static string GetRepositoryNameFromUrl(string url) + internal static string GetRepositoryNameFromUrl(string url) { var repositoryName = url.Substring(url.LastIndexOf('/') + 1); @@ -67,5 +68,14 @@ static string GetRepositoryNameFromUrl(string url) ? repositoryName.Substring(0, repositoryName.LastIndexOf('.')) : repositoryName; } + + internal static string CleanGitlabCIToken(string url) + { + if (url.Contains("@") && url.StartsWith("https")) + { + url = "https://" + url.Split('@')[1]; + } + return url; + } } } diff --git a/src/Agoda.DevFeedback.CommonTests/Agoda.DevFeedback.Common.Tests.csproj b/src/Agoda.DevFeedback.CommonTests/Agoda.DevFeedback.Common.Tests.csproj new file mode 100644 index 0000000..19e26ca --- /dev/null +++ b/src/Agoda.DevFeedback.CommonTests/Agoda.DevFeedback.Common.Tests.csproj @@ -0,0 +1,29 @@ + + + + net6.0 + enable + enable + + false + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + + + diff --git a/src/Agoda.DevFeedback.CommonTests/GitContextReaderTests.cs b/src/Agoda.DevFeedback.CommonTests/GitContextReaderTests.cs new file mode 100644 index 0000000..f21bcb6 --- /dev/null +++ b/src/Agoda.DevFeedback.CommonTests/GitContextReaderTests.cs @@ -0,0 +1,32 @@ +using Agoda.DevFeedback.Common; +using System; +using System.Collections.Generic; +using System.Text; +using NUnit.Framework; +using Shouldly; + +namespace Agoda.DevFeedback.Common.Tests +{ + [TestFixture()] + public class GitContextReaderTests + { + [Test()] + [TestCase("https://gitlab-ci-token:64_-_v7W68Q4uMG1sXIeh-W@gitlab.agodadev.io/full-stack/ycs/revenue-management", "64_-_v7W68Q4uMG1sXIeh-W")] + // Note: this is not a real token, it is just a random string + public void WhenUrlHasToken_ShouldCleanTokenFromUrl(string url, string token) + { + var result = GitContextReader.CleanGitlabCIToken(url); + result.ShouldNotContain(token); + result.ShouldNotContain("@"); + result.ShouldNotContain("gitlab-ci-token:"); + } + + [Test()] + [TestCase("https://gitlab.agodadev.io/full-stack/ycs/revenue-management")] + public void WhenGetRepoNameFromUrl_ShouldReturnTheGitlabNamespacePathForTheGitlabProject(string url) + { + GitContextReader.GetRepositoryNameFromUrl(url) + .ShouldBe("full-stack/ycs/revenue-management"); + } + } +} \ No newline at end of file diff --git a/src/DotnetBuildMetrics.sln b/src/DotnetBuildMetrics.sln index 8a0e043..66b6299 100644 --- a/src/DotnetBuildMetrics.sln +++ b/src/DotnetBuildMetrics.sln @@ -9,9 +9,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Agoda.DevFeedback.Common", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Agoda.DevFeedback.AspNetStartup", "Agoda.DevFeedback.AspNetStartup\Agoda.DevFeedback.AspNetStartup.csproj", "{1CDE58A7-3243-4564-93DA-59EF30475334}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Agoda.Tests.Metrics.NUnit", "Agoda.Tests.Metrics.NUnit\Agoda.Tests.Metrics.NUnit.csproj", "{E54150A6-5E21-47C7-947C-7AB6C362A1C9}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Agoda.Tests.Metrics.NUnit", "Agoda.Tests.Metrics.NUnit\Agoda.Tests.Metrics.NUnit.csproj", "{E54150A6-5E21-47C7-947C-7AB6C362A1C9}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Agoda.Tests.Metrics.NUnit.Tests", "Agoda.Tests.Metrics.NUnit.Tests\Agoda.Tests.Metrics.NUnit.Tests.csproj", "{C3FD34EE-C8E1-4A48-885D-1E9AC37B3561}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Agoda.Tests.Metrics.NUnit.Tests", "Agoda.Tests.Metrics.NUnit.Tests\Agoda.Tests.Metrics.NUnit.Tests.csproj", "{C3FD34EE-C8E1-4A48-885D-1E9AC37B3561}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Agoda.DevFeedback.Common.Tests", "Agoda.DevFeedback.CommonTests\Agoda.DevFeedback.Common.Tests.csproj", "{A78ACD7D-E485-4FAE-8669-D6A672CF6D3E}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -39,6 +41,10 @@ Global {C3FD34EE-C8E1-4A48-885D-1E9AC37B3561}.Debug|Any CPU.Build.0 = Debug|Any CPU {C3FD34EE-C8E1-4A48-885D-1E9AC37B3561}.Release|Any CPU.ActiveCfg = Release|Any CPU {C3FD34EE-C8E1-4A48-885D-1E9AC37B3561}.Release|Any CPU.Build.0 = Release|Any CPU + {A78ACD7D-E485-4FAE-8669-D6A672CF6D3E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A78ACD7D-E485-4FAE-8669-D6A672CF6D3E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A78ACD7D-E485-4FAE-8669-D6A672CF6D3E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A78ACD7D-E485-4FAE-8669-D6A672CF6D3E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE