Skip to content

Instantly share code, notes, and snippets.

@Cyberboss
Created October 5, 2020 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Cyberboss/b6bd567bb331fe7b66b7354dd4c2d7a6 to your computer and use it in GitHub Desktop.
Save Cyberboss/b6bd567bb331fe7b66b7354dd4c2d7a6 to your computer and use it in GitHub Desktop.
View GitHub Artifact storage usage for a given repository. Launch with `<token with repo scope> <owning github user/org name> <repo name>`
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Octokit" Version="0.48.0" />
</ItemGroup>
</Project>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Octokit;
namespace ArtifactSizeViewer
{
class Program
{
class ArtifactsPage
{
public List<Artifact> Artifacts { get; set; }
}
class Artifact
{
public long Id { get; set; }
public string Name { get; set; }
public long SizeInBytes { get; set; }
}
static async Task Main(string[] args)
{
var token = args[0];
var owner = args[1];
var repo = args[2];
var client = new GitHubClient(new ProductHeaderValue("ArtifactSizeViewer", "1.0.0"))
{
Credentials = new Credentials(token)
};
var apiConnection = new ApiConnection(client.Connection);
var results = await apiConnection.GetAll<ArtifactsPage>(
new Uri($"repos/{owner}/{repo}/actions/artifacts", UriKind.Relative));
var totalBytes = results.SelectMany(x => x.Artifacts).Select(x => x.SizeInBytes).Sum();
var gbUsed = ((double)totalBytes) / 1024 / 1024 / 1024;
Console.WriteLine($"{gbUsed}GB used.");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment