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
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ public RepositorySelectViewModel(IRepositoryCloneService service, IGitHubContext

var filterRepository = this.WhenAnyValue(x => x.Filter)
.Select(f => gitHubContextService.FindContextFromUrl(f))
.Where(c => c?.LinkType == LinkType.Repository)
.Select(c => new RepositoryModel(c.RepositoryName, c.Url));
.Select(CreateRepository);

repository = selectedRepository
.Merge(filterRepository)
Expand Down Expand Up @@ -198,5 +197,17 @@ RepositoryModel CreateRepository(IRepositoryItemViewModel item)
new RepositoryModel(item.Name, UriString.ToUriString(item.Url)) :
null;
}

RepositoryModel CreateRepository(GitHubContext context)
{
switch (context?.LinkType)
{
case LinkType.Repository:
case LinkType.Blob:
return new RepositoryModel(context.RepositoryName, context.Url);
}

return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public async Task Filter(string filter, string owner, string name, string url, i
[TestCase("filter", null)]
[TestCase("https://github.com", null)]
[TestCase("https://github.com/github/VisualStudio", "https://github.com/github/VisualStudio")]
[TestCase("https://github.com/github/VisualStudio/blob/master/README.md", "https://github.com/github/VisualStudio/blob/master/README.md")]
[TestCase("https://github.com/github/VisualStudio/pull/2208", null)]
public void Set_Repository_When_Filter_Is_Url(string url, string expectUrl)
{
var expectCloneUrl = expectUrl != null ? new UriString(expectUrl) : null;
Expand All @@ -69,6 +71,24 @@ public void Set_Repository_When_Filter_Is_Url(string url, string expectUrl)

Assert.That(target.Repository?.CloneUrl, Is.EqualTo(expectCloneUrl));
}

[TestCase("filter;https://github.com/github/VisualStudio", "https://github.com/github/VisualStudio")]
[TestCase("https://github.com/github/VisualStudio;filter", null)]
public void Change_Filters(string filters, string expectUrl)
{
var expectCloneUrl = expectUrl != null ? new UriString(expectUrl) : null;
var repositoryCloneService = CreateRepositoryCloneService();
var gitHubContextService = new GitHubContextService(Substitute.For<IGitHubServiceProvider>(),
Substitute.For<IGitService>(), Substitute.For<IVSServices>());
var target = new RepositorySelectViewModel(repositoryCloneService, gitHubContextService);

foreach (var filter in filters.Split(';'))
{
target.Filter = filter;
}

Assert.That(target.Repository?.CloneUrl, Is.EqualTo(expectCloneUrl));
}
}

static IGitHubContextService CreateGitHubContextService()
Expand Down