Skip to content

Commit 8fc057b

Browse files
authored
Fix issue with generated URL (#76)
* Fix URL creation * Perpare unit tests
1 parent c2d37ac commit 8fc057b

File tree

15 files changed

+183
-44
lines changed

15 files changed

+183
-44
lines changed

src/DotNet.GitHub/GlobalUsings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@
1414
global using Octokit;
1515
global using Octokit.Internal;
1616
global using ModelProject = DotNet.Models.Project;
17+
18+
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("DotNet.GitHubTests")]

src/DotNet.GitHub/ModelExtensions.cs

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ public static class ModelExtensions
88
public static string ToMarkdownBody(
99
this ISet<ProjectSupportReport> psrs,
1010
string tfm,
11-
string rootDirectory,
12-
string branch)
11+
IRepoOptions options)
1312
{
13+
var (rootDirectory, branch) = (options.Directory, options.Branch);
1414
IMarkdownDocument document = new MarkdownDocument();
1515

1616
document.AppendParagraph(
@@ -44,17 +44,8 @@ public static string ToMarkdownBody(
4444
new MarkdownList(
4545
psrs.OrderBy(psr => psr.Project.FullPath).Select(psr =>
4646
{
47-
var relativePath =
48-
Path.GetRelativePath(rootDirectory, psr.Project.FullPath);
49-
50-
var lineNumberFileReference =
51-
$"../blob/{branch}/{relativePath.Replace("\\", "/")}#L{psr.Project.TfmLineNumber}"
52-
.EscapeUriString();
53-
var name = relativePath.ShrinkPath("...");
54-
55-
// Must force anchor link, as GitHub assumes site-relative links.
56-
var anchor = $"<a href='{lineNumberFileReference}' title='{name} at line number {psr.Project.TfmLineNumber:#,0}'>{name}</a>";
57-
47+
var anchor = ToLineNumberUrl(
48+
psr.Project.FullPath, psr.Project.TfmLineNumber, options);
5849
return new MarkdownCheckListItem(false, anchor);
5950
})));
6051

@@ -79,9 +70,9 @@ public static string ToMarkdownBody(
7970
public static string ToMarkdownBody(
8071
this ISet<DockerfileSupportReport> dfsr,
8172
string tfm,
82-
string rootDirectory,
83-
string branch)
73+
IRepoOptions options)
8474
{
75+
var (rootDirectory, branch) = (options.Directory, options.Branch);
8576
IMarkdownDocument document = new MarkdownDocument();
8677

8778
document.AppendParagraph(
@@ -115,20 +106,13 @@ public static string ToMarkdownBody(
115106
new MarkdownList(
116107
dfsr.SelectMany(sr => sr.TargetFrameworkMonikerSupports.Select(tfms => (sr.Dockerfile, tfms)))
117108
.OrderBy(t => t.Dockerfile.FullPath)
118-
.Select(t =>
109+
.SelectMany(t =>
119110
{
120-
var relativePath =
121-
Path.GetRelativePath(rootDirectory, t.Dockerfile.FullPath);
122-
// TODO: 1
123-
var lineNumberFileReference =
124-
$"../blob/{branch}/{relativePath.Replace("\\", "/")}#L{1}"
125-
.EscapeUriString();
126-
var name = relativePath.ShrinkPath("...");
127-
128-
// Must force anchor link, as GitHub assumes site-relative links.
129-
var anchor = $"<a href='{lineNumberFileReference}' title='{name} at line number {1:#,0}'>{name}</a>";
130-
131-
return new MarkdownCheckListItem(false, anchor);
111+
return t.Dockerfile.ImageDetails!.Select(i =>
112+
{
113+
var anchor = ToLineNumberUrl(t.Dockerfile.FullPath, i.LineNumber, options);
114+
return new MarkdownCheckListItem(false, anchor);
115+
});
132116
})));
133117

134118
document.AppendParagraph(
@@ -149,6 +133,25 @@ public static string ToMarkdownBody(
149133
return document.ToString();
150134
}
151135

136+
private static string ToLineNumberUrl(
137+
string fullPath, int lineNumber, IRepoOptions options)
138+
{
139+
if (fullPath is null)
140+
{
141+
return "N/A";
142+
}
143+
144+
var relativePath =
145+
Path.GetRelativePath(options.Directory, fullPath!)
146+
.Replace("\\", "/");
147+
var lineNumberFileReference =
148+
$"https://github.com/{options.Owner}/{options.Name}/blob/{options.Branch}/{relativePath}#L{lineNumber}";
149+
var name = relativePath.ShrinkPath("...");
150+
151+
// Must force anchor link, as GitHub assumes site-relative links.
152+
return $"<a href='{lineNumberFileReference}' title='{name}'>{name}</a>";
153+
}
154+
152155
public static bool TryCreateIssueContent(
153156
this ISet<ModelProject> projects,
154157
string rootDirectory,

src/DotNet.Models/IRepoOptions.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace DotNet.Models;
5+
6+
public interface IRepoOptions
7+
{
8+
string Owner { get; }
9+
string Name { get; }
10+
string Branch { get; }
11+
string Directory { get; }
12+
}

src/DotNet.Releases/Core/CoreReleaseIndexService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace DotNet.Releases;
55

6-
public sealed class CoreReleaseIndexService : ICoreReleaseIndexService
6+
internal sealed class CoreReleaseIndexService : ICoreReleaseIndexService
77
{
88
const string NetCoreKey = nameof(NetCoreKey);
99

src/DotNet.Releases/Framework/FrameworkReleaseIndexService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace DotNet.Releases;
55

6-
public sealed class FrameworkReleaseIndexService : IFrameworkReleaseIndexService
6+
internal sealed class FrameworkReleaseIndexService : IFrameworkReleaseIndexService
77
{
88
/// <summary>
99
/// https://github.com/dotnet/website-resources/tree/master/data/dotnet-framework-releases

src/DotNet.Releases/Framework/FrameworkReleaseService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace DotNet.Releases;
55

6-
public sealed class FrameworkReleaseService : IFrameworkReleaseService
6+
internal sealed class FrameworkReleaseService : IFrameworkReleaseService
77
{
88
readonly IMemoryCache _cache;
99
readonly IFrameworkReleaseIndexService _indexService;

src/DotNet.Releases/GlobalUsings.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@
99
global using DotNet.Releases.Extensions;
1010
global using Microsoft.Deployment.DotNet.Releases;
1111
global using Microsoft.Extensions.Caching.Memory;
12+
13+
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("DotNet.GitHubTests")]
14+
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("DotNet.ReleasesTests")]

src/DotNet.Releases/LabeledVersion.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public LabeledVersion(Version version, string? label = null) =>
2222

2323
public static bool TryParse(string? input, out LabeledVersion? labeledVersion)
2424
{
25-
if (input is not null and { Length: > 0 })
25+
if (input is { Length: > 0 })
2626
{
2727
var split = input.Split("-");
2828
if (Version.TryParse(split[0], out var version))

src/DotNet.VersionSweeper/Options.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace DotNet.VersionSweeper;
55

6-
public sealed class Options
6+
public sealed class Options : IRepoOptions
77
{
88
string _repositoryName = null!;
99
string _branchName = null!;

src/DotNet.VersionSweeper/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,15 @@ static void AppendGrouping<T>(
176176
await CreateAndEnqueueAsync(
177177
graphQLClient, issueQueue, job,
178178
$"Upgrade from `{tfm}` to LTS (or current) image tag",
179-
options, o => dockerfileSupportReports.ToMarkdownBody(tfm, o.Directory, o.Branch));
179+
options, o => dockerfileSupportReports.ToMarkdownBody(tfm, o));
180180
}
181181

182182
foreach (var (tfm, projectSupportReports) in tfmToProjectSupportReports)
183183
{
184184
await CreateAndEnqueueAsync(
185185
graphQLClient, issueQueue, job,
186186
$"Upgrade from `{tfm}` to LTS (or current) version",
187-
options, o => projectSupportReports.ToMarkdownBody(tfm, o.Directory, o.Branch));
187+
options, o => projectSupportReports.ToMarkdownBody(tfm, o));
188188
}
189189

190190
if (nonSdkStyleProjects.TryCreateIssueContent(

0 commit comments

Comments
 (0)