public async Task LoadsRepositories() { var repos = new IRemoteRepositoryModel[] { Substitute.For <IRemoteRepositoryModel>(), Substitute.For <IRemoteRepositoryModel>(), Substitute.For <IRemoteRepositoryModel>() }; var col = TrackingCollection.Create(repos.ToObservable()); var repositoryHost = Substitute.For <IRepositoryHost>(); repositoryHost.ModelService.GetRepositories(Arg.Any <ITrackingCollection <IRemoteRepositoryModel> >()).Returns(_ => col); var cloneService = Substitute.For <IRepositoryCloneService>(); var vm = GetVM( repositoryHost, cloneService, Substitute.For <IOperatingSystem>(), Substitute.For <INotificationService>(), Substitute.For <IUsageTracker>()); await col.OriginalCompleted; Assert.Equal(3, vm.Repositories.Count); }
public async Task InitializeAsync(ILocalRepositoryModel repository, IConnection connection) { IsLoading = true; try { modelService = await modelServiceFactory.CreateAsync(connection); listSettings = settings.UIState .GetOrCreateRepositoryState(repository.CloneUrl) .PullRequests; localRepository = repository; remoteRepository = await modelService.GetRepository( localRepository.Owner, localRepository.Name); Repositories = remoteRepository.IsFork ? new[] { remoteRepository.Parent, remoteRepository } : new[] { remoteRepository }; SelectedState = States.FirstOrDefault(x => x.Name == listSettings.SelectedState) ?? States[0]; // Setting SelectedRepository will cause a Load(). SelectedRepository = Repositories[0]; } finally { IsLoading = false; } }
public void CopyFrom(IRemoteRepositoryModel other) { if (!Equals(other)) { throw new ArgumentException("Instance to copy from doesn't match this instance. this:(" + this + ") other:(" + other + ")", nameof(other)); } Icon = other.Icon; }
public bool Equals([AllowNull] IRemoteRepositoryModel other) { if (ReferenceEquals(this, other)) { return(true); } return(other != null && Id == other.Id); }
async Task Load() { IsBusy = true; if (modelService == null) { modelService = await modelServiceFactory.CreateAsync(connection); } if (remoteRepository == null) { remoteRepository = await modelService.GetRepository( localRepository.Owner, localRepository.Name); Repositories = remoteRepository.IsFork ? new[] { remoteRepository.Parent, remoteRepository } : new[] { remoteRepository }; SelectedRepository = Repositories[0]; } PullRequests = modelService.GetPullRequests(SelectedRepository, pullRequests); pullRequests.Subscribe(pr => { trackingAssignees.AddItem(pr.Assignee); trackingAuthors.AddItem(pr.Author); }, () => { }); pullRequests.OriginalCompleted .ObserveOn(RxApp.MainThreadScheduler) ////.Catch<System.Reactive.Unit, Octokit.AuthorizationException>(ex => ////{ //// log.Info("Received AuthorizationException reading pull requests", ex); //// return repositoryHost.LogOut(); ////}) .Catch <System.Reactive.Unit, Exception>(ex => { // Occurs on network error, when the repository was deleted on GitHub etc. log.Error(ex, "Received Exception reading pull requests"); return(Observable.Empty <System.Reactive.Unit>()); }) .Subscribe(_ => { if (listSettings.SelectedAuthor != null) { SelectedAuthor = Authors.FirstOrDefault(x => x.Login == listSettings.SelectedAuthor); } if (listSettings.SelectedAssignee != null) { SelectedAssignee = Assignees.FirstOrDefault(x => x.Login == listSettings.SelectedAssignee); } IsBusy = false; UpdateFilter(SelectedState, SelectedAssignee, SelectedAuthor, SearchQuery); }); }
bool FilterRepository(IRemoteRepositoryModel repo, int position, IList <IRemoteRepositoryModel> list) { if (string.IsNullOrWhiteSpace(FilterText)) { return(true); } // Not matching on NameWithOwner here since that's already been filtered on by the selected account return(repo.Name.IndexOf(FilterText ?? "", StringComparison.OrdinalIgnoreCase) != -1); }
/// <summary> /// Initializes a new instance of the <see cref="RemoteRepositoryModel"/> class. /// </summary> /// <param name="id">The API ID of the repository.</param> /// <param name="name">The repository name.</param> /// <param name="cloneUrl">The repository's clone URL.</param> /// <param name="isPrivate">Whether the repository is private.</param> /// <param name="isFork">Whether the repository is a fork.</param> /// <param name="ownerAccount">The repository owner account.</param> /// <param name="parent">The parent repository if this repository is a fork.</param> public RemoteRepositoryModel(long id, string name, UriString cloneUrl, bool isPrivate, bool isFork, IAccount ownerAccount, IRemoteRepositoryModel parent) : base(name, cloneUrl) { Guard.ArgumentNotEmptyString(name, nameof(name)); Guard.ArgumentNotNull(ownerAccount, nameof(ownerAccount)); Id = id; OwnerAccount = ownerAccount; IsFork = isFork; SetIcon(isPrivate, isFork); // this is an assumption, we'd have to load the repo information from octokit to know for sure // probably not worth it for this ctor DefaultBranch = new BranchModel("master", this); Parent = parent; }
public async Task LoadsRepositories() { var repos = new IRemoteRepositoryModel[] { Substitute.For<IRemoteRepositoryModel>(), Substitute.For<IRemoteRepositoryModel>(), Substitute.For<IRemoteRepositoryModel>() }; var col = TrackingCollection.Create(repos.ToObservable()); var repositoryHost = Substitute.For<IRepositoryHost>(); repositoryHost.ModelService.GetRepositories(Arg.Any<ITrackingCollection<IRemoteRepositoryModel>>()).Returns(_ => col); var cloneService = Substitute.For<IRepositoryCloneService>(); var vm = GetVM( repositoryHost, cloneService, Substitute.For<IOperatingSystem>(), Substitute.For<INotificationService>(), Substitute.For<IUsageTracker>()); await col.OriginalCompleted; Assert.Equal(3, vm.Repositories.Count); }
public async Task LoadsRepositories() { var repos = new IRemoteRepositoryModel[] { CreateMockRepositoryModel(), CreateMockRepositoryModel(), CreateMockRepositoryModel(), }; var modelService = Substitute.For <IModelService>(); modelService.GetRepositories(Arg.Any <ITrackingCollection <IRemoteRepositoryModel> >()) .Returns(x => SetupRepositories(x, repos.ToObservable())); var cloneService = Substitute.For <IRepositoryCloneService>(); var vm = GetVM( modelService, cloneService, Substitute.For <IOperatingSystem>()); var col = (ITrackingCollection <IRemoteRepositoryModel>)vm.Repositories; await col.OriginalCompleted; Assert.Equal(3, vm.Repositories.Count); }
public void CopyFrom(IRemoteRepositoryModel other) { throw new NotImplementedException(); }
public int CompareTo([AllowNull] IRemoteRepositoryModel other) { return(other != null?UpdatedAt.CompareTo(other.UpdatedAt) : 1); }
public CloneRequest(string basePath, IRemoteRepositoryModel repository) { BasePath = basePath; Repository = repository; }
async Task <CodeContainer> RunAcquisition(IProgress <ServiceProgressData> downloadProgress, CancellationToken cancellationToken, IRemoteRepositoryModel repository) { CloneRequest request = null; try { var uiProvider = await Task.Run(() => Package.GetGlobalService(typeof(IUIProvider)) as IUIProvider); var cm = uiProvider.TryGetService <IConnectionManager>(); var gitRepositories = await GetGitRepositoriesExt(uiProvider); request = ShowCloneDialog(uiProvider, gitRepositories, repository); } catch { // TODO: log } if (request == null) { return(null); } var path = Path.Combine(request.BasePath, request.Repository.Name); var uri = request.Repository.CloneUrl.ToRepositoryUrl(); return(new CodeContainer( localProperties: new CodeContainerLocalProperties(path, CodeContainerType.Folder, new CodeContainerSourceControlProperties(request.Repository.Name, path, new Guid(Guids.GitSccProviderId))), remote: new RemoteCodeContainer(request.Repository.Name, new Guid(CodeContainerProviderId), uri, new Uri(uri.ToString().TrimSuffix(".git")), DateTimeOffset.UtcNow), isFavorite: false, lastAccessed: DateTimeOffset.UtcNow)); }
public void Initialize(ILocalRepositoryModel sourceRepository, IRemoteRepositoryModel remoteRepository) { SourceRepository = sourceRepository; DestinationRepository = remoteRepository; }
public void Initialize(ILocalRepositoryModel sourceRepository, IRemoteRepositoryModel remoteRepository) { }
public int CompareTo(IRemoteRepositoryModel other) { return(0); }
/// <summary> /// Loads the view model from octokit models. /// </summary> /// <param name="remoteRepository">The remote repository.</param> /// <param name="pullRequest">The pull request model.</param> public async Task Load(IRemoteRepositoryModel remoteRepository, IPullRequestModel pullRequest) { Guard.ArgumentNotNull(remoteRepository, nameof(remoteRepository)); try { var firstLoad = (Model == null); Model = pullRequest; RemoteRepository = remoteRepository; Session = await sessionManager.GetSession(pullRequest); Title = Resources.PullRequestNavigationItemText + " #" + pullRequest.Number; IsFromFork = !pullRequestsService.IsPullRequestFromRepository(LocalRepository, Model); SourceBranchDisplayName = GetBranchDisplayName(IsFromFork, pullRequest.Head?.Label); TargetBranchDisplayName = GetBranchDisplayName(IsFromFork, pullRequest.Base.Label); CommentCount = pullRequest.Comments.Count + pullRequest.ReviewComments.Count; Body = !string.IsNullOrWhiteSpace(pullRequest.Body) ? pullRequest.Body : Resources.NoDescriptionProvidedMarkdown; var changes = await pullRequestsService.GetTreeChanges(LocalRepository, pullRequest); ChangedFilesTree = (await CreateChangedFilesTree(pullRequest, changes)).Children.ToList(); var localBranches = await pullRequestsService.GetLocalBranches(LocalRepository, pullRequest).ToList(); IsCheckedOut = localBranches.Contains(LocalRepository.CurrentBranch); if (IsCheckedOut) { var divergence = await pullRequestsService.CalculateHistoryDivergence(LocalRepository, Model.Number); var pullEnabled = divergence.BehindBy > 0; var pushEnabled = divergence.AheadBy > 0 && !pullEnabled; string pullToolTip; string pushToolTip; if (pullEnabled) { pullToolTip = string.Format( Resources.PullRequestDetailsPullToolTip, IsFromFork ? Resources.Fork : Resources.Remote, SourceBranchDisplayName); } else { pullToolTip = Resources.NoCommitsToPull; } if (pushEnabled) { pushToolTip = string.Format( Resources.PullRequestDetailsPushToolTip, IsFromFork ? Resources.Fork : Resources.Remote, SourceBranchDisplayName); } else if (divergence.AheadBy == 0) { pushToolTip = Resources.NoCommitsToPush; } else { pushToolTip = Resources.MustPullBeforePush; } UpdateState = new UpdateCommandState(divergence, pullEnabled, pushEnabled, pullToolTip, pushToolTip); CheckoutState = null; } else { var caption = localBranches.Count > 0 ? string.Format(Resources.PullRequestDetailsCheckout, localBranches.First().DisplayName) : string.Format(Resources.PullRequestDetailsCheckoutTo, await pullRequestsService.GetDefaultLocalBranchName(LocalRepository, Model.Number, Model.Title)); var clean = await pullRequestsService.IsWorkingDirectoryClean(LocalRepository); string disabled = null; if (pullRequest.Head == null || !pullRequest.Head.RepositoryCloneUrl.IsValidUri) { disabled = Resources.SourceRepositoryNoLongerAvailable; } else if (!clean) { disabled = Resources.WorkingDirectoryHasUncommittedCHanges; } CheckoutState = new CheckoutCommandState(caption, disabled); UpdateState = null; } if (firstLoad) { usageTracker.IncrementPullRequestOpened().Forget(); } if (!isInCheckout) { pullRequestsService.RemoveUnusedRemotes(LocalRepository).Subscribe(_ => { }); } } catch (Exception ex) { log.Error(ex, "Error loading PullRequestModel"); ErrorMessage = ex.Message.Trim(); } finally { IsLoading = IsBusy = false; } }
public bool Equals(IRemoteRepositoryModel other) { throw new NotImplementedException(); }
bool FilterRepository(IRemoteRepositoryModel repo, int position, IList<IRemoteRepositoryModel> list) { if (string.IsNullOrWhiteSpace(FilterText)) return true; // Not matching on NameWithOwner here since that's already been filtered on by the selected account return repo.Name.IndexOf(FilterText ?? "", StringComparison.OrdinalIgnoreCase) != -1; }
CloneRequest ShowCloneDialog(IUIProvider uiProvider, IGitRepositoriesExt gitRepositories, IRemoteRepositoryModel repository = null) { string basePath = null; uiProvider.AddService(this, gitRepositories); var load = uiProvider.SetupUI(repository == null ? UIControllerFlow.Clone : UIControllerFlow.StartPageClone, null //TODO: set the connection corresponding to the repository if the repository is not null ); load.Subscribe(x => { if ((repository == null && x.Data.ViewType == Exports.UIViewType.Clone) || // fire the normal clone dialog (repository != null && x.Data.ViewType == Exports.UIViewType.StartPageClone) // fire the clone dialog for re-acquiring a repo ) { var vm = x.View.ViewModel as IBaseCloneViewModel; if (repository != null) { vm.SelectedRepository = repository; } x.View.Done.Subscribe(_ => { basePath = vm.BaseRepositoryPath; if (repository == null) { repository = vm.SelectedRepository; } }); } }); uiProvider.RunUI(); uiProvider.RemoveService(typeof(IGitRepositoriesExt), this); return(new CloneRequest(basePath, repository)); }
public int CompareTo(IRemoteRepositoryModel other) { throw new NotImplementedException(); }
void ShowSwitchRepositoryPath(IRemoteRepositoryModel remoteRepository) { switchPage.Initialize(Repository, remoteRepository); Content = switchPage; }
public bool Equals(IRemoteRepositoryModel other) { return(false); }
public void CopyFrom(IRemoteRepositoryModel other) { }