public void SameContentEqualsTrue(string name1, string url1, string path1, string name2, string url2, string path2) { var a = new LocalRepositoryModel(name1, new UriString(url1), path1); var b = new LocalRepositoryModel(name2, new UriString(url2), path2); Assert.Equal(a, b); Assert.False(a == b); Assert.Equal(a.GetHashCode(), b.GetHashCode()); }
/// <inheritdoc/> public async Task <bool> IsUnmodifiedAndPushed(LocalRepositoryModel repository, string relativePath, byte[] contents) { using (var repo = await GetRepository(repository)) { var modified = await gitClient.IsModified(repo, relativePath, contents); var pushed = await gitClient.IsHeadPushed(repo); return(!modified && pushed); } }
public void NoRemoteUrl() { using (var temp = new TempDirectory()) { var gitService = Substitute.For <IGitService>(); var repo = Substitute.For <IRepository>(); var path = temp.Directory.CreateSubdirectory("repo-name"); gitService.GetUri(path.FullName).Returns((UriString)null); var model = new LocalRepositoryModel(path.FullName, gitService); Assert.That("repo-name", Is.EqualTo(model.Name)); } }
static async Task <PullRequestListViewModel> CreateTargetAndInitialize( IPullRequestSessionManager sessionManager = null, IRepositoryService repositoryService = null, IPullRequestService service = null, LocalRepositoryModel repository = null, IConnection connection = null) { var result = CreateTarget(sessionManager, repositoryService, service); await result.InitializeAsync(repository, connection); return(result); }
public async Task <bool> SyncSubmodules(LocalRepositoryModel repository, Action <string> progress) { var exitCode = await Where("git"); if (exitCode != 0) { progress(Resources.CouldntFindGitOnPath); return(false); } return(await SyncSubmodules(repository.LocalPath, progress) == 0); }
public IObservable <BranchModel> GetLocalBranches(LocalRepositoryModel repository, PullRequestDetailModel pullRequest) { return(Observable.Defer(() => { // BranchModel doesn't keep a reference to rep using (var repo = gitService.GetRepository(repository.LocalPath)) { var result = GetLocalBranchesInternal(repository, repo, pullRequest).Select(x => new BranchModel(x, repository)); return result.ToList().ToObservable(); } })); }
/// <inheritdoc/> public async Task <PullRequestDetailModel> PostStandaloneReviewCommentReply( LocalRepositoryModel localRepository, string pullRequestId, string body, string inReplyTo) { var(id, _, _) = await CreatePendingReviewCore(localRepository, pullRequestId); var comment = await PostPendingReviewCommentReply(localRepository, id, body, inReplyTo); return(await SubmitPendingReview(localRepository, id, null, PullRequestReviewEvent.Comment)); }
public async Task ShouldReturnPullRequestBranchForPullRequestFromSameRepositoryOwnerCaseMismatchAsync() { var service = CreateTarget(MockGitClient(), MockGitService()); var localRepo = new LocalRepositoryModel { CloneUrl = new UriString("https://github.com/Foo/bar") }; var result = await service.GetLocalBranches(localRepo, CreatePullRequest(fromFork : false)); Assert.That("source", Is.EqualTo(result.Name)); }
public async Task <string> GetMergeBase(LocalRepositoryModel repository, PullRequestDetailModel pullRequest) { using (var repo = gitService.GetRepository(repository.LocalPath)) { return(await gitClient.GetPullRequestMergeBase( repo, repository.CloneUrl.WithOwner(pullRequest.BaseRepositoryOwner), pullRequest.BaseRefSha, pullRequest.HeadRefSha, pullRequest.BaseRefName, pullRequest.Number)); } }
public IObservable <Unit> Push(LocalRepositoryModel repository) { return(Observable.Defer(async() => { using (var repo = gitService.GetRepository(repository.LocalPath)) { var remoteName = repo.Head.RemoteName; var remote = await gitClient.GetHttpRemote(repo, remoteName); await gitClient.Push(repo, repo.Head.TrackedBranch.UpstreamBranchCanonicalName, remote.Name); return Observable.Return(Unit.Default); } })); }
public void NoRemoteUrl() { using (var temp = new TempDirectory()) { var provider = Substitutes.ServiceProvider; var gitservice = provider.GetGitService(); var repo = Substitute.For<IRepository>(); var path = temp.Directory.CreateSubdirectory("repo-name"); gitservice.GetUri(path.FullName).Returns((UriString)null); var model = new LocalRepositoryModel(path.FullName); Assert.Equal("repo-name", model.Name); } }
public void NoRemoteUrl() { using (var temp = new TempDirectory()) { var provider = Substitutes.ServiceProvider; var gitservice = provider.GetGitService(); var repo = Substitute.For <IRepository>(); var path = temp.Directory.CreateSubdirectory("repo-name"); gitservice.GetUri(path.FullName).Returns((UriString)null); var model = new LocalRepositoryModel(path.FullName); Assert.Equal("repo-name", model.Name); } }
static async Task InitializeAsync( IPullRequestReviewAuthoringViewModel target, LocalRepositoryModel localRepository = null) { localRepository = localRepository ?? CreateLocalRepositoryModel(); await target.InitializeAsync( localRepository, Substitute.For <IConnection>(), "owner", "repo", 5); }
public void WithRemoteUrl() { using (var temp = new TempDirectory()) { var gitService = Substitute.For <IGitService>(); var repo = Substitute.For <IRepository>(); var path = temp.Directory.CreateSubdirectory("repo-name"); gitService.GetUri(path.FullName).Returns(new UriString("https://github.com/user/repo-name")); var model = new LocalRepositoryModel(path.FullName, gitService); Assert.That("repo-name", Is.EqualTo(model.Name)); Assert.That("user", Is.EqualTo(model.Owner)); } }
static IPullRequestSession CreateSession() { var author = Substitute.For <IAccount>(); var repository = new LocalRepositoryModel { LocalPath = @"C:\Foo" }; var result = Substitute.For <IPullRequestSession>(); result.LocalRepository.Returns(repository); result.PullRequest.Returns(new PullRequestDetailModel()); return(result); }
public IObservable <TreeChanges> GetTreeChanges(LocalRepositoryModel repository, PullRequestDetailModel pullRequest) { return(Observable.Defer(async() => { // TreeChanges doesn't keep a reference to Repository using (var repo = gitService.GetRepository(repository.LocalPath)) { var remote = await gitClient.GetHttpRemote(repo, "origin"); await gitClient.Fetch(repo, remote.Name); var changes = await gitClient.Compare(repo, pullRequest.BaseRefSha, pullRequest.HeadRefSha, detectRenames: true); return Observable.Return(changes); } })); }
public IObservable <bool> IsWorkingDirectoryClean(LocalRepositoryModel repository) { // The `using` appears to resolve this issue: // https://github.com/github/VisualStudio/issues/1306 using (var repo = gitService.GetRepository(repository.LocalPath)) { var statusOptions = new StatusOptions { ExcludeSubmodules = true }; var status = repo.RetrieveStatus(statusOptions); var isClean = !IsCheckoutBlockingDirty(status); return(Observable.Return(isClean)); } }
public void SameContentEqualsTrue(string name1, string url1, string path1, string name2, string url2, string path2) { var gitService = Substitute.For <IGitService>(); var a = new LocalRepositoryModel { Name = name1, CloneUrl = url1, LocalPath = path1 }; var b = new LocalRepositoryModel { Name = name2, CloneUrl = url2, LocalPath = path2 }; Assert.That(a, Is.EqualTo(b)); Assert.False(a == b); Assert.That(a.GetHashCode(), Is.EqualTo(b.GetHashCode())); }
/// <inheritdoc/> public async Task InitializeAsync(LocalRepositoryModel repository, IConnection connection) { try { LocalRepository = repository; SelectedState = States.FirstOrDefault(); AuthorFilter = new UserFilterViewModel(LoadAuthors); IsLoading = true; var parent = await repositoryService.FindParent( HostAddress.Create(repository.CloneUrl), repository.Owner, repository.Name); if (parent == null) { RemoteRepository = repository; } else { // TODO: Handle forks with different names. RemoteRepository = new RepositoryModel( repository.Name, UriString.ToUriString(repository.CloneUrl.ToRepositoryUrl(parent.Value.owner))); Forks = new RepositoryModel[] { RemoteRepository, repository, }; } this.WhenAnyValue(x => x.SelectedState, x => x.RemoteRepository) .Skip(1) .Subscribe(_ => Refresh().Forget()); Observable.Merge( this.WhenAnyValue(x => x.SearchQuery).Skip(1).SelectUnit(), AuthorFilter.WhenAnyValue(x => x.Selected).Skip(1).SelectUnit()) .Subscribe(_ => FilterChanged()); await Refresh(); } catch (Exception ex) { Error = ex; IsLoading = false; log.Error(ex, "Error initializing IssueListViewModelBase"); } }
public void CreatePullRequestAllArgsMandatory() { var serviceProvider = Substitutes.ServiceProvider; var gitService = serviceProvider.GetGitService(); var service = new PullRequestService( Substitute.For <IGitClient>(), serviceProvider.GetGitService(), Substitute.For <IVSGitExt>(), Substitute.For <IApiClientFactory>(), Substitute.For <IGraphQLClientFactory>(), serviceProvider.GetOperatingSystem(), Substitute.For <IUsageTracker>()); IModelService ms = null; LocalRepositoryModel sourceRepo = null; LocalRepositoryModel targetRepo = null; string title = null; string body = null; BranchModel source = null; BranchModel target = null; Assert.Throws <ArgumentNullException>(() => service.CreatePullRequest(ms, sourceRepo, targetRepo, source, target, title, body)); ms = Substitute.For <IModelService>(); Assert.Throws <ArgumentNullException>(() => service.CreatePullRequest(ms, sourceRepo, targetRepo, source, target, title, body)); sourceRepo = new LocalRepositoryModel { Name = "name", CloneUrl = "http://github.com/github/stuff", LocalPath = "c:\\path" }; Assert.Throws <ArgumentNullException>(() => service.CreatePullRequest(ms, sourceRepo, targetRepo, source, target, title, body)); targetRepo = new LocalRepositoryModel { Name = "name", CloneUrl = "http://github.com/github/stuff", LocalPath = "c:\\path" }; Assert.Throws <ArgumentNullException>(() => service.CreatePullRequest(ms, sourceRepo, targetRepo, source, target, title, body)); title = "a title"; Assert.Throws <ArgumentNullException>(() => service.CreatePullRequest(ms, sourceRepo, targetRepo, source, target, title, body)); body = "a body"; Assert.Throws <ArgumentNullException>(() => service.CreatePullRequest(ms, sourceRepo, targetRepo, source, target, title, body)); source = new BranchModel("source", sourceRepo); Assert.Throws <ArgumentNullException>(() => service.CreatePullRequest(ms, sourceRepo, targetRepo, source, target, title, body)); target = new BranchModel("target", targetRepo); var pr = service.CreatePullRequest(ms, sourceRepo, targetRepo, source, target, title, body); Assert.NotNull(pr); }
async Task RefreshCurrentSession(LocalRepositoryModel repository, IPullRequestSession session) { var showStatus = await IsDotComOrEnterpriseRepository(repository); if (!showStatus) { ShowStatus(null); return; } var viewModel = CreatePullRequestStatusViewModel(session); ShowStatus(viewModel); }
public void WithRemoteUrl() { using (var temp = new TempDirectory()) { var provider = Substitutes.ServiceProvider; var gitservice = provider.GetGitService(); var repo = Substitute.For<IRepository>(); var path = temp.Directory.CreateSubdirectory("repo-name"); gitservice.GetUri(path.FullName).Returns(new UriString("https://github.com/user/repo-name")); var model = new LocalRepositoryModel(path.FullName); Assert.Equal("repo-name", model.Name); Assert.Equal("user", model.Owner); } }
static async Task <Target> CreateTargetAndInitialize( IRepositoryService repositoryService = null, LocalRepositoryModel repository = null, IConnection connection = null, int itemCount = 1000) { repository = repository ?? CreateLocalRepository(); connection = connection ?? Substitute.For <IConnection>(); var target = CreateTarget(repositoryService, itemCount); await target.InitializeAsync(repository, connection); return(target); }
/// <inheritdoc/> public async Task <PullRequestDetailModel> CreatePendingReview( LocalRepositoryModel localRepository, string pullRequestId) { var address = HostAddress.Create(localRepository.CloneUrl.Host); var graphql = await graphqlFactory.CreateConnection(address); var(_, owner, number) = await CreatePendingReviewCore(localRepository, pullRequestId); var detail = await ReadPullRequestDetail(address, owner, localRepository.Name, number); await usageTracker.IncrementCounter(x => x.NumberOfPRReviewDiffViewInlineCommentStartReview); return(detail); }
public async Task <string> GetGraphQLPullRequestId( LocalRepositoryModel localRepository, string repositoryOwner, int number) { var address = HostAddress.Create(localRepository.CloneUrl.Host); var graphql = await graphqlFactory.CreateConnection(address); var query = new Query() .Repository(repositoryOwner, localRepository.Name) .PullRequest(number) .Select(x => x.Id); return((await graphql.Run(query)).Value); }
async Task RepoChanged(LocalRepositoryModel localRepositoryModel) { repository = localRepositoryModel; CurrentSession = null; sessions.Clear(); if (localRepositoryModel != null) { await StatusChanged(); } else { initialized.TrySetResult(null); } }
public Encoding GetEncoding(LocalRepositoryModel repository, string relativePath) { var fullPath = Path.Combine(repository.LocalPath, relativePath); if (File.Exists(fullPath)) { var encoding = Encoding.UTF8; if (HasPreamble(fullPath, encoding)) { return(encoding); } } return(null); }
void HandleClonedRepo(LocalRepositoryModel newrepo) { Guard.ArgumentNotNull(newrepo, nameof(newrepo)); var msg = string.Format(CultureInfo.CurrentCulture, Constants.Notification_RepoCloned, newrepo.Name, newrepo.CloneUrl); if (newrepo.HasCommits() && newrepo.MightContainSolution()) { msg += " " + string.Format(CultureInfo.CurrentCulture, Constants.Notification_OpenProject, newrepo.LocalPath); } else { msg += " " + string.Format(CultureInfo.CurrentCulture, Constants.Notification_CreateNewProject, newrepo.LocalPath); } ShowNotification(newrepo, msg); }
public IObservable <IPullRequestModel> CreatePullRequest(IModelService modelService, LocalRepositoryModel sourceRepository, RepositoryModel targetRepository, BranchModel sourceBranch, BranchModel targetBranch, string title, string body ) { Extensions.Guard.ArgumentNotNull(modelService, nameof(modelService)); Extensions.Guard.ArgumentNotNull(sourceRepository, nameof(sourceRepository)); Extensions.Guard.ArgumentNotNull(targetRepository, nameof(targetRepository)); Extensions.Guard.ArgumentNotNull(sourceBranch, nameof(sourceBranch)); Extensions.Guard.ArgumentNotNull(targetBranch, nameof(targetBranch)); Extensions.Guard.ArgumentNotNull(title, nameof(title)); Extensions.Guard.ArgumentNotNull(body, nameof(body)); return(PushAndCreatePR(modelService, sourceRepository, targetRepository, sourceBranch, targetBranch, title, body).ToObservable()); }
public IObservable <IReadOnlyList <CommitMessage> > GetMessagesForUniqueCommits( LocalRepositoryModel repository, string baseBranch, string compareBranch, int maxCommits) { return(Observable.Defer(async() => { // CommitMessage doesn't keep a reference to Repository using (var repo = gitService.GetRepository(repository.LocalPath)) { var messages = await gitClient.GetMessagesForUniqueCommits(repo, baseBranch, compareBranch, maxCommits); return Observable.Return(messages); } })); }
public async Task ShouldReturnCorrectDefaultLocalBranchNameForPullRequestsWithNonLatinCharsAsync() { var service = new PullRequestService( MockGitClient(), MockGitService(), Substitute.For <IVSGitExt>(), Substitute.For <IGraphQLClientFactory>(), Substitute.For <IOperatingSystem>(), Substitute.For <IUsageTracker>()); var localRepo = new LocalRepositoryModel { }; var result = await service.GetDefaultLocalBranchName(localRepo, 123, "コードをレビューする準備ができたこと"); Assert.That("pr/123", Is.EqualTo(result)); }
public LocalRepositoryModel CreateLocalRepositoryModel(string localPath) { var result = new LocalRepositoryModel { LocalPath = localPath }; if (localPath == "repo1") { // Trying to force #1493 here by introducing a a delay on the first // ActiveRepositories changed notification so that the second completes // first. Thread.Sleep(10); } return(result); }
public async Task ShouldRemoveUnusedRemoteAsync() { var gitClient = MockGitClient(); var gitService = MockGitService(); var service = CreateTarget(gitClient, gitService); var localRepo = new LocalRepositoryModel { CloneUrl = new UriString("https://github.com/foo/bar") }; using (var repo = gitService.GetRepository(localRepo.CloneUrl)) { var remote1 = Substitute.For <Remote>(); var remote2 = Substitute.For <Remote>(); var remote3 = Substitute.For <Remote>(); var remotes = new List <Remote> { remote1, remote2, remote3 }; var remoteCollection = Substitute.For <RemoteCollection>(); remote1.Name.Returns("remote1"); remote2.Name.Returns("remote2"); remote3.Name.Returns("remote3"); remoteCollection.GetEnumerator().Returns(_ => remotes.GetEnumerator()); repo.Network.Remotes.Returns(remoteCollection); var branch1 = Substitute.For <LibGit2Sharp.Branch>(); var branch2 = Substitute.For <LibGit2Sharp.Branch>(); var branches = new List <LibGit2Sharp.Branch> { branch1, branch2 }; var branchCollection = Substitute.For <BranchCollection>(); branch1.RemoteName.Returns("remote1"); branch2.RemoteName.Returns("remote1"); branchCollection.GetEnumerator().Returns(_ => branches.GetEnumerator()); repo.Branches.Returns(branchCollection); gitClient.GetConfig <bool>(Arg.Any <IRepository>(), "remote.remote1.created-by-ghfvs").Returns(Task.FromResult(true)); gitClient.GetConfig <bool>(Arg.Any <IRepository>(), "remote.remote2.created-by-ghfvs").Returns(Task.FromResult(true)); await service.RemoveUnusedRemotes(localRepo); remoteCollection.DidNotReceive().Remove("remote1"); remoteCollection.Received().Remove("remote2"); remoteCollection.DidNotReceive().Remove("remote3"); } }
public async void GenerateUrl(int testid, bool createRootedPath, string baseUrl, string sha, string path, int startLine, int endLine, string expected) { using (var temp = new TempDirectory()) { SetupRepository(sha); var basePath = temp.Directory.CreateSubdirectory("generate-url-test1-" + testid); if (createRootedPath && path != null) path = System.IO.Path.Combine(basePath.FullName, path); ILocalRepositoryModel model = null; if (!String.IsNullOrEmpty(baseUrl)) model = new LocalRepositoryModel("bar", new UriString(baseUrl), basePath.FullName); else model = new LocalRepositoryModel(basePath.FullName); var result = await model.GenerateUrl(path, startLine, endLine); Assert.Equal(expected, result?.ToString()); } }
public void CreatePullRequestAllArgsMandatory() { var serviceProvider = Substitutes.ServiceProvider; var service = new PullRequestService(Substitute.For<IGitClient>(), serviceProvider.GetGitService(), serviceProvider.GetOperatingSystem(), Substitute.For<IUsageTracker>()); IRepositoryHost host = null; ILocalRepositoryModel sourceRepo = null; ILocalRepositoryModel targetRepo = null; string title = null; string body = null; IBranch source = null; IBranch target = null; Assert.Throws<ArgumentNullException>(() => service.CreatePullRequest(host, sourceRepo, targetRepo, source, target, title, body)); host = serviceProvider.GetRepositoryHosts().GitHubHost; Assert.Throws<ArgumentNullException>(() => service.CreatePullRequest(host, sourceRepo, targetRepo, source, target, title, body)); sourceRepo = new LocalRepositoryModel("name", new GitHub.Primitives.UriString("http://github.com/github/stuff"), "c:\\path"); Assert.Throws<ArgumentNullException>(() => service.CreatePullRequest(host, sourceRepo, targetRepo, source, target, title, body)); targetRepo = new LocalRepositoryModel("name", new GitHub.Primitives.UriString("http://github.com/github/stuff"), "c:\\path"); Assert.Throws<ArgumentNullException>(() => service.CreatePullRequest(host, sourceRepo, targetRepo, source, target, title, body)); title = "a title"; Assert.Throws<ArgumentNullException>(() => service.CreatePullRequest(host, sourceRepo, targetRepo, source, target, title, body)); body = "a body"; Assert.Throws<ArgumentNullException>(() => service.CreatePullRequest(host, sourceRepo, targetRepo, source, target, title, body)); source = new BranchModel("source", sourceRepo); Assert.Throws<ArgumentNullException>(() => service.CreatePullRequest(host, sourceRepo, targetRepo, source, target, title, body)); target = new BranchModel("target", targetRepo); var pr = service.CreatePullRequest(host, sourceRepo, targetRepo, source, target, title, body); Assert.NotNull(pr); }