8000 Unify the repository list and URL tabs in the clone dialog by jcansdale · Pull Request #2197 · github/VisualStudio · GitHub
[go: up one dir, main page]

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

Unify the repository list and URL tabs in the clone dialog #2197

Merged
merged 16 commits into from
Feb 5, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Allow user to enter repository URL in filter
If user enters a valid repository URL, expose it as the selected
repository.
  • Loading branch information
jcansdale committed Jan 23, 2019
commit 5571cb7dd3c136cd1e5f92b6b15b428ef81ef450
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Reactive.Linq;
using System.Threading.Tasks;
using System.Windows.Data;
using GitHub.Exports;
using GitHub.Extensions;
using GitHub.Logging;
using GitHub.Models;
Expand All @@ -23,6 +24,7 @@ public class RepositorySelectViewModel : ViewModelBase, IRepositorySelectViewMod
{
static readonly ILogger log = LogManager.ForContext<RepositorySelectViewModel>();
readonly IRepositoryCloneService service;
readonly IGitHubContextService gitHubContextService;
IConnection connection;
Exception error;
string filter;
Expand All @@ -35,15 +37,26 @@ public class RepositorySelectViewModel : ViewModelBase, IRepositorySelectViewMod
IRepositoryItemViewModel selectedItem;

[ImportingConstructor]
public RepositorySelectViewModel(IRepositoryCloneService service)
public RepositorySelectViewModel(IRepositoryCloneService service, IGitHubContextService gitHubContextService)
{
Guard.ArgumentNotNull(service, nameof(service));
Guard.ArgumentNotNull(service, nameof(gitHubContextService));

this.service = service;
this.gitHubContextService = gitHubContextService;

repository = this.WhenAnyValue(x => x.SelectedItem)
.Select(CreateRepository)
var selectedRepository = this.WhenAnyValue(x => x.SelectedItem)
.Select(CreateRepository);

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));

repository = selectedRepository
.Merge(filterRepository)
.ToProperty(this, x => x.Repository);

this.WhenAnyValue(x => x.Filter).Subscribe(_ => ItemsView?.Refresh());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public async Task Filter(string filter, string owner, string name, string url, i
var hostAddress = HostAddress.GitHubDotComHostAddress;
var connection = CreateConnection(hostAddress);
var repositoryCloneService = CreateRepositoryCloneService(contributedToRepositories, hostAddress);
var target = new RepositorySelectViewModel(repositoryCloneService);
var gitHubContextService = CreateGitHubContextService();
var target = new RepositorySelectViewModel(repositoryCloneService, gitHubContextService);
target.Filter = filter;
target.Initialize(connection);

Expand All @@ -49,39 +50,63 @@ public async Task Filter(string filter, string owner, string name, string url, i
Assert.That(items.Count, Is.EqualTo(expectCount));
}

static IConnection CreateConnection(HostAddress hostAddress)
[TestCase("filter", null)]
[TestCase("https://github.com", null)]
[TestCase("https://github.com/github/VisualStudio", "https://github.com/github/VisualStudio")]
public void Set_Repository_When_Filter_Is_Url(string url, string expectUrl)
{
var connection = Substitute.For<IConnection>();
connection.HostAddress.Returns(hostAddress);
return connection;
}
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);

static IRepositoryCloneService CreateRepositoryCloneService(
IList<RepositoryListItemModel> contributedToRepositories,
HostAddress hostAddress)
{
var viewRepositoriesModel = CreateViewerRepositoriesModel(contributedToRepositories: contributedToRepositories);
var repositoryCloneService = Substitute.For<IRepositoryCloneService>();
repositoryCloneService.ReadViewerRepositories(hostAddress).Returns(viewRepositoriesModel);
return repositoryCloneService;
target.Filter = url;

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

private static ViewerRepositoriesModel CreateViewerRepositoriesModel(
string owner = "owner",
IList<RepositoryListItemModel> repositories = null,
IList<RepositoryListItemModel> contributedToRepositories = null)
{
repositories = repositories ?? Array.Empty<RepositoryListItemModel>();
contributedToRepositories = contributedToRepositories ?? Array.Empty<RepositoryListItemModel>();
static IGitHubContextService CreateGitHubContextService()
{
return Substitute.For<IGitHubContextService>();
}

return new ViewerRepositoriesModel
{
Owner = owner,
Repositories = CreateRepositoriesList(repositories),
ContributedToRepositories = CreateRepositoriesList(contributedToRepositories),
Organizations = CreateOrganizationsList()
};
}
static IConnection CreateConnection(HostAddress hostAddress)
{
var connection = Substitute.For<IConnection>();
connection.HostAddress.Returns(hostAddress);
return connection;
}

static IRepositoryCloneService CreateRepositoryCloneService(
IList<RepositoryListItemModel> contributedToRepositories = null,
HostAddress hostAddress = null)
{
contributedToRepositories = contributedToRepositories ?? Array.Empty<RepositoryListItemModel>();
hostAddress = hostAddress ?? HostAddress.GitHubDotComHostAddress;

var viewRepositoriesModel = CreateViewerRepositoriesModel(contributedToRepositories: contributedToRepositories);
var repositoryCloneService = Substitute.For<IRepositoryCloneService>();
repositoryCloneService.ReadViewerRepositories(hostAddress).Returns(viewRepositoriesModel);
return repositoryCloneService;
}

private static ViewerRepositoriesModel CreateViewerRepositoriesModel(
string owner = "owner",
IList<RepositoryListItemModel> repositories = null,
IList<RepositoryListItemModel> contributedToRepositories = null)
{
repositories = repositories ?? Array.Empty<RepositoryListItemModel>();
contributedToRepositories = contributedToRepositories ?? Array.Empty<RepositoryListItemModel>();

return new ViewerRepositoriesModel
{
Owner = owner,
Repositories = CreateRepositoriesList(repositories),
ContributedToRepositories = CreateRepositoriesList(contributedToRepositories),
Organizations = CreateOrganizationsList()
};
}

static IReadOnlyList<RepositoryListItemModel> CreateRepositoriesList(IList<RepositoryListItemModel> repositories)
Expand Down
0