Пример #1
0
        async Task <IEnumerable <PackageInfo> > GetPackages(IConnection connection)
        {
            IEnumerable <PackageInfo> result;

            if (PackageOwner is { } packageOwner)
            {
                var packageList = await GraphQLUtilities.FindPackageList(connection, packageOwner);

                if (packageList is null)
                {
                    throw new ApplicationException($"Couldn't find a user or org with the login of '{packageOwner}'");
                }

                result = await GetPackages(connection, packageList);
            }
Пример #2
0
        protected override async Task <int> OnExecuteAsyncImpl(CommandLineApplication app,
                                                               CancellationToken cancellationToken)
        {
            var connection = CreateConnection();

            if (PackagesPath is null)
            {
                Console.WriteLine("Please include a packages path");
                return(1);
            }

            var packageList = await GraphQLUtilities.FindPackageList(connection, PackagesPath);

            if (packageList == null)
            {
                Console.WriteLine("Couldn't find packages");
                return(1);
            }

            var query = packageList.Select(p =>
                                           new
            {
                // If access token doesn't have `repo` scope, private packages will have a null `Repository` object
                IsPrivate = p.Repository != null ? p.Repository.IsPrivate : true,
                p.Name,
                p.Statistics.DownloadsTotalCount,
                Versions = p.Versions(null, null, null, null, null).AllPages().Select(v =>
                                                                                      new
                {
                    v.Version,
                    v.Statistics.DownloadsTotalCount,
                    Files = v.Files(null, null, null, null, null).AllPages(40).Select(f => new { f.Name, f.UpdatedAt, f.Size }).ToList()
                }).ToList()
            }).Compile();

            var packages = await connection.Run(query, cancellationToken : cancellationToken);

            long publicStorage  = 0;
            long privateStorage = 0;

            foreach (var package in packages)
            {
                Console.WriteLine($"{package.Name} ({package.DownloadsTotalCount} downloads)");
                foreach (var version in package.Versions)
                {
                    foreach (var file in version.Files)
                    {
                        if (file.Size != null)
                        {
                            if (package.IsPrivate)
                            {
                                privateStorage += (int)file.Size;
                            }
                            else
                            {
                                publicStorage += (int)file.Size;
                            }
                        }
                    }

                    if (version.Files.Count == 1)
                    {
                        var file = version.Files[0];
                        if (file.Name.Contains(version.Version))
                        {
                            Console.WriteLine($"  {file.Name} ({file.UpdatedAt:d}, {version.DownloadsTotalCount} downloads, {file.Size} bytes)");
                            continue;
                        }
                    }

                    Console.WriteLine($"  {version.Version} ({version.DownloadsTotalCount} downloads)");
                    foreach (var file in version.Files)
                    {
                        Console.WriteLine($"    {file.Name} ({file.UpdatedAt:d}, {file.Size} bytes)");
                    }
                }
            }

            Console.WriteLine();
            Console.WriteLine($"Public storage used {publicStorage / (1024 * 1024)} MB");
            Console.WriteLine($"Private storage used {privateStorage / (1024 * 1024)} MB");

            return(0);
        }
Пример #3
0
        protected override async Task <int> OnExecuteAsyncImpl(CommandLineApplication app,
                                                               CancellationToken cancellationToken)
        {
            var connection = CreateConnection();

            if (PackagesPath is null)
            {
                Console.WriteLine("Please include a packages path");
                return(1);
            }

            var packageList = await GraphQLUtilities.FindPackageList(connection, PackagesPath);

            if (packageList == null)
            {
                Console.WriteLine("Couldn't find packages");
                return(1);
            }

            var query = packageList.Select(p =>
                                           new
            {
                p.Repository.Url,
                p.Name,
                Versions = p.Versions(null, null, null, null, null).AllPages().Select(v =>
                                                                                      new
                {
                    v.Id,
                    v.Version,
                    v.Statistics.DownloadsTotalCount
                }).ToList()
            }).Compile();

            var packages        = (await connection.Run(query, cancellationToken: cancellationToken)).ToList();
            var packagesDeleted = 0;

            if (DockerCleanUp)
            {
                foreach (var package in packages)
                {
                    if (package.Versions.Count == 1 && package.Versions[0] is var version && version.Version == "docker-base-layer")
                    {
                        Console.WriteLine($"Cleaning up '{package.Name}'");

                        var versionId = version.Id;
                        var success   = await DeletePackageVersion(connection, versionId, cancellationToken);

                        if (success)
                        {
                            Console.WriteLine($"  Deleted '{version.Version}'");
                            packagesDeleted++;
                        }
                    }
                }

                Console.WriteLine("Complete");
                return(0);
            }

            foreach (var package in packages)
            {
                Console.WriteLine(package.Name);
                foreach (var version in package.Versions)
                {
                    if (Force)
                    {
                        Console.WriteLine($"  Deleting '{version.Version}'");

                        var versionId = version.Id;
                        await DeletePackageVersion(connection, versionId, cancellationToken);

                        packagesDeleted++;
                    }
                    else
                    {
                        Console.WriteLine($"  {version.Version}");
                    }
                }
            }

            if (!Force)
            {
                Console.WriteLine();
                Console.WriteLine("To delete these package versions, use the --force option.");
            }

            return(packagesDeleted == packages.Count ? 0 : 1);
        }