From aabe7bf8b0df7a04e06f269ea88a3154618f696a Mon Sep 17 00:00:00 2001 From: Sam Smith Date: Sat, 17 Jun 2023 11:25:09 -0400 Subject: [PATCH 1/7] Updated exception type to be argument exception --- src/DotNetCensus.Core/APIs/GitHubAPI.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DotNetCensus.Core/APIs/GitHubAPI.cs b/src/DotNetCensus.Core/APIs/GitHubAPI.cs index 70e94efc..31485853 100644 --- a/src/DotNetCensus.Core/APIs/GitHubAPI.cs +++ b/src/DotNetCensus.Core/APIs/GitHubAPI.cs @@ -128,7 +128,7 @@ private static HttpClient BuildHttpClient(string? clientId, string? clientSecret //Console.WriteLine($"Running GitHub url: {url}"); if (!url.Contains("api.github.com")) { - throw new Exception("api.github.com missing from URL"); + throw new ArgumentException("api.github.com missing from URL"); } HttpClient client = new(); client.DefaultRequestHeaders.Accept.Clear(); From 5a4cb65392ceb4d2392a2ccf82bd4994f52d876e Mon Sep 17 00:00:00 2001 From: Sam Smith Date: Sat, 17 Jun 2023 11:29:32 -0400 Subject: [PATCH 2/7] Fixed order of catch if --- src/DotNetCensus.Core/APIs/GitHubAPI.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DotNetCensus.Core/APIs/GitHubAPI.cs b/src/DotNetCensus.Core/APIs/GitHubAPI.cs index 31485853..dbb8ee32 100644 --- a/src/DotNetCensus.Core/APIs/GitHubAPI.cs +++ b/src/DotNetCensus.Core/APIs/GitHubAPI.cs @@ -84,7 +84,7 @@ public static class GitHubAPI { foreach (FileDetails item in fileDetails) { - if (item.type == "file" && item != null && item.path != null) + if (item != null && item.path != null && item.type == "file") { result = await GetRepoFileContents(clientId, clientSecret, owner, repo, item.path, branch); break; From e533bf647fe9aaacfe0c0364c979603657e0ec32 Mon Sep 17 00:00:00 2001 From: Sam Smith Date: Sat, 17 Jun 2023 11:35:44 -0400 Subject: [PATCH 3/7] Added comment --- src/DotNetCensus.Core/APIs/GitHubAPI.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/DotNetCensus.Core/APIs/GitHubAPI.cs b/src/DotNetCensus.Core/APIs/GitHubAPI.cs index dbb8ee32..a61cc890 100644 --- a/src/DotNetCensus.Core/APIs/GitHubAPI.cs +++ b/src/DotNetCensus.Core/APIs/GitHubAPI.cs @@ -78,6 +78,7 @@ public static class GitHubAPI } catch (Newtonsoft.Json.JsonSerializationException) { + //TODO This catch exception is here for a reason - but I don't remember what - need to find a test that covers it FileDetails[] fileDetails = JsonConvert.DeserializeObject(jsonObj?.ToString()); if (fileDetails != null && fileDetails.Length > 1) From 87a7efe66e52e908a84ee8965b6fad747c147426 Mon Sep 17 00:00:00 2001 From: Sam Smith Date: Sat, 17 Jun 2023 11:39:28 -0400 Subject: [PATCH 4/7] Code gardening --- src/DotNetCensus.Core/Projects/ProjectClassification.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/DotNetCensus.Core/Projects/ProjectClassification.cs b/src/DotNetCensus.Core/Projects/ProjectClassification.cs index d06e6ced..c3d1a263 100644 --- a/src/DotNetCensus.Core/Projects/ProjectClassification.cs +++ b/src/DotNetCensus.Core/Projects/ProjectClassification.cs @@ -95,6 +95,8 @@ public static string GetFriendlyName(string frameworkCode, string family) { string number = frameworkCode.Replace("net", ""); StringBuilder formattedNumber = new(); + formattedNumber.Append(family); + formattedNumber.Append(' '); //Add .'s between each number. Gross. (e.g. net462 becomes 4.6.2) for (int i = 0; i < number.Length; i++) { @@ -104,7 +106,7 @@ public static string GetFriendlyName(string frameworkCode, string family) formattedNumber.Append('.'); } } - return family + " " + formattedNumber; + return formattedNumber.ToString(); } else if (frameworkCode.StartsWith("netcoreapp")) { From a3b126d582215024b031e3164c580f625a957c73 Mon Sep 17 00:00:00 2001 From: Sam Smith Date: Sat, 17 Jun 2023 11:44:12 -0400 Subject: [PATCH 5/7] Fix to code coverage --- src/DotNetCensus/Options.cs | 2 +- src/DotNetCensus/Program.cs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/DotNetCensus/Options.cs b/src/DotNetCensus/Options.cs index de0faeb3..6ea5eea2 100644 --- a/src/DotNetCensus/Options.cs +++ b/src/DotNetCensus/Options.cs @@ -23,7 +23,7 @@ public class Options public string? Repo { get; set; } [Option('u', "user", Required = false, HelpText = "GitHub repo user")] - public string? User { get; set; } + public string? User { get; set; } [Option('p', "password", Required = false, HelpText = "GitHub repo password")] public string? Password { get; set; } diff --git a/src/DotNetCensus/Program.cs b/src/DotNetCensus/Program.cs index e363116d..838054a7 100644 --- a/src/DotNetCensus/Program.cs +++ b/src/DotNetCensus/Program.cs @@ -40,9 +40,10 @@ static void RunOptions(Options opts) //setup the GitHub repo details if (opts.Owner != null && opts.Repo != null) { + opts.User = opts.Repo; //This is not a typo - we are using the repo name as the user _repo = new Repo(opts.Owner, opts.Repo) { - User = opts.Repo, //This is not a typo - we are using the repo name as the user + User = opts.User, Password = opts.Password, Branch = opts.Branch }; From 111df59dc153cd0ad0e107540b3d9622f30e5ec2 Mon Sep 17 00:00:00 2001 From: Sam Smith Date: Sat, 17 Jun 2023 11:44:57 -0400 Subject: [PATCH 6/7] code gardening --- src/DotNetCensus/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DotNetCensus/Program.cs b/src/DotNetCensus/Program.cs index 838054a7..e87833a5 100644 --- a/src/DotNetCensus/Program.cs +++ b/src/DotNetCensus/Program.cs @@ -61,7 +61,7 @@ static void RunOptions(Options opts) static void HandleParseError(IEnumerable errs) { //handle errors - var excList = new List(); + List excList = new List(); foreach (var err in errs) { excList.Add(new ArgumentException(err.ToString())); From 9d1f08fa95e8ee9f33fa7bd84e419ede4ee25c10 Mon Sep 17 00:00:00 2001 From: Sam Smith Date: Sat, 17 Jun 2023 11:46:10 -0400 Subject: [PATCH 7/7] code gardening --- src/DotNetCensus.Core/Projects/ProjectClassification.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DotNetCensus.Core/Projects/ProjectClassification.cs b/src/DotNetCensus.Core/Projects/ProjectClassification.cs index c3d1a263..3739e4d5 100644 --- a/src/DotNetCensus.Core/Projects/ProjectClassification.cs +++ b/src/DotNetCensus.Core/Projects/ProjectClassification.cs @@ -248,10 +248,10 @@ public static string GetHistoricalFrameworkVersion(string line) public static string GetLanguage(string directory) { + string language; //Check to see if it's a VB.NET or C# project int csFiles = new DirectoryInfo(directory).GetFiles("*.cs", SearchOption.AllDirectories).Length; int vbFiles = new DirectoryInfo(directory).GetFiles("*.vb", SearchOption.AllDirectories).Length; - string language; if (csFiles >= vbFiles) { language = "csharp";