public async Task InitializeAsync( ILocalRepositoryModel localRepository, IConnection connection, string owner, string repo, int pullRequestNumber) { if (repo != localRepository.Name) { throw new NotSupportedException(); } IsLoading = true; try { LocalRepository = localRepository; RemoteRepositoryOwner = owner; modelService = await modelServiceFactory.CreateAsync(connection); var pullRequest = await modelService.GetPullRequest( RemoteRepositoryOwner, LocalRepository.Name, pullRequestNumber); await Load(pullRequest); } finally { IsLoading = false; } }
public async Task InitializeAsync(IConnection connection) { modelService = await modelServiceFactory.CreateAsync(connection); Title = string.Format(CultureInfo.CurrentCulture, Resources.CreateTitle, connection.HostAddress.Title); accounts = modelService.GetAccounts() .ObserveOn(RxApp.MainThreadScheduler) .ToProperty(this, vm => vm.Accounts, initialValue: new ReadOnlyCollection <IAccount>(new IAccount[] { })); this.WhenAny(x => x.Accounts, x => x.Value) .Select(accts => accts?.FirstOrDefault()) .WhereNotNull() .Subscribe(a => SelectedAccount = a); GitIgnoreTemplates = TrackingCollection.CreateListenerCollectionAndRun( modelService.GetGitIgnoreTemplates(), new[] { GitIgnoreItem.None }, OrderedComparer <GitIgnoreItem> .OrderByDescending(item => GitIgnoreItem.IsRecommended(item.Name)).Compare, x => { if (x.Name.Equals("VisualStudio", StringComparison.OrdinalIgnoreCase)) { SelectedGitIgnoreTemplate = x; } }); Licenses = TrackingCollection.CreateListenerCollectionAndRun( modelService.GetLicenses(), new[] { LicenseItem.None }, OrderedComparer <LicenseItem> .OrderByDescending(item => LicenseItem.IsRecommended(item.Name)).Compare); }
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 async Task InitializeAsync(LocalRepositoryModel repository, IConnection connection) { IsLoading = true; try { var modelService = await modelServiceFactory.CreateAsync(connection); Observable.CombineLatest( modelService.GetAccounts(), modelService.GetRepository(repository.Owner, repository.Name), modelService.GetForks(repository).ToList(), (a, r, f) => new { Accounts = a, Respoitory = r, Forks = f }) .Finally(() => IsLoading = false) .Subscribe(x => { var forks = x.Forks; var parents = new List <RemoteRepositoryModel>(); var current = x.Respoitory; while (current.Parent != null) { parents.Add(current.Parent); current = current.Parent; } BuildAccounts(x.Accounts, repository, forks, parents); }); } catch (Exception ex) { log.Error(ex, "Error initializing ForkRepositoryViewModel"); IsLoading = false; } }
public async Task InitializeAsync(LocalRepositoryModel repository, IConnection connection) { modelService = await modelServiceFactory.CreateAsync(connection); activeLocalRepo = repository; SourceBranch = gitService.GetBranch(repository); var obs = modelService.ApiClient.GetRepository(repository.Owner, repository.Name) .Select(r => CreateRemoteRepositoryModel(r)) .PublishLast(); disposables.Add(obs.Connect()); var githubObs = obs; githubRepository = githubObs.ToProperty(this, x => x.GitHubRepository); this.WhenAnyValue(x => x.GitHubRepository) .WhereNotNull() .Subscribe(r => { TargetBranch = r.IsFork ? r.Parent.DefaultBranch : r.DefaultBranch; }); githubObs.SelectMany(r => { var b = Observable.Empty <BranchModel>(); if (r.IsFork) { b = modelService.GetBranches(r.Parent).Select(x => { return(x); }); } return(b.Concat(modelService.GetBranches(r))); }) .ToList() .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(x => { Branches = x.ToList(); Initialized = true; }); var draftKey = GetDraftKey(); await LoadInitialState(draftKey).ConfigureAwait(true); this.WhenAnyValue( x => x.PRTitle, x => x.Description, (t, d) => new PullRequestDraft { Title = t, Body = d }) .Throttle(TimeSpan.FromSeconds(1), timerScheduler) .Subscribe(x => draftStore.UpdateDraft(draftKey, string.Empty, x)); Initialized = true; }
public static async Task <IModelService> GetModelService( this IConnectionManager cm, LocalRepositoryModel repository, IModelServiceFactory factory) { var connection = await cm.GetConnection(repository); return(connection?.IsLoggedIn == true ? await factory.CreateAsync(connection) : null); }
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); }); }
public static async Task <IModelService> GetModelService( this IConnectionManager cm, ILocalRepositoryModel repository, IModelServiceFactory factory) { var connection = await cm.LookupConnection(repository); return(connection != null ? await factory.CreateAsync(connection) : null); }
public async Task InitializeAsync(IConnection connection) { var modelService = await modelServiceFactory.CreateAsync(connection); apiClient = modelService.ApiClient; // This class is only instantiated after we are logged into to a github account, so we should be safe to grab the first one here as the defaut. account = modelService.GetAccounts() .FirstAsync() .Select(a => a.First()) .ObserveOn(RxApp.MainThreadScheduler) .ToProperty(this, vm => vm.Account); }
public async Task InitializeAsync(ILocalRepositoryModel sourceRepository, IAccount destinationAccount, IConnection connection) { var modelService = await modelServiceFactory.CreateAsync(connection); apiClient = modelService.ApiClient; DestinationAccount = destinationAccount; SourceRepository = sourceRepository; DestinationRepository = new RemoteRepositoryModel( 0, sourceRepository.Name, CreateForkUri(sourceRepository.CloneUrl, destinationAccount.Login), false, true, destinationAccount, null); }
public async Task InitializeAsync(IConnection connection) { modelService = await modelServiceFactory.CreateAsync(connection).ConfigureAwait(true); Title = string.Format(CultureInfo.CurrentCulture, Resources.CreateTitle, connection.HostAddress.Title); accounts = modelService.GetAccounts() .ObserveOn(RxApp.MainThreadScheduler) .ToProperty(this, vm => vm.Accounts, initialValue: new ReadOnlyCollection <IAccount>(Array.Empty <IAccount>())); this.WhenAny(x => x.Accounts, x => x.Value) .Select(accts => accts?.FirstOrDefault()) .WhereNotNull() .Subscribe(a => SelectedAccount = a); modelService.GetGitIgnoreTemplates() .Where(x => x != null) .ToList() .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(x => { var sorted = x .Distinct() .OrderByDescending(item => item.Recommended) .ThenBy(item => item.Name); GitIgnoreTemplates = new[] { GitIgnoreItem.None }.Concat(sorted).ToList(); SelectedGitIgnoreTemplate = GitIgnoreTemplates .FirstOrDefault(i => i?.Name.Equals("VisualStudio", StringComparison.OrdinalIgnoreCase) == true); }); modelService.GetLicenses() .Where(x => x != null) .ToList() .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(x => { var sorted = x .Distinct() .OrderByDescending(item => item.Recommended) .ThenBy(item => item.Key); Licenses = new[] { LicenseItem.None }.Concat(sorted).ToList(); }); }
public async Task InitializeAsync(IConnection connection) { var modelService = await modelServiceFactory.CreateAsync(connection); Title = string.Format(CultureInfo.CurrentCulture, Resources.CloneTitle, connection.HostAddress.Title); IsBusy = true; modelService.GetRepositories(repositories); repositories.OriginalCompleted .ObserveOn(RxApp.MainThreadScheduler) .Subscribe( _ => { } , ex => { LoadingFailed = true; IsBusy = false; log.Error(ex, "Error while loading repositories"); }, () => IsBusy = false ); repositories.Subscribe(); }
/// <inheritdoc/> public async Task InitializeAsync( LocalRepositoryModel localRepository, IConnection connection, string owner, string repo, int number) { IsLoading = true; try { if (!string.Equals(repo, localRepository.Name, StringComparison.OrdinalIgnoreCase)) { throw new NotSupportedException("Showing pull requests from other repositories not yet supported."); } LocalRepository = localRepository; RemoteRepositoryOwner = owner; Number = number; WebUrl = localRepository.CloneUrl.ToRepositoryUrl(owner).Append("pull/" + number); modelService = await modelServiceFactory.CreateAsync(connection); Session = await sessionManager.GetSession(owner, repo, number); await Load(Session.PullRequest); teamExplorerContext.StatusChanged += RefreshIfActive; } catch (Exception ex) { Error = ex; } finally { IsLoading = false; } }
public RepositoryPublishViewModel( IRepositoryPublishService repositoryPublishService, INotificationService notificationService, IConnectionManager connectionManager, IModelServiceFactory modelServiceFactory, IDialogService dialogService, IUsageTracker usageTracker) { Guard.ArgumentNotNull(repositoryPublishService, nameof(repositoryPublishService)); Guard.ArgumentNotNull(notificationService, nameof(notificationService)); Guard.ArgumentNotNull(connectionManager, nameof(connectionManager)); Guard.ArgumentNotNull(usageTracker, nameof(usageTracker)); Guard.ArgumentNotNull(modelServiceFactory, nameof(modelServiceFactory)); Guard.ArgumentNotNull(dialogService, nameof(dialogService)); this.notificationService = notificationService; this.usageTracker = usageTracker; this.modelServiceFactory = modelServiceFactory; this.dialogService = dialogService; Connections = connectionManager.Connections; this.repositoryPublishService = repositoryPublishService; if (Connections.Any()) { SelectedConnection = Connections.FirstOrDefault(x => x.HostAddress.IsGitHubDotCom()) ?? Connections[0]; } accounts = this.WhenAnyValue(x => x.SelectedConnection) .Where(x => x != null) .SelectMany(async c => (await modelServiceFactory.CreateAsync(c)).GetAccounts()) .Switch() .ObserveOn(RxApp.MainThreadScheduler) .ToProperty(this, x => x.Accounts, initialValue: new ReadOnlyCollection <IAccount>(Array.Empty <IAccount>())); this.WhenAny(x => x.Accounts, x => x.Value) .WhereNotNull() .Where(accts => accts.Any()) .Subscribe(accts => { var selectedAccount = accts.FirstOrDefault(); if (selectedAccount != null) { SelectedAccount = accts.FirstOrDefault(); } }); isHostComboBoxVisible = this.WhenAny(x => x.Connections, x => x.Value) .WhereNotNull() .Select(h => h.Count > 1) .ToProperty(this, x => x.IsHostComboBoxVisible); InitializeValidation(); PublishRepository = InitializePublishRepositoryCommand(); PublishRepository.IsExecuting.Subscribe(x => IsBusy = x); LoginAsDifferentUser = ReactiveCommand.CreateFromTask(LoginAsDifferentUserAsync); var defaultRepositoryName = repositoryPublishService.LocalRepositoryName; if (!string.IsNullOrEmpty(defaultRepositoryName)) { RepositoryName = defaultRepositoryName; } this.WhenAny(x => x.SelectedConnection, x => x.SelectedAccount, (a, b) => true) .Where(x => RepositoryNameValidator.ValidationResult != null && SafeRepositoryNameWarningValidator.ValidationResult != null) .Subscribe(async _ => { var name = RepositoryName; RepositoryName = null; await RepositoryNameValidator.ResetAsync(); await SafeRepositoryNameWarningValidator.ResetAsync(); RepositoryName = name; }); }
public async Task InitializeAsync(ILocalRepositoryModel repository, IConnection connection) { modelService = await modelServiceFactory.CreateAsync(connection); activeLocalRepo = repository; SourceBranch = repository.CurrentBranch; var obs = modelService.ApiClient.GetRepository(repository.Owner, repository.Name) .Select(r => new RemoteRepositoryModel(r)) .PublishLast(); disposables.Add(obs.Connect()); var githubObs = obs; githubRepository = githubObs.ToProperty(this, x => x.GitHubRepository); this.WhenAnyValue(x => x.GitHubRepository) .WhereNotNull() .Subscribe(r => { TargetBranch = r.IsFork ? r.Parent.DefaultBranch : r.DefaultBranch; }); githubObs.SelectMany(r => { var b = Observable.Empty <IBranch>(); if (r.IsFork) { b = modelService.GetBranches(r.Parent).Select(x => { return(x); }); } return(b.Concat(modelService.GetBranches(r))); }) .ToList() .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(x => { Branches = x.ToList(); Initialized = true; }); SourceBranch = activeLocalRepo.CurrentBranch; var uniqueCommits = this.WhenAnyValue( x => x.SourceBranch, x => x.TargetBranch) .Where(x => x.Item1 != null && x.Item2 != null) .Select(branches => { var baseBranch = branches.Item1.Name; var compareBranch = branches.Item2.Name; // We only need to get max two commits for what we're trying to achieve here. // If there's no commits we want to block creation of the PR, if there's one commits // we wan't to use its commit message as the PR title/body and finally if there's more // than one we'll use the branch name for the title. return(service.GetMessagesForUniqueCommits(activeLocalRepo, baseBranch, compareBranch, maxCommits: 2) .Catch <IReadOnlyList <CommitMessage>, Exception>(ex => { log.Warning(ex, "Could not load unique commits"); return Observable.Empty <IReadOnlyList <CommitMessage> >(); })); }) .Switch() .ObserveOn(RxApp.MainThreadScheduler) .Replay(1) .RefCount(); Observable.CombineLatest( this.WhenAnyValue(x => x.SourceBranch), uniqueCommits, service.GetPullRequestTemplate(repository).DefaultIfEmpty(string.Empty), (compare, commits, template) => new { compare, commits, template }) .Subscribe(x => { var prTitle = string.Empty; var prDescription = string.Empty; if (x.commits.Count == 1) { prTitle = x.commits[0].Summary; prDescription = x.commits[0].Details; } else { prTitle = x.compare.Name.Humanize(); } if (!string.IsNullOrWhiteSpace(x.template)) { if (!string.IsNullOrEmpty(prDescription)) { prDescription += "\n\n"; } prDescription += x.template; } PRTitle = prTitle; Description = prDescription; }); Initialized = true; }
public RepositoryPublishViewModel( IRepositoryPublishService repositoryPublishService, INotificationService notificationService, IConnectionManager connectionManager, IModelServiceFactory modelServiceFactory, IUsageTracker usageTracker) { Guard.ArgumentNotNull(repositoryPublishService, nameof(repositoryPublishService)); Guard.ArgumentNotNull(notificationService, nameof(notificationService)); Guard.ArgumentNotNull(connectionManager, nameof(connectionManager)); Guard.ArgumentNotNull(usageTracker, nameof(usageTracker)); Guard.ArgumentNotNull(modelServiceFactory, nameof(modelServiceFactory)); this.notificationService = notificationService; this.usageTracker = usageTracker; this.modelServiceFactory = modelServiceFactory; title = this.WhenAny( x => x.SelectedConnection, x => x.Value != null ? string.Format(CultureInfo.CurrentCulture, Resources.PublishToTitle, x.Value.HostAddress.Title) : Resources.PublishTitle ) .ToProperty(this, x => x.Title); Connections = connectionManager.Connections; this.repositoryPublishService = repositoryPublishService; if (Connections.Any()) { SelectedConnection = Connections.FirstOrDefault(x => x.HostAddress.IsGitHubDotCom()) ?? Connections[0]; } accounts = this.WhenAnyValue(x => x.SelectedConnection) .Where(x => x != null) .SelectMany(async c => (await modelServiceFactory.CreateAsync(c)).GetAccounts()) .Switch() .ObserveOn(RxApp.MainThreadScheduler) .ToProperty(this, x => x.Accounts, initialValue: new ReadOnlyCollection <IAccount>(new IAccount[] {})); this.WhenAny(x => x.Accounts, x => x.Value) .WhereNotNull() .Where(accts => accts.Any()) .Subscribe(accts => { var selectedAccount = accts.FirstOrDefault(); if (selectedAccount != null) { SelectedAccount = accts.FirstOrDefault(); } }); isHostComboBoxVisible = this.WhenAny(x => x.Connections, x => x.Value) .WhereNotNull() .Select(h => h.Count > 1) .ToProperty(this, x => x.IsHostComboBoxVisible); InitializeValidation(); PublishRepository = InitializePublishRepositoryCommand(); canKeepPrivate = CanKeepPrivateObservable.CombineLatest(PublishRepository.IsExecuting, (canKeep, publishing) => canKeep && !publishing) .ToProperty(this, x => x.CanKeepPrivate); PublishRepository.IsExecuting.Subscribe(x => IsBusy = x); var defaultRepositoryName = repositoryPublishService.LocalRepositoryName; if (!string.IsNullOrEmpty(defaultRepositoryName)) { RepositoryName = defaultRepositoryName; } this.WhenAny(x => x.SelectedConnection, x => x.SelectedAccount, (a, b) => true) .Where(x => RepositoryNameValidator.ValidationResult != null && SafeRepositoryNameWarningValidator.ValidationResult != null) .Subscribe(async _ => { var name = RepositoryName; RepositoryName = null; await RepositoryNameValidator.ResetAsync(); await SafeRepositoryNameWarningValidator.ResetAsync(); RepositoryName = name; }); }