Created
October 5, 2020 19:44
-
-
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>`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<OutputType>Exe</OutputType> | |
<TargetFramework>netcoreapp3.1</TargetFramework> | |
</PropertyGroup> | |
<ItemGroup> | |
<PackageReference Include="Octokit" Version="0.48.0" /> | |
</ItemGroup> | |
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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