private static async Task RunAsync(string orgName, string outputFileName, string cacheLocation) { var isForExcel = outputFileName == null; var client = await GitHubClientFactory.CreateAsync(); var cachedOrg = await CachedOrg.LoadAsync(client, orgName, Console.Out, cacheLocation, forceUpdate : false); var csvDocument = new CsvDocument("repo", "repo-state", "repo-last-pushed", "principal-kind", "principal", "permission", "via-team"); using (var writer = csvDocument.Append()) { foreach (var repo in cachedOrg.Repos) { var publicPrivate = repo.IsPrivate ? "private" : "public"; var lastPush = repo.LastPush.ToLocalTime().DateTime.ToString(); foreach (var teamAccess in repo.Teams) { var permissions = teamAccess.Permission.ToString().ToLower(); var teamName = teamAccess.Team.Name; var teamUrl = teamAccess.Team.Url; writer.WriteHyperlink(repo.Url, repo.Name, isForExcel); writer.Write(publicPrivate); writer.Write(lastPush); writer.Write("team"); writer.WriteHyperlink(teamUrl, teamName, isForExcel); writer.Write(permissions); writer.Write(teamName); writer.WriteLine(); } foreach (var userAccess in repo.Users) { var via = userAccess.Describe().ToString(); var userUrl = CachedOrg.GetUserUrl(userAccess.UserLogin); var permissions = userAccess.Permission.ToString().ToLower(); writer.WriteHyperlink(repo.Url, repo.Name, isForExcel); writer.Write(publicPrivate); writer.Write(lastPush); writer.Write("user"); writer.WriteHyperlink(userUrl, userAccess.UserLogin, isForExcel); writer.Write(permissions); writer.Write(via); writer.WriteLine(); } } } if (outputFileName == null) { csvDocument.ViewInExcel(); } else { csvDocument.Save(outputFileName); } }
private static void SaveVioloations(string orgName, string outputFileName, bool isForExcel, IReadOnlyList <PolicyViolation> violations) { var csvDocument = new CsvDocument("org", "severity", "rule", "rule-title", "fingerprint", "violation", "repo", "user", "team", "assignees"); using (var writer = csvDocument.Append()) { foreach (var violation in violations) { writer.Write(orgName); writer.Write(violation.Descriptor.Severity.ToString()); writer.Write(violation.Descriptor.DiagnosticId); writer.Write(violation.Descriptor.Title); writer.Write(violation.Fingerprint.ToString()); writer.Write(violation.Title); if (violation.Repo == null) { writer.Write(string.Empty); } else { writer.WriteHyperlink(violation.Repo.Url, violation.Repo.Name, isForExcel); } if (violation.User == null) { writer.Write(string.Empty); } else { writer.WriteHyperlink(violation.User.Url, violation.User.Login, isForExcel); } if (violation.Team == null) { writer.Write(string.Empty); } else { writer.WriteHyperlink(violation.Team.Url, violation.Team.Name, isForExcel); } var assignees = string.Join(", ", violation.Assignees.Select(r => r.Login)); writer.Write(assignees); writer.WriteLine(); } } if (outputFileName == null) { csvDocument.ViewInExcel(); } else { csvDocument.Save(outputFileName); } }
static void Main(string[] args) { var usageData = @"\\fxcore\apps\NuGet\usage\NuGet.apiu"; var platform1 = ".NET Core/2.2/Platform Extensions"; var platform2 = ".NET Core/3.0"; var usageResults = ConsoleRunner.Run(pm => { pm.SetTask($"Loading NuGet usage data"); pm.SetDetails(usageData); using (var fileStream = File.OpenRead(usageData)) using (var progressStream = new ProgressStream(fileStream, pm)) return(ApiUsageResults.Load(progressStream)); }); var apiCatalog = ConsoleRunner.Run(pm => { pm.SetTask($"Loading API Catalog"); var ds = SqlCatalogStores.ProductionDataSource; var db = SqlCatalogStores.ProductionDatabase; return(ApiCatalogSqlServerFormat.Load(ds, db, pm)); }); var usageById = usageResults.Usages.ToDictionary(u => u.Id); var assemblyGroup1 = apiCatalog.AssemblyGroups.Single(ag => ag.AreaPath == platform1); var assemblyGroup2 = apiCatalog.AssemblyGroups.Single(ag => ag.AreaPath == platform2); var assemblies = new HashSet <AssemblyDefinition>(assemblyGroup1.Assemblies); var csvDocument = new CsvDocument("ID", "Namespace", "Type", "Member", "Package", "Path"); using (var csvWriter = csvDocument.Append()) { ConsoleRunner.Run(pm => { pm.SetTask($"Computing diff between {assemblyGroup1.Name} and {assemblyGroup2.Name}"); var apiCount = apiCatalog.GetAllApis().Count(); foreach (var api in apiCatalog.GetAllApis().WithProgress(apiCount, pm)) { var isInAssemblyGroup1 = false; var isInAssemblyGroup2 = false; foreach (var ag in apiCatalog.GetContainedAssemblyGroups(api)) { if (ag == assemblyGroup1) { isInAssemblyGroup1 = true; } else if (ag == assemblyGroup2) { isInAssemblyGroup2 = true; } } var isOverride = apiCatalog.LookupDeclarations(api) .Where(d => assemblies.Contains(d.Assembly)) .Any(d => d.Syntax.Contains(" override ")); var apiWasRemoved = isInAssemblyGroup1 && !isInAssemblyGroup2 && !isOverride; if (apiWasRemoved) { var apiId = api.DocId; var apiNamespace = api.GetNamespaceName(apiCatalog); var apiTypeName = api.GetTypeName(apiCatalog); var apiMemberName = api.GetMemberName(); if (usageById.TryGetValue(api.DocId, out var usage)) { var packages = usage.DataSeries.SelectMany(ds => ds) .SelectMany(dp => usageResults.Assemblies[dp.AssemblyIndex].Applications) .Distinct(); foreach (var package in packages) { var packageName = package.Metadata["Name"]; var packagePath = package.Metadata["Path"]; csvWriter.Write(apiId); csvWriter.Write(apiNamespace); csvWriter.Write(apiTypeName); csvWriter.Write(apiMemberName); csvWriter.Write(packageName); csvWriter.Write(packagePath); csvWriter.WriteLine(); } } else { var packageName = ""; var packagePath = ""; csvWriter.Write(apiId); csvWriter.Write(apiNamespace); csvWriter.Write(apiTypeName); csvWriter.Write(apiMemberName); csvWriter.Write(packageName); csvWriter.Write(packagePath); csvWriter.WriteLine(); } } } }); } csvDocument.ViewInExcel(); }
private static async Task RunAsync(string orgName, List <string> repoNames, List <string> teamNames, List <string> userNames, string outputFileName, string cacheLocation) { Console.WriteLine("Loading org data..."); var cachedOrg = await CachedOrg.LoadFromCacheAsync(orgName, cacheLocation); if (cachedOrg == null) { Console.Error.WriteLine("The org wasn't loaded yet or the cache isn't valid anymore."); return; } var repoFilter = CreateRepoFilter(cachedOrg, repoNames); var teamFilter = CreateTeamFilter(cachedOrg, teamNames); var userFilter = CreateUserFilter(cachedOrg, userNames); Console.WriteLine("Loading Microsoft links..."); var ospoClient = await OspoClientFactory.CreateAsync(); var links = await ospoClient.GetAllAsync(); Console.WriteLine("Computing result..."); var emailByUser = new Dictionary <CachedUser, string>(); var nameByUser = new Dictionary <CachedUser, string>(); var microsoftLink = links.ToDictionary(l => l.GitHubInfo.Login); foreach (var user in cachedOrg.Users) { emailByUser[user] = user.Email; nameByUser[user] = user.Name; if (microsoftLink.TryGetValue(user.Login, out var link)) { if (!string.IsNullOrEmpty(link.MicrosoftInfo.EmailAddress)) { emailByUser[user] = link.MicrosoftInfo.EmailAddress; } if (!string.IsNullOrEmpty(link.MicrosoftInfo.PreferredName)) { nameByUser[user] = link.MicrosoftInfo.PreferredName; } } } var isForExcel = outputFileName == null; var csvDocument = new CsvDocument("team", "repo", "user", "user-name", "user-email", "is-microsoft", "change", "repo-admins"); using (var writer = csvDocument.Append()) { foreach (var userAccess in cachedOrg.Collaborators) { var repo = userAccess.Repo; var user = userAccess.User; if (!repoFilter(repo) || !userFilter(user)) { continue; } foreach (var team in cachedOrg.Teams) { if (!teamFilter(team)) { continue; } var whatIfRemoved = userAccess.WhatIfRemovedFromTeam(team); var change = whatIfRemoved.ToString(); if (whatIfRemoved.IsUnchanged) { continue; } var isMicrosoft = microsoftLink.ContainsKey(user.Login) ? "Yes" : "No"; var repoAdmins = repo.GetAdministrators() .Select(u => (Email: emailByUser[u], Name: nameByUser[u])) .Where(t => !string.IsNullOrEmpty(t.Email)) .Select(t => $"{t.Name}<{t.Email}>"); var repoAdminList = string.Join("; ", repoAdmins); writer.WriteHyperlink(team.Url, team.Name, isForExcel); writer.WriteHyperlink(repo.Url, repo.Name, isForExcel); writer.WriteHyperlink(user.Url, user.Login, isForExcel); writer.Write(nameByUser[user]); writer.Write(emailByUser[user]); writer.Write(isMicrosoft); writer.Write(change); writer.Write(repoAdminList); writer.WriteLine(); } } } if (outputFileName != null) { csvDocument.Save(outputFileName); } else { csvDocument.ViewInExcel(); } }
private static async Task Main(string[] args) { if (args.Length < 1 || 2 < args.Length) { var exeName = Path.GetFileNameWithoutExtension(Environment.GetCommandLineArgs()[0]); Console.Error.WriteLine("error: wrong number of arguments"); Console.Error.WriteLine($"usage {exeName} <org-name> [output-path]"); return; } var orgName = args[0]; var outputFileName = args.Length < 2 ? null : args[1]; var isForExcel = outputFileName == null; if (outputFileName == null && !ExcelExtensions.IsExcelInstalled()) { Console.Error.WriteLine("error: you must specify and output path because you don't have Excel."); return; } var client = await GitHubClientFactory.CreateAsync(); var cachedOrg = await LoadCachedOrgAsync(client, orgName); var csvDocument = new CsvDocument("repo", "repo-state", "repo-last-pushed", "principal-kind", "principal", "permission", "via-team"); using (var writer = csvDocument.Append()) { foreach (var repo in cachedOrg.Repos) { var publicPrivate = repo.IsPrivate ? "private" : "public"; var lastPush = repo.LastPush.ToLocalTime().DateTime.ToString(); var repoUrl = $"https://github.com/{cachedOrg.Name}/{repo.Name}"; foreach (var teamAccess in repo.Teams) { var permissions = teamAccess.Permission.ToString().ToLower(); var teamName = teamAccess.Team.Name; var teamUrl = $"https://github.com/orgs/{cachedOrg.Name}/teams/{teamName.ToLower()}"; writer.Write(CreateHyperlink(isForExcel, repoUrl, repo.Name)); writer.Write(publicPrivate); writer.Write(lastPush); writer.Write("team"); writer.Write(CreateHyperlink(isForExcel, teamUrl, teamName)); writer.Write(permissions); writer.Write(teamName); writer.WriteLine(); } foreach (var userAccess in repo.Users) { var via = cachedOrg.DescribeAccess(userAccess); var userUrl = $"https://github.com/{userAccess.User}"; var permissions = userAccess.Permission.ToString().ToLower(); writer.Write(CreateHyperlink(isForExcel, repoUrl, repo.Name)); writer.Write(publicPrivate); writer.Write(lastPush); writer.Write("user"); writer.Write(CreateHyperlink(isForExcel, userUrl, userAccess.User)); writer.Write(permissions); writer.Write(via); writer.WriteLine(); } } } if (outputFileName == null) { csvDocument.ViewInExcel(); } else { var extension = Path.GetExtension(outputFileName); if (extension == ".md") { csvDocument.SaveAsMarkdownTable(outputFileName); } else { csvDocument.Save(outputFileName); } } }