Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 8c2c96b

Browse files
authored
Merge pull request #2177 from github/fixes/2176-recognize-repository-urls
Only auto-fill clone URL for supported link types
2 parents d05ee40 + 5f392b6 commit 8c2c96b

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

src/GitHub.App/Services/DialogService.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.ComponentModel.Composition;
33
using System.Threading.Tasks;
44
using GitHub.Api;
5+
using GitHub.Exports;
56
using GitHub.Extensions;
67
using GitHub.Factories;
78
using GitHub.Models;
@@ -38,7 +39,13 @@ public async Task<CloneDialogResult> ShowCloneDialog(IConnection connection, str
3839
if (string.IsNullOrEmpty(url))
3940
{
4041
var clipboardContext = gitHubContextService.FindContextFromClipboard();
41-
url = clipboardContext?.Url;
42+
switch (clipboardContext?.LinkType)
43+
{
44+
case LinkType.Blob:
45+
case LinkType.Repository:
46+
url = clipboardContext?.Url;
47+
break;
48+
}
4249
}
4350

4451
var viewModel = factory.CreateViewModel<IRepositoryCloneViewModel>();

src/GitHub.App/Services/GitHubContextService.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,27 @@ public GitHubContext FindContextFromUrl(string url)
124124
Url = uri
125125
};
126126

127-
var repositoryPrefix = uri.ToRepositoryUrl().ToString() + "/";
127+
if (uri.Owner == null)
128+
{
129+
context.LinkType = LinkType.Unknown;
130+
return context;
131+
}
132+
133+
if (uri.RepositoryName == null)
134+
{
135+
context.LinkType = LinkType.Unknown;
136+
return context;
137+
}
138+
139+
var repositoryUrl = uri.ToRepositoryUrl().ToString();
140+
if (string.Equals(url, repositoryUrl, StringComparison.OrdinalIgnoreCase) ||
141+
string.Equals(url, repositoryUrl + ".git", StringComparison.OrdinalIgnoreCase))
142+
{
143+
context.LinkType = LinkType.Repository;
144+
return context;
145+
}
146+
147+
var repositoryPrefix = repositoryUrl + "/";
128148
if (!url.StartsWith(repositoryPrefix, StringComparison.OrdinalIgnoreCase))
129149
{
130150
return context;

src/GitHub.Exports/Exports/ExportMetadata.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public enum LinkType
2121
{
2222
Unknown,
2323
Blob,
24-
Blame
24+
Blame,
25+
Repository
2526
}
2627

2728
/// <summary>

test/GitHub.App.UnitTests/Services/GitHubContextServiceTests.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,12 @@ public void Url_EqualTo(string url, string expectUrl)
133133
Assert.That(context.Url?.ToString(), Is.EqualTo(expectUrl));
134134
}
135135

136+
[TestCase("https://github.com/github/VisualStudio", LinkType.Repository)]
137+
[TestCase("https://github.com/github/VisualStudio.git", LinkType.Repository)]
138+
[TestCase("https://github.com/github/VisualStudio/unknown/master/README.md", LinkType.Unknown)]
136139
[TestCase("https://github.com/github/VisualStudio/blob/master/README.md", LinkType.Blob)]
140+
[TestCase("https://github.com", LinkType.Unknown)]
141+
[TestCase("https://github.com/github", LinkType.Unknown)]
137142
[TestCase("https://github.com/github/VisualStudio/unknown/master/README.md", LinkType.Unknown)]
138143
public void LinkType_EqualTo(string url, LinkType expectLinkType)
139144
{

0 commit comments

Comments
 (0)