66using GitHub . Commands ;
77using GitHub . Services ;
88using GitHub . Primitives ;
9+ using GitHub . App . Services ;
910using GitHub . Services . Vssdk . Commands ;
1011using EnvDTE ;
1112using Microsoft . VisualStudio ;
@@ -15,6 +16,7 @@ namespace GitHub.VisualStudio.Commands
1516 [ Export ( typeof ( IOpenFromUrlCommand ) ) ]
1617 public class OpenFromUrlCommand : VsCommand < string > , IOpenFromUrlCommand
1718 {
19+ readonly Lazy < GitHubContextService > gitHubContextService ;
1820 readonly Lazy < IRepositoryCloneService > repositoryCloneService ;
1921 readonly Lazy < IPullRequestEditorService > pullRequestEditorService ;
2022 readonly Lazy < IGitHubToolWindowManager > gitHubToolWindowManager ;
@@ -32,11 +34,13 @@ public class OpenFromUrlCommand : VsCommand<string>, IOpenFromUrlCommand
3234
3335 [ ImportingConstructor ]
3436 public OpenFromUrlCommand (
37+ Lazy < GitHubContextService > gitHubContextService ,
3538 Lazy < IRepositoryCloneService > repositoryCloneService ,
3639 Lazy < IPullRequestEditorService > pullRequestEditorService ,
3740 [ Import ( typeof ( Microsoft . VisualStudio . Shell . SVsServiceProvider ) ) ] IServiceProvider sp ) :
3841 base ( CommandSet , CommandId )
3942 {
43+ this . gitHubContextService = gitHubContextService ;
4044 this . repositoryCloneService = repositoryCloneService ;
4145 this . pullRequestEditorService = pullRequestEditorService ;
4246 dte = new Lazy < DTE > ( ( ) => ( DTE ) sp . GetService ( typeof ( DTE ) ) ) ;
@@ -56,6 +60,21 @@ public override async Task Execute(string url)
5660
5761 var gitHubUrl = new UriString ( url ) ;
5862 if ( ! gitHubUrl . IsValidUri || ! gitHubUrl . IsHypertextTransferProtocol )
63+ {
64+ gitHubUrl = null ;
65+ }
66+
67+ if ( gitHubUrl == null )
68+ {
69+ // HACK: Reconstruct a GitHub URL from the topmost browser window
70+ var context = gitHubContextService . Value . FindContextFromBrowser ( ) ;
71+ if ( context != null )
72+ {
73+ gitHubUrl = $ "https://github.com/{ context . Owner } /{ context . RepositoryName } ";
74+ }
75+ }
76+
77+ if ( gitHubUrl == null )
5978 {
6079 return ;
6180 }
0 commit comments