Skip to content

Commit 5e0ce7e

Browse files
authored
Fix VMR file links (#4853)
#4841 (comment) 1. [Fix Vmr File Links](https://github.com/dotnet/arcade-services/pull/4853/commits/0d56e8213460983b14b9be7318fdf212860ff5ef)Some url-creating methods were written for normal repos and were incompatible with the vmr file structure 2. [Safely encode variable strings into url](https://github.com/dotnet/arcade-services/pull/4853/commits/5789e2f77fb1522b617a91704d9c44e0618f036a)Safely encode string variables into the URLs in all the helper methods, as per Copilot's suggestion, in order to avoid possible edge cases due to special characters in any of the variables
1 parent 314f790 commit 5e0ce7e

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/Microsoft.DotNet.Darc/DarcLib/Helpers/GitRepoUrlUtils.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,14 @@ public static string GetRepoFileAtCommitUri(string repoUri, string commit, strin
138138
_ => throw new ArgumentException("Unknown git repository type", nameof(repoUri)),
139139
};
140140

141+
public static string GetVmrFileAtCommitUri(string vmrUri, string productDirectory, string commit, string filePath)
142+
=> ParseTypeFromUri(vmrUri) switch
143+
{
144+
GitRepoType.AzureDevOps => $"{vmrUri}?version=GC{commit}&path=src/{productDirectory}/{filePath}",
145+
GitRepoType.GitHub => $"{vmrUri}/blob/{commit}/src/{productDirectory}/{filePath}",
146+
_ => throw new ArgumentException("Unknown git repository type", nameof(vmrUri)),
147+
};
148+
141149
public static string GetRepoFileAtBranchUri(string repoUri, string branch, string filePath)
142150
=> ParseTypeFromUri(repoUri) switch
143151
{
@@ -146,6 +154,14 @@ public static string GetRepoFileAtBranchUri(string repoUri, string branch, strin
146154
_ => throw new ArgumentException("Unknown git repository type", nameof(repoUri))
147155
};
148156

157+
public static string GetVmrFileAtBranchUri(string vmrUri, string productDirectory, string branch, string filePath)
158+
=> ParseTypeFromUri(vmrUri) switch
159+
{
160+
GitRepoType.AzureDevOps => $"{vmrUri}?version=GB{branch}&path=src/{productDirectory}/{filePath}",
161+
GitRepoType.GitHub => $"{vmrUri}/blob/{branch}/src/{productDirectory}/{filePath}",
162+
_ => throw new ArgumentException("Unknown git repository type", nameof(vmrUri))
163+
};
164+
149165
public static string GetRepoNameWithOrg(string uri)
150166
{
151167
var (repo, org) = GetRepoNameAndOwner(uri);

src/ProductConstructionService/ProductConstructionService.DependencyFlow/PullRequestConflictNotifier.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ public async Task NotifyAboutConflictingUpdateAsync(
6666
foreach (var file in conflictException.FilesInConflict)
6767
{
6868
var sourceString = subscription.IsBackflow()
69-
? $"[🔍 view in VMR]({GitRepoUrlUtils.GetRepoFileAtCommitUri(update.SourceRepo, update.SourceSha, file)})"
70-
: $"[🔍 view in {GitRepoUrlUtils.GetRepoNameWithOrg(update.SourceRepo)}]({GitRepoUrlUtils.GetRepoFileAtCommitUri(update.SourceRepo, update.SourceSha, file)})";
69+
? $"[🔍 View in VMR]({GitRepoUrlUtils.GetVmrFileAtCommitUri(update.SourceRepo, subscription.TargetDirectory, update.SourceSha, file)})"
70+
: $"[🔍 View in {GitRepoUrlUtils.GetRepoNameWithOrg(update.SourceRepo)}]({GitRepoUrlUtils.GetRepoFileAtCommitUri(update.SourceRepo, update.SourceSha, file)})";
7171
var targetString = subscription.IsBackflow()
72-
? $"[🔍 view in {GitRepoUrlUtils.GetRepoNameWithOrg(subscription.TargetRepository)}]({GitRepoUrlUtils.GetRepoFileAtBranchUri(subscription.TargetRepository, subscription.TargetBranch, file)})"
73-
: $"[🔍 view in VMR]({GitRepoUrlUtils.GetRepoFileAtBranchUri(subscription.TargetRepository, subscription.TargetBranch, file)})";
72+
? $"[🔍 View in {GitRepoUrlUtils.GetRepoNameWithOrg(subscription.TargetRepository)}]({GitRepoUrlUtils.GetRepoFileAtBranchUri(subscription.TargetRepository, subscription.TargetBranch, file)})"
73+
: $"[🔍 View in VMR]({GitRepoUrlUtils.GetVmrFileAtBranchUri(subscription.TargetRepository, subscription.SourceDirectory, subscription.TargetBranch, file)})";
7474
sb.AppendLine($" - `{file}` - {sourceString} / {targetString}");
7575
}
7676
sb.AppendLine();

0 commit comments

Comments
 (0)