Skip to content

Commit

Permalink
Merge 9d1f08f into c3160e6
Browse files Browse the repository at this point in the history
  • Loading branch information
samsmithnz committed Jun 17, 2023
2 parents c3160e6 + 9d1f08f commit 3fa204c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/DotNetCensus.Core/APIs/GitHubAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,14 @@ 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<FileDetails[]>(jsonObj?.ToString());
if (fileDetails != null &&
fileDetails.Length > 1)
{
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;
Expand Down Expand Up @@ -128,7 +129,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();
Expand Down
6 changes: 4 additions & 2 deletions src/DotNetCensus.Core/Projects/ProjectClassification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
{
Expand All @@ -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"))
{
Expand Down Expand Up @@ -246,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";
Expand Down
2 changes: 1 addition & 1 deletion src/DotNetCensus/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
5 changes: 3 additions & 2 deletions src/DotNetCensus/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand All @@ -60,7 +61,7 @@ static void RunOptions(Options opts)
static void HandleParseError(IEnumerable<Error> errs)
{
//handle errors
var excList = new List<Exception>();
List<Exception> excList = new List<Exception>();
foreach (var err in errs)
{
excList.Add(new ArgumentException(err.ToString()));
Expand Down

0 comments on commit 3fa204c

Please sign in to comment.