Skip to content

Instantly share code, notes, and snippets.

@terrajobst terrajobst/dumpperms.cs Secret

Created Oct 23, 2019
Embed
What would you like to do?
using Microsoft.Fx.Csv;
using System;
using System.Linq;
using System.Threading.Tasks;
namespace GitHubPermissionSurveyor
{
class Program
{
static async Task Main()
{
var csvDocument = new CsvDocument("repo", "repo-state", "principal-kind", "principal", "permission");
using (var writer = csvDocument.Append())
{
var client = GitHubClientFactory.Create();
var repos = await client.Repository.GetAllForOrg("dotnet");
var i = 0;
foreach (var repo in repos)
{
var percentage = i / (float)repos.Count;
i++;
Console.WriteLine($"{repo.FullName} ({percentage:P})");
var publicPrivate = repo.Private ? "private" : "public";
var teams = await client.Repository.GetAllTeams(repo.Owner.Login, repo.Name);
foreach (var team in teams)
{
writer.Write($"=HYPERLINK(\"{repo.HtmlUrl}\", \"{repo.Name}\")");
writer.Write(publicPrivate);
writer.Write("team");
writer.Write($"=HYPERLINK(\"https://github.com/orgs/dotnet/teams/{team.Name.ToLower()}\", \"{team.Name}\")");
writer.Write(team.Permission.StringValue);
writer.WriteLine();
}
foreach (var user in await client.Repository.Collaborator.GetAll(repo.Owner.Login, repo.Name))
{
var permissions = user.Permissions.Admin
? "admin"
: user.Permissions.Push
? "push"
: user.Permissions.Pull
? "read"
: "";
writer.Write($"=HYPERLINK(\"{repo.HtmlUrl}\", \"{repo.Name}\")");
writer.Write(publicPrivate);
writer.Write("collaborator");
writer.Write($"=HYPERLINK(\"{user.HtmlUrl}\", \"{user.Login}\")");
writer.Write(permissions);
writer.WriteLine();
}
}
}
csvDocument.ViewInExcel();
}
}
}
@kapsiR

This comment has been minimized.

Copy link

kapsiR commented Oct 24, 2019

@terrajobst: Where can I find Microsoft.Fx.Csv? 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.