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

Commit 7568520

Browse files
authored
Merge pull request #2215 from github/fixes/2214-open-from-github-url-filter
Fix opening a /blob/ URL using combined repository list/URL clone dialog
2 parents 0fb5841 + 19912d7 commit 7568520

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

src/GitHub.App/ViewModels/Dialog/Clone/RepositorySelectViewModel.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ public RepositorySelectViewModel(IRepositoryCloneService service, IGitHubContext
5050

5151
var filterRepository = this.WhenAnyValue(x => x.Filter)
5252
.Select(f => gitHubContextService.FindContextFromUrl(f))
53-
.Where(c => c?.LinkType == LinkType.Repository)
54-
.Select(c => new RepositoryModel(c.RepositoryName, c.Url));
53+
.Select(CreateRepository);
5554

5655
repository = selectedRepository
5756
.Merge(filterRepository)
@@ -198,5 +197,17 @@ RepositoryModel CreateRepository(IRepositoryItemViewModel item)
198197
new RepositoryModel(item.Name, UriString.ToUriString(item.Url)) :
199198
null;
200199
}
200+
201+
RepositoryModel CreateRepository(GitHubContext context)
202+
{
203+
switch (context?.LinkType)
204+
{
205+
case LinkType.Repository:
206+
case LinkType.Blob:
207+
return new RepositoryModel(context.RepositoryName, context.Url);
208+
}
209+
210+
return null;
211+
}
201212
}
202213
}

test/GitHub.App.UnitTests/ViewModels/Dialog/Clone/RepositorySelectViewModelTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ public async Task Filter(string filter, string owner, string name, string url, i
5757
[TestCase("filter", null)]
5858
[TestCase("https://github.com", null)]
5959
[TestCase("https://github.com/github/VisualStudio", "https://github.com/github/VisualStudio")]
60+
[TestCase("https://github.com/github/VisualStudio/blob/master/README.md", "https://github.com/github/VisualStudio/blob/master/README.md")]
61+
[TestCase("https://github.com/github/VisualStudio/pull/2208", null)]
6062
public void Set_Repository_When_Filter_Is_Url(string url, string expectUrl)
6163
{
6264
var expectCloneUrl = expectUrl != null ? new UriString(expectUrl) : null;
@@ -69,6 +71,24 @@ public void Set_Repository_When_Filter_Is_Url(string url, string expectUrl)
6971

7072
Assert.That(target.Repository?.CloneUrl, Is.EqualTo(expectCloneUrl));
7173
}
74+
75+
[TestCase("filter;https://github.com/github/VisualStudio", "https://github.com/github/VisualStudio")]
76+
[TestCase("https://github.com/github/VisualStudio;filter", null)]
77+
public void Change_Filters(string filters, string expectUrl)
78+
{
79+
var expectCloneUrl = expectUrl != null ? new UriString(expectUrl) : null;
80+
var repositoryCloneService = CreateRepositoryCloneService();
81+
var gitHubContextService = new GitHubContextService(Substitute.For<IGitHubServiceProvider>(),
82+
Substitute.For<IGitService>(), Substitute.For<IVSServices>());
83+
var target = new RepositorySelectViewModel(repositoryCloneService, gitHubContextService);
84+
85+
foreach (var filter in filters.Split(';'))
86+
{
87+
target.Filter = filter;
88+
}
89+
90+
Assert.That(target.Repository?.CloneUrl, Is.EqualTo(expectCloneUrl));
91+
}
7292
}
7393

7494
static IGitHubContextService CreateGitHubContextService()

0 commit comments

Comments
 (0)