Skip to content

Commit

Permalink
Ensure workspace path ends with a slash
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrrrz committed May 26, 2022
1 parent e57396d commit ef58724
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
9 changes: 7 additions & 2 deletions GitHubActionsTestLogger/GitHubWorkflow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ public partial class GitHubWorkflow
StringComparison.OrdinalIgnoreCase
);

public static string? SummaryFilePath { get; } = Environment.GetEnvironmentVariable("GITHUB_STEP_SUMMARY");
public static string? SummaryFilePath { get; } =
Environment.GetEnvironmentVariable("GITHUB_STEP_SUMMARY");

public static string? TryGenerateFilePermalink(string filePath, int? line)
{
Expand All @@ -106,7 +107,11 @@ public partial class GitHubWorkflow
string.IsNullOrWhiteSpace(commitHash))
return null;

var filePathNormalized = PathEx.GetRelativePath(workspacePath, filePath).Replace("\\", "/").Trim('/');
var filePathNormalized = PathEx
.GetRelativePath(workspacePath.EnsureEndsWith("/"), filePath)
.Replace("\\", "/")
.Trim('/');

var lineMarker = line?.Pipe(l => $"#L{l}");

return $"{serverUrl}/{repositorySlug}/blob/{commitHash}/{filePathNormalized}{lineMarker}";
Expand Down
6 changes: 6 additions & 0 deletions GitHubActionsTestLogger/Utils/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,10 @@ public static StringBuilder Trim(this StringBuilder builder)

return builder;
}

public static string EnsureEndsWith(
this string str,
string end,
StringComparison comparison = StringComparison.Ordinal) =>
!str.EndsWith(end, comparison) ? str + end : str;
}
5 changes: 2 additions & 3 deletions GitHubActionsTestLogger/Utils/PathEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ internal static class PathEx
// members, so we'll just use this one on all targets.
public static string GetRelativePath(string basePath, string path)
{
// Without using System
var basePathUri = new Uri(basePath);
var pathUri = new Uri(path);
var basePathUri = new Uri(basePath, UriKind.Absolute);
var pathUri = new Uri(path, UriKind.Absolute);

return Uri.UnescapeDataString(
basePathUri
Expand Down

0 comments on commit ef58724

Please sign in to comment.