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); } }
public void ProcessDirectory(string directory, Action <string> Log) { Log("Obteniendo los archivos a procesar..."); string[] files = Directory.GetFiles(directory, "*.xml", SearchOption.AllDirectories); Log(string.Format("Encontre [{0}] archivos", files.Length)); CsvDocument csv = new CsvDocument(); csv.HeaderColumns.Add("FacturaArchivo"); csv.HeaderColumns.Add("EmisorNombre"); csv.HeaderColumns.Add("EmisorRfc"); csv.HeaderColumns.Add("ImpuestosTotal"); csv.HeaderColumns.Add("ImpuestosIvaTasa"); csv.HeaderColumns.Add("ImpuestosIvaImporte"); csv.HeaderColumns.Add("TipoIngreso"); csv.HeaderColumns.Add("Total"); csv.HeaderColumns.Add("Descuento"); csv.HeaderColumns.Add("SubTotal"); csv.HeaderColumns.Add("FormaPago"); csv.HeaderColumns.Add("Fecha"); var data = csv.Table; XmlSerializer serializer = new XmlSerializer(typeof(Comprobante)); foreach (string file in files) { Log($"Procesando archivo: {file}"); using (StreamReader reader = new StreamReader(file)) { Comprobante record = (Comprobante)serializer.Deserialize(reader); data.Add(new List <string>() { Path.GetFileNameWithoutExtension(file) ?? string.Empty, record.Emisor.Nombre ?? string.Empty, record.Emisor.Rfc ?? string.Empty, record.Impuestos.TotalImpuestosTrasladados ?? string.Empty, GetImpuesto("IVA", record.Impuestos).Tasa ?? string.Empty, GetImpuesto("IVA", record.Impuestos).Importe ?? string.Empty, record.Fecha ?? string.Empty, record.FormaDePago ?? string.Empty, record.Descuento ?? string.Empty, record.TipoDeComprobante ?? string.Empty, record.SubTotal ?? string.Empty, record.Total ?? string.Empty }); } } var reportPath = Path.Combine(directory, "Reporte.csv"); csv.Save(reportPath, true); }
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); } } }