예제 #1
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 vars = new Dictionary <string, object>
            {
                { "after", null },
            };

            var packageConnection = await GraphQLUtilities.FindPackageConnection(connection, PackagesPath, 100, Var("after"), vars);

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

            var query = packageConnection
                        .Select(p => new
            {
                p.PageInfo.EndCursor,
                p.PageInfo.HasNextPage,
                Packages = p.Nodes.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()
                }).ToList()
            }).Compile();

            long publicStorage  = 0;
            long privateStorage = 0;

            while (true)
            {
                var packages = await connection.Run(query, vars, cancellationToken : cancellationToken);

                foreach (var package in packages.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)");
                        }
                    }
                }

                if (packages.HasNextPage)
                {
                    vars["after"] = packages.EndCursor;
                    continue;
                }

                break;
            }

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

            return(0);
        }
예제 #2
0
        protected override async Task <int> OnExecuteAsyncImpl(CommandLineApplication app,
                                                               CancellationToken cancellationToken)
        {
            var connection = CreateConnection();

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

            var vars = new Dictionary <string, object>
            {
                { "after", null },
            };

            var packageConnection = await GraphQLUtilities.FindPackageConnection(connection, PackageOwner, 100, Var("after"), vars);

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

            var query = packageConnection
                        .Select(p => new
            {
                p.PageInfo.EndCursor,
                p.PageInfo.HasNextPage,
                Packages = p.Nodes.Select(p => new PackageInfo
                {
                    RepositoryUrl       = p.Repository != null ? p.Repository.Url : "[PRIVATE REPOSITORIES]",
                    Name                = p.Name,
                    PackageType         = p.PackageType,
                    DownloadsTotalCount = p.Statistics.DownloadsTotalCount,
                    Versions            = p.Versions(null, null, null, null, null).AllPages().Select(v => v.Version).ToList()
                }).ToList()
            }).Compile();

            var hasNextPage = false;

            do
            {
                var packages = await connection.Run(query, vars);

                var groups = packages.Packages.GroupBy(p => p.RepositoryUrl);
                foreach (var group in groups.OrderBy(g => g.Key))
                {
                    Console.WriteLine(group.Key);
                    foreach (var package in group)
                    {
                        Console.WriteLine($"    {package.Name} ({package.PackageType}) [{string.Join(", ", package.Versions)}] ({package.DownloadsTotalCount} downloads)");
                    }
                }

                hasNextPage   = packages.HasNextPage;
                vars["after"] = packages.EndCursor;
            }while (hasNextPage);

            return(0);
        }
예제 #3
0
파일: Program.cs 프로젝트: peters/gpr
        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 packageCollection = await GraphQLUtilities.FindPackageConnection(connection, PackagesPath);

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

            var query = packageCollection.Nodes.Select(p =>
                                                       new
            {
                p.Name,
                p.Statistics.DownloadsTotalCount,
                Versions = p.Versions(100, null, null, null, null).Nodes.Select(v =>
                                                                                new
                {
                    v.Version,
                    v.Statistics.DownloadsTotalCount,
                    Files = v.Files(40, null, null, null, null).Nodes.Select(f => new { f.Name, f.UpdatedAt, f.Size }).ToList()
                }).ToList()
            }).Compile();

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

            long totalStorage = 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)
                        {
                            totalStorage += (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($"Storage used {totalStorage / (1024 * 1024)} MB");

            return(0);
        }
예제 #4
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 vars = new Dictionary <string, object>
            {
                { "after", null },
            };

            var packageConnection = await GraphQLUtilities.FindPackageConnection(connection, PackagesPath, 100, Var("after"), vars);

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

            var query = packageConnection.Select(p => new
            {
                p.PageInfo.EndCursor,
                p.PageInfo.HasNextPage,
                Packages = p.Nodes.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()
                }).ToList()
            }).Compile();

            var packagesDeleted = 0;

            var hasNextPage = false;

            do
            {
                var result = await connection.Run(query, vars, cancellationToken : cancellationToken);

                var packages = result.Packages.ToList();

                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.Where(v => Version is null || v.Version == Version))
                    {
                        if (Force)
                        {
                            Console.WriteLine($"  Deleting '{version.Version}'");

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

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

                hasNextPage   = result.HasNextPage;
                vars["after"] = result.EndCursor;
            }while (hasNextPage);

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

            return(0);
        }
예제 #5
0
파일: Program.cs 프로젝트: peters/gpr
        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 packageCollection = await GraphQLUtilities.FindPackageConnection(connection, PackagesPath);

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

            var query = packageCollection.Nodes.Select(p =>
                                                       new
            {
                p.Repository.Url,
                p.Name,
                Versions = p.Versions(100, null, null, null, null).Nodes.Select(v =>
                                                                                new
                {
                    p.Repository.Url,
                    p.Name,
                    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);
        }