Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/GitHub.App/Services/DialogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.ComponentModel.Composition;
using System.Threading.Tasks;
using GitHub.Api;
using GitHub.Exports;
using GitHub.Extensions;
using GitHub.Factories;
using GitHub.Models;
Expand Down Expand Up @@ -38,7 +39,13 @@ public async Task<CloneDialogResult> ShowCloneDialog(IConnection connection, str
if (string.IsNullOrEmpty(url))
{
var clipboardContext = gitHubContextService.FindContextFromClipboard();
url = clipboardContext?.Url;
switch (clipboardContext?.LinkType)
{
case LinkType.Blob:
case LinkType.Repository:
url = clipboardContext?.Url;
break;
}
}

var viewModel = factory.CreateViewModel<IRepositoryCloneViewModel>();
Expand Down
22 changes: 21 additions & 1 deletion src/GitHub.App/Services/GitHubContextService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,27 @@ public GitHubContext FindContextFromUrl(string url)
Url = uri
};

var repositoryPrefix = uri.ToRepositoryUrl().ToString() + "/";
if (uri.Owner == null)
{
context.LinkType = LinkType.Unknown;
return context;
}

if (uri.RepositoryName == null)
{
context.LinkType = LinkType.Unknown;
return context;
}

var repositoryUrl = uri.ToRepositoryUrl().ToString();
if (string.Equals(url, repositoryUrl, StringComparison.OrdinalIgnoreCase) ||
string.Equals(url, repositoryUrl + ".git", StringComparison.OrdinalIgnoreCase))
{
context.LinkType = LinkType.Repository;
return context;
}

var repositoryPrefix = repositoryUrl + "/";
if (!url.StartsWith(repositoryPrefix, StringComparison.OrdinalIgnoreCase))
{
return context;
Expand Down
3 changes: 2 additions & 1 deletion src/GitHub.Exports/Exports/ExportMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public enum LinkType
{
Unknown,
Blob,
Blame
Blame,
Repository
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,12 @@ public void Url_EqualTo(string url, string expectUrl)
Assert.That(context.Url?.ToString(), Is.EqualTo(expectUrl));
}

[TestCase("https://github.com/github/VisualStudio", LinkType.Repository)]
[TestCase("https://github.com/github/VisualStudio.git", LinkType.Repository)]
[TestCase("https://github.com/github/VisualStudio/unknown/master/README.md", LinkType.Unknown)]
[TestCase("https://github.com/github/VisualStudio/blob/master/README.md", LinkType.Blob)]
[TestCase("https://github.com", LinkType.Unknown)]
[TestCase("https://github.com/github", LinkType.Unknown)]
[TestCase("https://github.com/github/VisualStudio/unknown/master/README.md", LinkType.Unknown)]
public void LinkType_EqualTo(string url, LinkType expectLinkType)
{
Expand Down