Beispiel #1
0
        public async Task UpdateDependencies(IUpdateCheckingConfig updateCheckingConfig)
        {
            try
            {
                var files = await _fileFetcher.GetProjectDependencyFileAsync();

                foreach (var file in files)
                {
                    var dependencyInfo = _fileParser.GetCsProjDependencyInfo(file.File);

                    var latestPackageVersions = await _updateChecker.CheckForUpdates(dependencyInfo.PackageInfos, updateCheckingConfig);

                    var updatedFiles = _fileUpdater.UpdateCsProjFile(dependencyInfo, latestPackageVersions);

                    foreach (var updatedFile in updatedFiles)
                    {
                        await _pullRequestCreator.CreatePullRequest(
                            new CreatePullRequestInfo
                        {
                            Content        = updatedFile.FileContent,
                            Path           = file.FileRelativePath,
                            PackageId      = updatedFile.PackageId,
                            UpdatedVersion = updatedFile.UpdatedVersion
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public async Task <IList <IPackageInfo> > CheckForUpdates(IList <IPackageInfo> packages, IUpdateCheckingConfig config)
        {
            var result = new List <IPackageInfo>();

            foreach (var package in packages)
            {
                var packageId      = package.PackageId;
                var currentVersion = new Version(package.Version);

                var availableVersions = await _nuGetClient.GetPackageVersions(packageId);

                if (availableVersions == null || !availableVersions.Any())
                {
                    availableVersions = await _proGetClient.GetPackageVersions(packageId);
                }

                var versions = availableVersions.Select(v => new Version(v.Version)).ToList();

                if (config.IncludePrereleaseVersions)
                {
                    versions = versions
                               .Where(v => !string.IsNullOrWhiteSpace(v.Prerelease))
                               .ToList();
                }

                if (!config.IncludePrereleaseVersions)
                {
                    versions = versions
                               .Where(v => string.IsNullOrWhiteSpace(v.Prerelease))
                               .ToList();
                }

                if (!config.UpdateMajorVersions)
                {
                    versions = versions
                               .Where(v => v.Major <= currentVersion.Major)
                               .ToList();
                }

                if (!versions.Any())
                {
                    return(new List <IPackageInfo>());
                }

                var versionComparer = new VersionComparer();

                var sortedByVersion = versions
                                      .OrderByDescending(c => c, versionComparer)
                                      .ToList();

                var latestNeededVersion = sortedByVersion.FirstOrDefault();

                var versionComparison = versionComparer.Compare(latestNeededVersion, currentVersion);

                if (versionComparison == 1)
                {
                    result.Add(new PackageInfo {
                        PackageId = packageId, Version = latestNeededVersion.OriginalVersion
                    });
                }
            }

            return(result);
        }