public async Task <int> Run(RepositorySettings repository,
                                    UsernamePasswordCredentials gitCreds,
                                    Identity userIdentity,
                                    SettingsContainer settings)
        {
            try
            {
                var repo = await BuildGitRepositorySpec(repository, gitCreds.Username);

                if (repo == null)
                {
                    return(0);
                }

                if (!await _repositoryFilter.ContainsDotNetProjects(repository))
                {
                    return(0);
                }

                var tempFolder = _folderFactory.UniqueTemporaryFolder();
                var git        = new LibGit2SharpDriver(_logger, tempFolder, gitCreds, userIdentity);

                var updatesDone = await _repositoryUpdater.Run(git, repo, settings);

                tempFolder.TryDelete();
                return(updatesDone);
            }
            catch (Exception ex)
            {
                _logger.Error($"Failed on repo {repository.RepositoryName}", ex);
                return(0);
            }
        }
        public async Task <int> Run(RepositorySettings repository,
                                    UsernamePasswordCredentials gitCreds,
                                    Identity userIdentity,
                                    SettingsContainer settings)
        {
            try
            {
                var repo = await BuildGitRepositorySpec(repository, gitCreds.Username);

                if (repo == null)
                {
                    return(0);
                }

                // should perform the remote check for "is this a .NET repo"
                // (and also not a github fork)
                // only when we have multiple remote repos
                // otherwise it's ok to work locally, and check there
                if (!(settings.SourceControlServerSettings.Scope == ServerScope.Repository || repository.IsLocalRepo))
                {
                    var remoteRepoContainsDotNet = await _repositoryFilter.ContainsDotNetProjects(repository);

                    if (!remoteRepoContainsDotNet)
                    {
                        return(0);
                    }
                }

                IFolder folder;
                if (repository.IsLocalRepo)
                {
                    folder = new Folder(_logger, new DirectoryInfo(repository.RemoteInfo.LocalRepositoryUri.AbsolutePath));
                    settings.WorkingFolder = new Folder(_logger, new DirectoryInfo(repository.RemoteInfo.WorkingFolder.AbsolutePath));
                    repo.DefaultBranch     = repository.RemoteInfo.BranchName;
                    repo.Remote            = repository.RemoteInfo.RemoteName;
                }
                else
                {
                    folder = _folderFactory.UniqueTemporaryFolder();
                    settings.WorkingFolder = folder;
                }

                var git = new LibGit2SharpDriver(_logger, folder, gitCreds, userIdentity);

                var updatesDone = await _repositoryUpdater.Run(git, repo, settings);

                if (!repository.IsLocalRepo)
                {
                    folder.TryDelete();
                }

                return(updatesDone);
            }
            catch (Exception ex)
            {
                _logger.Error($"Failed on repo {repository.RepositoryName}", ex);
                return(1);
            }
        }
        public async Task ShouldNotFilterOutADotnetRepository()
        {
            IRepositoryFilter subject = MakeRepositoryFilter();

            var result =
                await subject.ContainsDotNetProjects(new RepositorySettings { RepositoryName = "sdk", RepositoryOwner = "dotnet" });

            Assert.True(result);
        }
        public async Task <int> Run(RepositorySettings repository,
                                    UsernamePasswordCredentials gitCreds,
                                    Identity userIdentity,
                                    SettingsContainer settings)
        {
            try
            {
                var repo = await BuildGitRepositorySpec(repository, gitCreds.Username);

                if (repo == null)
                {
                    return(0);
                }

                if (!repository.IsLocalRepo) // The updaters will do the check for the local files, and they know what file types they can handle.
                {
                    if (!await _repositoryFilter.ContainsDotNetProjects(repository))
                    {
                        return(0);
                    }
                }

                IFolder folder;
                if (repository.IsLocalRepo)
                {
                    folder = new Folder(_logger, new DirectoryInfo(repository.RemoteInfo.LocalRepositoryUri.AbsolutePath));
                    settings.WorkingFolder = new Folder(_logger, new DirectoryInfo(repository.RemoteInfo.WorkingFolder.AbsolutePath));
                    repo.DefaultBranch     = repository.RemoteInfo.BranchName;
                    repo.Remote            = repository.RemoteInfo.RemoteName;
                }
                else
                {
                    folder = _folderFactory.UniqueTemporaryFolder();
                    settings.WorkingFolder = folder;
                }

                var git = new LibGit2SharpDriver(_logger, folder, gitCreds, userIdentity);

                var updatesDone = await _repositoryUpdater.Run(git, repo, settings);

                if (!repository.IsLocalRepo)
                {
                    folder.TryDelete();
                }

                return(updatesDone);
            }
            catch (Exception ex)
            {
                _logger.Error($"Failed on repo {repository.RepositoryName}", ex);
                return(1);
            }
        }
        public async Task ShouldFilterOutNonDotnetRepository()
        {
            IRepositoryFilter subject = MakeRepositoryFilter();

            var result =
                await subject.ContainsDotNetProjects(new RepositorySettings
            {
                RepositoryName  = "jquery",
                RepositoryOwner = "jquery"
            });

            Assert.False(result);
        }
Exemple #6
0
        public async Task <int> Run(RepositorySettings repository,
                                    GitUsernamePasswordCredentials credentials,
                                    SettingsContainer settings, User user)
        {
            try
            {
                var repositoryData = await BuildGitRepositorySpec(repository, credentials.Username);

                if (repositoryData == null)
                {
                    return(0);
                }

                // should perform the remote check for "is this a .NET repo"
                // (and also not a github fork)
                // only when we have multiple remote repos
                // otherwise it's ok to work locally, and check there
                if (!(settings.SourceControlServerSettings.Scope == ServerScope.Repository || repository.IsLocalRepo))
                {
                    var remoteRepoContainsDotNet = await _repositoryFilter.ContainsDotNetProjects(repository);

                    if (!remoteRepoContainsDotNet)
                    {
                        return(0);
                    }
                }

                IFolder folder;
                if (repository.IsLocalRepo)
                {
                    folder = new Folder(_logger, new DirectoryInfo(repository.RemoteInfo.LocalRepositoryUri.AbsolutePath));
                    settings.WorkingFolder     = new Folder(_logger, new DirectoryInfo(repository.RemoteInfo.WorkingFolder.AbsolutePath));
                    repositoryData.IsLocalRepo = repository.IsLocalRepo;

                    if (!repositoryData.IsFork) //check if we are on a fork. If not on a fork we set the remote to the locally found remote
                    {
                        repositoryData.Remote = repository.RemoteInfo.RemoteName;
                    }
                }
                else
                {
                    folder = _folderFactory.UniqueTemporaryFolder();
                    settings.WorkingFolder = folder;
                }

                if (!string.IsNullOrEmpty(repository.RemoteInfo?.BranchName))
                {
                    repositoryData.DefaultBranch = repository.RemoteInfo.BranchName;
                }

                repositoryData.IsLocalRepo = repository.IsLocalRepo;
                IGitDriver git = string.IsNullOrWhiteSpace(settings?.UserSettings?.GitPath) ?
                                 new LibGit2SharpDriver(_logger, folder, credentials, user) as IGitDriver :
                                 new GitCmdDriver(settings.UserSettings.GitPath, _logger, folder, credentials) as IGitDriver;

                var updatesDone = await _repositoryUpdater.Run(git, repositoryData, settings);

                if (!repository.IsLocalRepo)
                {
                    folder.TryDelete();
                }

                return(updatesDone);
            }
#pragma warning disable CA1031
            catch (Exception ex)
#pragma warning restore CA1031
            {
                _logger.Error($"Failed on repo {repository.RepositoryName}", ex);
                return(1);
            }
        }
Exemple #7
0
        public async Task <int> Run(RepositorySettings repository,
                                    GitUsernamePasswordCredentials credentials,
                                    SettingsContainer settings, User user)
        {
            if (repository == null)
            {
                throw new ArgumentNullException(nameof(repository));
            }

            if (credentials == null)
            {
                throw new ArgumentNullException(nameof(credentials));
            }

            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            DefaultCredentialServiceUtility.SetupDefaultCredentialService(_nugetLogger, true);

            var repositoryData = await BuildGitRepositorySpec(repository, credentials.Username);

            if (repositoryData == null)
            {
                return(0);
            }

            // should perform the remote check for "is this a .NET repo"
            // (and also not a github fork)
            // only when we have multiple remote repos
            // otherwise it's ok to work locally, and check there
            if (!(settings.SourceControlServerSettings.Scope == ServerScope.Repository || repository.IsLocalRepo))
            {
                var remoteRepoContainsDotNet = await _repositoryFilter.ContainsDotNetProjects(repository);

                if (!remoteRepoContainsDotNet)
                {
                    return(0);
                }
            }

            IFolder folder;

            if (repository.IsLocalRepo)
            {
                folder = new Folder(_logger, new DirectoryInfo(Uri.UnescapeDataString(repository.RemoteInfo.LocalRepositoryUri.AbsolutePath)));
                settings.WorkingFolder     = new Folder(_logger, new DirectoryInfo(Uri.UnescapeDataString(repository.RemoteInfo.WorkingFolder.AbsolutePath)));
                repositoryData.IsLocalRepo = repository.IsLocalRepo;

                if (!repositoryData.IsFork) //check if we are on a fork. If not on a fork we set the remote to the locally found remote
                {
                    repositoryData.Remote = repository.RemoteInfo.RemoteName;
                }
            }
            else
            {
                folder = !string.IsNullOrWhiteSpace(settings?.UserSettings?.Directory)
                    ? _folderFactory.FolderFromPath(settings.UserSettings.Directory)
                    : _folderFactory.UniqueTemporaryFolder();
                settings.WorkingFolder = folder;
            }

            if (!string.IsNullOrEmpty(repository.RemoteInfo?.BranchName))
            {
                repositoryData.DefaultBranch = repository.RemoteInfo.BranchName;
            }

            repositoryData.IsLocalRepo = repository.IsLocalRepo;
            IGitDriver git = string.IsNullOrWhiteSpace(settings?.UserSettings?.GitPath) ?
                             new LibGit2SharpDriver(_logger, folder, credentials, user) as IGitDriver :
                             new GitCmdDriver(settings.UserSettings.GitPath, _logger, folder, credentials) as IGitDriver;

            try
            {
                return(await _repositoryUpdater.Run(git, repositoryData, settings));
            }
            finally
            {
                if (!repository.IsLocalRepo)
                {
                    folder.TryDelete();
                }
            }
        }