private static async Task Main(string[] args) { string orgName = null; var repoNames = new List <string>(); var teamNames = new List <string>(); var userNames = new List <string>(); string outputFileName = null; string cacheLocation = null; var help = false; var options = new OptionSet() .Add("org=", "The {name} of the GitHub organization", v => orgName = v) .Add("r|repo=", "The {name} of the repo to analyze impact for", v => repoNames.Add(v)) .Add("t|team=", "The {name} of the team to analyze impact for", v => teamNames.Add(v)) .Add("u|user="******"The {name} of the user to analyze impact for", v => userNames.Add(v)) .Add("o|output=", "The {path} where the output .csv file should be written to.", v => outputFileName = v) .Add("cache-location=", "The {path} where the .json cache is located.", v => cacheLocation = v) .Add("h|?|help", null, v => help = true, true) .Add(new ResponseFileSource()); try { var unprocessed = options.Parse(args); if (help) { var exeName = Path.GetFileNameWithoutExtension(Environment.GetCommandLineArgs()[0]); Console.Error.WriteLine($"This tool computes what would happen if a given team was removed."); Console.Error.WriteLine(); Console.Error.WriteLine($"usage: {exeName} --org <org> [OPTIONS]+"); options.WriteOptionDescriptions(Console.Error); return; } if (unprocessed.Count > 0) { orgName = unprocessed[0]; unprocessed.RemoveAt(0); } if (orgName == null) { Console.Error.WriteLine($"error: --org must be specified"); return; } if (unprocessed.Any()) { foreach (var option in unprocessed) { Console.Error.WriteLine($"error: unrecognized argument {option}"); } return; } } catch (Exception ex) { Console.Error.WriteLine(ex.ToString()); return; } if (outputFileName == null && !ExcelExtensions.IsExcelInstalled()) { Console.Error.WriteLine("error: you must specify an output path because you don't have Excel."); return; } await RunAsync(orgName, repoNames, teamNames, userNames, outputFileName, cacheLocation); }
private static async Task Main(string[] args) { string orgName = null; string outputFileName = null; string cacheLocation = null; string githubToken = null; string ospoToken = null; string policyRepo = null; var help = false; var options = new OptionSet() .Add("org=", "The {name} of the GitHub organization", v => orgName = v) .Add("o|output=", "The {path} where the output .csv file should be written to.", v => outputFileName = v) .Add("cache-location=", "The {path} where the .json cache should be written to.", v => cacheLocation = v) .Add("github-token=", "The GitHub API {token} to be used.", v => githubToken = v) .Add("ospo-token=", "The OSPO API {token} to be used.", v => ospoToken = v) .Add("policy-repo=", "The GitHub {repo} policy violations should be file in.", v => policyRepo = v) .Add("h|?|help", null, v => help = true, true) .Add(new ResponseFileSource()); try { var unprocessed = options.Parse(args); if (help) { var exeName = Path.GetFileNameWithoutExtension(Environment.GetCommandLineArgs()[0]); Console.Error.WriteLine($"usage: {exeName} --org <org> [OPTIONS]+"); options.WriteOptionDescriptions(Console.Error); return; } if (unprocessed.Count > 0) { orgName = unprocessed[0]; unprocessed.RemoveAt(0); } if (orgName == null) { Console.Error.WriteLine($"error: --org must be specified"); return; } if (unprocessed.Any()) { foreach (var option in unprocessed) { Console.Error.WriteLine($"error: unrecognized argument {option}"); } return; } } catch (Exception ex) { Console.Error.WriteLine(ex.ToString()); return; } if (outputFileName == null && !ExcelExtensions.IsExcelInstalled()) { Console.Error.WriteLine("error: you must specify an output path because you don't have Excel."); return; } await RunAsync(orgName, outputFileName, cacheLocation, githubToken, ospoToken, policyRepo); }
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); } } }