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

Open from clipboard url #1771

Merged
merged 69 commits into from
Jul 13, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
1de94ef
Add GitHub.OpenFromUrl command
jcansdale Jun 22, 2018
516128a
Update UriString to handle extended GitHub URLs
jcansdale Jun 22, 2018
7071b43
Support opening target from GitHub URL
jcansdale Jun 22, 2018
199a79f
Allow navigating to URL from clipboard
jcansdale Jun 25, 2018
134f6a8
Checkout or open using default path
jcansdale Jun 25, 2018
d5b833d
Don't open folder if current solution is inside it
jcansdale Jun 25, 2018
c097098
Add support for navigating to a PR URL
jcansdale Jun 25, 2018
12eb8d5
Open at line number from GitHub URL
jcansdale Jun 25, 2018
9399711
Add Open from GitHub command to File > Open
jcansdale Jun 25, 2018
89484dc
Merge branch 'master' into fixes/1757-open-from-url
jcansdale Jun 26, 2018
0aade59
Update UriString to allow http URLs with owner
jcansdale Jun 26, 2018
70d9d90
Find GitHub context from Chrome window title
jcansdale Jun 27, 2018
a82390f
Add support for opening from topmost browser
jcansdale Jun 27, 2018
c4cac4d
Support syncing the file open in topmost browser
jcansdale Jun 27, 2018
d1b0231
Ask user before cloning or opening a repository
jcansdale Jun 28, 2018
0d264d5
Factor GitHub URL parsing into FindContextFromUrl
jcansdale Jun 28, 2018
19249b0
Convert from GitHub to Visual Studio line numbers
jcansdale Jun 28, 2018
9b0fe66
Add support for file links that use a commit SHA
jcansdale Jun 28, 2018
7320235
Fix a few typos
jcansdale Jun 28, 2018
e900d7d
Update title regex to work with Firefox
jcansdale Jun 29, 2018
5019370
Detect repository home with no description
jcansdale Jul 2, 2018
90c0aa9
Use regex for matching line
jcansdale Jul 3, 2018
0bed9b2
Find line end from GitHub URL
jcansdale Jul 3, 2018
0aae4ca
Add support for navigating to a range of lines
jcansdale Jul 3, 2018
0fc10b7
Highlight line when single line is selected
jcansdale Jul 3, 2018
cfdf410
Select just the target lines
jcansdale Jul 3, 2018
55b1570
Stop the tuple madness
jcansdale Jul 3, 2018
cb7816c
Explicitly match CommitSha in blob URLs
jcansdale Jul 3, 2018
2243891
Add ResolvePath to resolve Treeish + BlobName
jcansdale Jul 3, 2018
39f3a54
Rename Treeish to TreeishPath
jcansdale Jul 4, 2018
d06ba40
First try opening in active repository
jcansdale Jul 4, 2018
d9ce6f5
Add separate `GitHub.OpenFromClipboard` command
jcansdale Jul 4, 2018
dbcb792
Simplify OpenFromClipboardCommand
jcansdale Jul 4, 2018
8e968cc
Show alert when no GitHub URL in clipboard
jcansdale Jul 4, 2018
b31b14f
Add ResolveGitObject to find local object from URL
jcansdale Jul 5, 2018
5b16030
Merge branch 'master' into fixes/1757-open-from-url
jcansdale Jul 5, 2018
92ffa39
Show message when there is no repo to navigate
jcansdale Jul 5, 2018
1f0f5fb
Return commitish and path from ResolveGitObject
jcansdale Jul 5, 2018
1d468d9
Let ResolveGitObject resolve commit without path
jcansdale Jul 5, 2018
5058564
Warn user when changes in local version of file
jcansdale Jul 5, 2018
bc780c4
If target blob has changed then show AnnotateFile
jcansdale Jul 6, 2018
c175d97
Don't throw when navigating to non-blob
jcansdale Jul 6, 2018
7784364
Rename ResolveGitObject to ResolveBlob
jcansdale Jul 6, 2018
6a3d8e4
Remove legacy ResolvePath method
jcansdale Jul 6, 2018
11866fb
Remove Open from GitHub... from File > Open menu
jcansdale Jul 9, 2018
c5c493d
Warn when user isn't in target repository
jcansdale Jul 9, 2018
36d6b0b
Merge branch 'master' into feature/open-from-clipboard-url
jcansdale Jul 9, 2018
3029ccd
Merge branch 'feature/open-from-clipboard-url' of https://github.com/…
jcansdale Jul 9, 2018
de5726f
Make ResolveBlob return if commitish is a SHA
jcansdale Jul 9, 2018
ab3e7e9
Change ResolveBlob to resolve remote refs
jcansdale Jul 9, 2018
19be672
Return commit SHA from ResolveBlob
jcansdale Jul 10, 2018
381806b
Add support for resolving tags
jcansdale Jul 10, 2018
f81fb36
Warn if URL owner is different to current owner
jcansdale Jul 10, 2018
e1bfa23
Allow repository names to differ in case
jcansdale Jul 10, 2018
fd0f835
Merge branch 'master' into feature/open-from-clipboard-url
jcansdale Jul 12, 2018
c429d76
Show dialog when attempting to open non-blob URL
jcansdale Jul 12, 2018
9ad3ba7
We don't support vpath in a URL
jcansdale Jul 12, 2018
81b6d8a
Lose the App form GitHub.App.Services
jcansdale Jul 12, 2018
f651b19
Clean up and xmldoc the AnnotateFile method
jcansdale Jul 12, 2018
f12ab09
Remove FindContextFromBrowser from hidden command
jcansdale Jul 12, 2018
057a77f
Add xmldocs for GitHubContext
jcansdale Jul 12, 2018
513b562
Add xmldocs for GitHubContextService
jcansdale Jul 12, 2018
b26b2a9
Merge branch 'master' into feature/open-from-clipboard-url
jcansdale Jul 13, 2018
83610bf
Only show command when in context of git repo
jcansdale Jul 13, 2018
bec5eca
Add more xmldocs
jcansdale Jul 13, 2018
ce68103
Lazy initialize the UIContext
jcansdale Jul 13, 2018
e88a3e4
Merge branch 'master' into feature/open-from-clipboard-url
grokys Jul 13, 2018
22ec886
Use <inheritdoc/> on members not classes!
jcansdale Jul 13, 2018
edbec49
Make <summary> xmldoc elements a single sentence
jcansdale Jul 13, 2018
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
Prev Previous commit
Next Next commit
Update UriString to allow http URLs with owner
The following URL will now have an owner of "owner":
https://github.com/owner
Previously it would make a repository name of "owner".
  • Loading branch information
jcansdale committed Jun 26, 2018
commit 0aade5901fc5df9a770046e83bf8a68b62f2cf01
23 changes: 11 additions & 12 deletions src/GitHub.Exports/Primitives/UriString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,17 @@ public UriString(string uriString) : base(NormalizePath(uriString))
SetFilePath(uriString);
}

if (RepositoryName != null)
if (Owner != null && RepositoryName != null)
{
NameWithOwner = Owner != null
? string.Format(CultureInfo.InvariantCulture, "{0}/{1}", Owner, RepositoryName)
: RepositoryName;
NameWithOwner = string.Format(CultureInfo.InvariantCulture, "{0}/{1}", Owner, RepositoryName);
}
else if (Owner != null)
{
NameWithOwner = Owner;
}
else if (RepositoryName != null)
{
NameWithOwner = RepositoryName;
}
}

Expand All @@ -68,13 +74,6 @@ void SetUri(Uri uri)
var ownerSegment = FindSegment(uri.Segments, 0);
var repositorySegment = FindSegment(uri.Segments, 1);

if (repositorySegment == null)
{
// Prioritize having a RepositoryName over an Owner
repositorySegment = ownerSegment;
ownerSegment = null;
}

Host = uri.Host;
Owner = ownerSegment;
RepositoryName = GetRepositoryName(repositorySegment);
Expand Down Expand Up @@ -148,7 +147,7 @@ public Uri ToRepositoryUrl(string owner = null)
? url.Scheme
: Uri.UriSchemeHttps;

var nameWithOwner = owner != null && Owner != null ?
var nameWithOwner = owner != null && RepositoryName != null ?
string.Format(CultureInfo.InvariantCulture, "{0}/{1}", owner, RepositoryName) :
NameWithOwner;

Expand Down
26 changes: 9 additions & 17 deletions test/GitHub.Primitives.UnitTests/UriStringTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ public class TheConstructor : TestBaseClass
[TestCase("jane;fingerprint=9e:1a:5e:27:16:4d:2a:13:90:2c:64:41:bd:25:fd:[email protected]:github/Windows.git",
"foo.com", "github", "Windows")]
[TestCase("https://[email protected]/haacked/test-mytest.git", "bitbucket.org", "haacked", "test-mytest")]
[TestCase("https://git01.codeplex.com/nuget", "git01.codeplex.com", null, "nuget")]
[TestCase("https://git01.codeplex.com/nuget", "git01.codeplex.com", "nuget", null,
Description = "We assume the first component is the owner")]
[TestCase("https://example.com/vpath/foo/bar", "example.com", "vpath", "foo")]
[TestCase("https://example.com/vpath/foo/bar.git", "example.com", "vpath", "foo")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vpath here suggests "virtual path" which I assume is because enterprise installations can have a virtual path before the owner? I this PR changes the parsing of this to not work with vpaths, but maybe we should change the string vpath to something else here?

[TestCase("https://github.com/github/Windows.git?pr=24&branch=pr/23&filepath=relative/to/the/path.md",
"github.com", "github", "Windows")]
[TestCase("https://github.com/github/VisualStudio/blob/master/src/code.cs", "github.com", "github", "VisualStudio")]
[TestCase("https://github.com/github", "github.com", "github", null)]
[TestCase("https://github.com", "github.com", null, null)]
public void ParsesWellFormedUrlComponents(string url, string expectedHost, string owner, string repositoryName)
{
var cloneUrl = new UriString(url);
Expand Down Expand Up @@ -71,13 +74,17 @@ public void ParsesLocalFileUris(string path)
[TestCase("http://example.com", "example.com", null, null)]
[TestCase("http://example.com?bar", "example.com", null, null)]
[TestCase("https://example.com?bar", "example.com", null, null)]
[TestCase("ssh://[email protected]/Windows.git", "example.com", null, "Windows")]
[TestCase("ssh://[email protected]/Windows.git", "example.com", "Windows.git", null,
Description = "We assume the first component is the owner even if it ends with .git")]
[TestCase("[email protected]:/", "bar.com", null, null)]
[TestCase("[email protected]/", "bar.com", null, null)]
[TestCase("[email protected]", "bar.com", null, null)]
[TestCase("[email protected]:/Windows.git", "bar.com", null, "Windows")]
[TestCase("[email protected]/Windows.git", "baz.com", null, "Windows")]
[TestCase("ssh://[email protected]:github/Windows.git", "github.com", "github", "Windows")]

// NOTE: Used by LocalRepositoryModelTests.GenerateUrl but I don't think it's a legal URL
[TestCase("[email protected]/foo/bar", "github.com", null, "foo/bar")]
public void ParsesWeirdUrlsAsWellAsPossible(string url, string expectedHost, string owner, string repositoryName)
{
var cloneUrl = new UriString(url);
Expand Down Expand Up @@ -202,21 +209,6 @@ public void ConvertsWithNewOwner(string uriString, string expected, string owner
[TestCase("[email protected]:org/repo.git", "https://example.com/org/repo")]
[TestCase("ssh://[email protected]:443/shana/cef", "https://github.com/shana/cef")]
[TestCase("ssh://[email protected]:23/haacked/encourage", "https://example.com:23/haacked/encourage")]

[TestCase("asdf", null)]
[TestCase("", null)]
[TestCase("file:///C:/dev/exp/foo", "file:///C:/dev/exp/foo")]
[TestCase("http://example.com/", "http://example.com/")]
[TestCase("http://[email protected]/foo/bar", "http://example.com/foo/bar")]
[TestCase("https://github.com/github/Windows", "https://github.com/github/Windows")]
[TestCase("https://github.com/github/Windows.git", "https://github.com/github/Windows")]
[TestCase("https://[email protected]/github/Windows.git", "https://github.com/github/Windows")]
[TestCase("http://example.com:4000/github/Windows", "http://example.com:4000/github/Windows")]
[TestCase("[email protected]:github/Windows.git", "https://192.168.1.2/github/Windows")]
[TestCase("[email protected]:org/repo.git", "https://example.com/org/repo")]
[TestCase("ssh://[email protected]:443/shana/cef", "https://github.com/shana/cef")]
[TestCase("ssh://[email protected]:23/haacked/encourage", "https://example.com:23/haacked/encourage")]

public void ShouldNeverThrow(string url, string expected)
{
Uri uri;
Expand Down