Skip to content

Commit

Permalink
Merge pull request #763 from samsmithnz/Jan2023BugBash
Browse files Browse the repository at this point in the history
Jan2023 bug bash
  • Loading branch information
samsmithnz authored Jan 15, 2023
2 parents 7124ddf + 6ded872 commit 75df416
Show file tree
Hide file tree
Showing 28 changed files with 68 additions and 88 deletions.
4 changes: 2 additions & 2 deletions src/DevOpsMetrics.Core/DataAccess/BuildsDA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static async Task<List<AzureDevOpsBuild>> GetAzureDevOpsBuilds(string pat
{
List<AzureDevOpsBuild> builds = new();
JArray list = null;
if (useCache == true)
if (useCache)
{
//Get the builds from Azure storage
AzureTableStorageDA daTableStorage = new();
Expand Down Expand Up @@ -51,7 +51,7 @@ public static async Task<List<GitHubActionsRun>> GetGitHubActionRuns(string clie
{
List<GitHubActionsRun> runs = new();
JArray list = null;
if (useCache == true)
if (useCache)
{
//Get the builds from Azure storage
AzureTableStorageDA daTableStorage = new();
Expand Down
4 changes: 0 additions & 4 deletions src/DevOpsMetrics.Core/DataAccess/LeadTimeForChangesDA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,6 @@ public static async Task<LeadTimeForChangesModel> GetGitHubLeadTimesForChanges(b
{
pullRequest.Status = "inProgress";
}
else
{
pullRequest.Status = pullRequest.Status;
}

leadTimeForChangesList.Add(new KeyValuePair<DateTime, TimeSpan>(minTime, pullRequest.Duration));
pullRequests.Add(pullRequest);
Expand Down
8 changes: 4 additions & 4 deletions src/DevOpsMetrics.Core/DataAccess/PullRequestsDA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static async Task<AzureDevOpsPR> GetAzureDevOpsPullRequest(string patToke
{
List<AzureDevOpsPR> prs = new();
JArray list;
if (useCache == true)
if (useCache)
{
//Get the pull requests from Azure storage
AzureTableStorageDA daTableStorage = new();
Expand Down Expand Up @@ -49,7 +49,7 @@ public static async Task<AzureDevOpsPR> GetAzureDevOpsPullRequest(string patToke
public static async Task<List<AzureDevOpsPRCommit>> GetAzureDevOpsPullRequestCommits(string patToken, TableStorageConfiguration tableStorageConfig, string organization, string project, string repository, string pullRequestId, bool useCache)
{
JArray list;
if (useCache == true)
if (useCache)
{
//Get the commits from Azure storage
AzureTableStorageDA daTableStorage = new();
Expand All @@ -69,7 +69,7 @@ public static async Task<GitHubPR> GetGitHubPullRequest(string clientId, string
{
List<GitHubPR> prs = new();
JArray list;
if (useCache == true)
if (useCache)
{
//Get the pull requests from Azure storage
AzureTableStorageDA daTableStorage = new();
Expand Down Expand Up @@ -101,7 +101,7 @@ public static async Task<GitHubPR> GetGitHubPullRequest(string clientId, string
public static async Task<List<GitHubPRCommit>> GetGitHubPullRequestCommits(string clientId, string clientSecret, TableStorageConfiguration tableStorageConfig, string owner, string repo, string pull_number, bool useCache)
{
JArray list;
if (useCache == true)
if (useCache)
{
//Get the commits from Azure storage
AzureTableStorageDA daTableStorage = new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public JArray GetTableStorageItemsFromStorage(TableStorageConfiguration tableSto
JArray list = new();
foreach (AzureStorageTableModel item in items)
{
if (includePartitionAndRowKeys == true)
if (includePartitionAndRowKeys)
{
string data = item.Data?.ToString();
list.Add(
Expand Down Expand Up @@ -124,7 +124,7 @@ public async Task<int> UpdateAzureDevOpsBuildsInStorage(string patToken, TableSt
string partitionKey = PartitionKeys.CreateBuildWorkflowPartitionKey(organization, project, buildName);
string rowKey = build.buildNumber;
AzureStorageTableModel newItem = new(partitionKey, rowKey, item.ToString());
if (await tableBuildsDA.AddItem(newItem) == true)
if (await tableBuildsDA.AddItem(newItem))
{
itemsAdded++;
}
Expand Down Expand Up @@ -165,7 +165,7 @@ public async Task<int> UpdateAzureDevOpsPullRequestsInStorage(string patToken, T
string partitionKey = PartitionKeys.CreateAzureDevOpsPRPartitionKey(organization, project);
string rowKey = pullRequest.PullRequestId;
AzureStorageTableModel newItem = new(partitionKey, rowKey, item.ToString());
if (await tableDA.AddItem(newItem) == true)
if (await tableDA.AddItem(newItem))
{
itemsAdded++;
}
Expand Down Expand Up @@ -194,7 +194,7 @@ public async Task<int> UpdateAzureDevOpsPullRequestCommitsInStorage(string patTo
string partitionKey = PartitionKeys.CreateAzureDevOpsPRCommitPartitionKey(organization, project, pullRequestId);
string rowKey = pullRequestCommit.commitId;
AzureStorageTableModel newItem = new(partitionKey, rowKey, item.ToString());
if (await tableDA.AddItem(newItem) == true)
if (await tableDA.AddItem(newItem))
{
itemsAdded++;
}
Expand Down Expand Up @@ -224,7 +224,7 @@ public async Task<int> UpdateGitHubActionRunsInStorage(string clientId, string c
string partitionKey = PartitionKeys.CreateBuildWorkflowPartitionKey(owner, repo, workflowName);
string rowKey = build.run_number;
AzureStorageTableModel newItem = new(partitionKey, rowKey, item.ToString());
if (await tableBuildDA.AddItem(newItem) == true)
if (await tableBuildDA.AddItem(newItem))
{
itemsAdded++;
}
Expand Down Expand Up @@ -257,7 +257,7 @@ public async Task<int> UpdateChangeFailureRate(TableStorageCommonDA tableChangeF
string rowKey = newBuild.Id;
string json = JsonConvert.SerializeObject(newBuild);
AzureStorageTableModel newItem = new(partitionKey, rowKey, json);
if (await tableChangeFailureRateDA.AddItem(newItem, forceUpdate) == true)
if (await tableChangeFailureRateDA.AddItem(newItem, forceUpdate))
{
itemsAdded++;
}
Expand All @@ -277,7 +277,7 @@ public async Task<int> UpdateGitHubActionPullRequestsInStorage(string clientId,
{
GitHubPR pr = JsonConvert.DeserializeObject<GitHubPR>(item.ToString());

if (pr.state == "closed" & pr.merged_at != null)
if (pr.state == "closed" && pr.merged_at != null)
{
string partitionKey = PartitionKeys.CreateGitHubPRPartitionKey(owner, repo);
string rowKey = pr.number;
Expand All @@ -292,7 +292,7 @@ public async Task<int> UpdateGitHubActionPullRequestsInStorage(string clientId,
json = o.ToString();
}
AzureStorageTableModel newItem = new(partitionKey, rowKey, json);
if (await tableDA.AddItem(newItem) == true)
if (await tableDA.AddItem(newItem))
{
itemsAdded++;
}
Expand All @@ -318,7 +318,7 @@ public async Task<int> UpdateGitHubActionPullRequestCommitsInStorage(string clie
string partitionKey = PartitionKeys.CreateGitHubPRCommitPartitionKey(owner, repo, pull_number);
string rowKey = commit.sha;
AzureStorageTableModel newItem = new(partitionKey, rowKey, item.ToString());
if (await tableDA.AddItem(newItem) == true)
if (await tableDA.AddItem(newItem))
{
itemsAdded++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public async Task<bool> AddItem(AzureStorageTableModel data, bool forceUpdate =
{
//Check if the item exists in storage
AzureStorageTableModel item = await GetItem(data.PartitionKey, data.RowKey);
if (item == null || forceUpdate == true)
if (item == null || forceUpdate)
{
await SaveItem(data);
return true; //data saved to table!
Expand Down
6 changes: 2 additions & 4 deletions src/DevOpsMetrics.Core/LeadTimeForChanges.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,8 @@ public static string GetLeadTimeForChangesRating(float leadTimeForChangesInHours
{
rating = "Low";
}
else //no rating
{
rating = "None";
}
//no rating else statement not required here, as all scenarios are covered above with < and >

return rating;
}
}
Expand Down
8 changes: 3 additions & 5 deletions src/DevOpsMetrics.Core/MeanTimeToRestore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static string GetMeanTimeToRestoreRating(float meanTimeToRestoreInHours)
float dailyRestoration = 24f;
float weeklyRestoration = 24f * 7f;

string rating;
string rating = "";
if (meanTimeToRestoreInHours <= 0)
{
rating = "None";
Expand All @@ -86,10 +86,8 @@ public static string GetMeanTimeToRestoreRating(float meanTimeToRestoreInHours)
{
rating = "Low";
}
else //no rating
{
rating = "None";
}
//no rating else statement not required here, as all scenarios are covered above with < and >

return rating;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/DevOpsMetrics.Service/Controllers/BuildsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public async Task<int> UpdateAzureDevOpsBuilds(
string patTokenName = PartitionKeys.CreateAzureDevOpsSettingsPartitionKeyPatToken(organization, project, repository);
patTokenName = SecretsProcessing.CleanKey(patTokenName);
string patToken = Configuration[patTokenName];
if (string.IsNullOrEmpty(patToken) == true)
if (string.IsNullOrEmpty(patToken))
{
throw new Exception($"patToken '{patTokenName}' not found in key vault");
}
Expand Down Expand Up @@ -76,7 +76,7 @@ public async Task<int> UpdateGitHubActionRuns(
clientSecretName = SecretsProcessing.CleanKey(clientSecretName);
string clientId = Configuration[clientIdName];
string clientSecret = Configuration[clientSecretName];
if (string.IsNullOrEmpty(clientId) == true | string.IsNullOrEmpty(clientSecret) == true)
if (string.IsNullOrEmpty(clientId) || string.IsNullOrEmpty(clientSecret))
{
throw new Exception($"clientId '{clientId}' or clientSecret '{clientSecret}' not found in key vault");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public async Task<DeploymentFrequencyModel> GetAzureDevOpsDeploymentFrequency(bo
string patTokenName = PartitionKeys.CreateAzureDevOpsSettingsPartitionKeyPatToken(organization, project, repository);
patTokenName = SecretsProcessing.CleanKey(patTokenName);
string patToken = Configuration[patTokenName];
if (string.IsNullOrEmpty(patToken) == true)
if (string.IsNullOrEmpty(patToken))
{
throw new Exception($"patToken '{patTokenName}' not found in key vault");
}
Expand Down Expand Up @@ -76,7 +76,7 @@ public async Task<DeploymentFrequencyModel> GetGitHubDeploymentFrequency(bool ge
clientSecretName = SecretsProcessing.CleanKey(clientSecretName);
string clientId = Configuration[clientIdName];
string clientSecret = Configuration[clientSecretName];
if (string.IsNullOrEmpty(clientId) == true | string.IsNullOrEmpty(clientSecret) == true)
if (string.IsNullOrEmpty(clientId) || string.IsNullOrEmpty(clientSecret))
{
throw new Exception($"clientId '{clientId}' or clientSecret '{clientSecret}' not found in key vault");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public async Task<LeadTimeForChangesModel> GetAzureDevOpsLeadTimeForChanges(bool
string patTokenName = PartitionKeys.CreateAzureDevOpsSettingsPartitionKeyPatToken(organization, project, repository);
patTokenName = SecretsProcessing.CleanKey(patTokenName);
string patToken = Configuration[patTokenName];
if (string.IsNullOrEmpty(patToken) == true)
if (string.IsNullOrEmpty(patToken))
{
throw new Exception($"patToken '{patTokenName}' not found in key vault");
}
Expand Down Expand Up @@ -77,7 +77,7 @@ public async Task<LeadTimeForChangesModel> GetGitHubLeadTimeForChanges(bool getS
clientSecretName = SecretsProcessing.CleanKey(clientSecretName);
string clientId = Configuration[clientIdName];
string clientSecret = Configuration[clientSecretName];
if (string.IsNullOrEmpty(clientId) == true | string.IsNullOrEmpty(clientSecret) == true)
if (string.IsNullOrEmpty(clientId) || string.IsNullOrEmpty(clientSecret))
{
throw new Exception($"clientId '{clientId}' or clientSecret '{clientSecret}' not found in key vault");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public async Task<int> UpdateAzureDevOpsPullRequests(
string patTokenName = PartitionKeys.CreateAzureDevOpsSettingsPartitionKeyPatToken(organization, project, repository);
patTokenName = SecretsProcessing.CleanKey(patTokenName);
string patToken = Configuration[patTokenName];
if (string.IsNullOrEmpty(patToken) == true)
if (string.IsNullOrEmpty(patToken))
{
throw new Exception($"patToken '{patTokenName}' not found in key vault");
}
Expand Down Expand Up @@ -74,7 +74,7 @@ public async Task<int> UpdateGitHubActionPullRequests(
clientSecretName = SecretsProcessing.CleanKey(clientSecretName);
string clientId = Configuration[clientIdName];
string clientSecret = Configuration[clientSecretName];
if (string.IsNullOrEmpty(clientId) == true | string.IsNullOrEmpty(clientSecret) == true)
if (string.IsNullOrEmpty(clientId) || string.IsNullOrEmpty(clientSecret))
{
throw new Exception($"clientId '{clientId}' or clientSecret '{clientSecret}' not found in key vault");
}
Expand Down Expand Up @@ -110,7 +110,7 @@ public async Task<int> UpdateAzureDevOpsPullRequestCommits(
string patTokenName = PartitionKeys.CreateAzureDevOpsSettingsPartitionKeyPatToken(organization, project, repository);
patTokenName = SecretsProcessing.CleanKey(patTokenName);
string patToken = Configuration[patTokenName];
if (string.IsNullOrEmpty(patToken) == true)
if (string.IsNullOrEmpty(patToken))
{
throw new Exception($"patToken '{patTokenName}' not found in key vault");
}
Expand Down Expand Up @@ -148,7 +148,7 @@ public async Task<int> UpdateGitHubActionPullRequestCommits(
clientSecretName = SecretsProcessing.CleanKey(clientSecretName);
string clientId = Configuration[clientIdName];
string clientSecret = Configuration[clientSecretName];
if (string.IsNullOrEmpty(clientId) == true | string.IsNullOrEmpty(clientSecret) == true)
if (string.IsNullOrEmpty(clientId) || string.IsNullOrEmpty(clientSecret))
{
throw new Exception($"clientId '{clientId}' or clientSecret '{clientSecret}' not found in key vault");
}
Expand Down
2 changes: 1 addition & 1 deletion src/DevOpsMetrics.Tests/Core/AzureMonitorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public async Task AzureMonitorProcessingTest()
bool result = await da.UpdateDevOpsMonitoringEventInStorage(tableStorageConfig, monitoringEvent);

//Assert
Assert.IsTrue(result == true);
Assert.IsTrue(result);
}
}
}
2 changes: 1 addition & 1 deletion src/DevOpsMetrics.Tests/Core/ChangeFailureRateDATests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public async Task UpdateChangeFailureRateDAIntegrationTest()
organization, project, buildName, percent, numberOfDays);

//Assert
Assert.IsTrue(result == true);
Assert.IsTrue(result);

}

Expand Down
2 changes: 1 addition & 1 deletion src/DevOpsMetrics.Tests/Core/NightlyProcessTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public async Task GitHubProcessingTest()
// owner, repo, branch, workflowName, workflowId, resourceGroupName, itemOrder, showSetting);

// //Assert
// Assert.IsTrue(result == true);
// Assert.IsTrue(result);
//}


Expand Down
8 changes: 4 additions & 4 deletions src/DevOpsMetrics.Tests/Core/SettingsDATests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public async Task AzUpdateSamLearnsAzureSettingDAIntegrationTest()
organization, project, repository, branch, buildName, buildId, resourceGroupName, itemOrder, showSetting);

//Assert
Assert.IsTrue(result == true);
Assert.IsTrue(result);
}

[TestMethod]
Expand All @@ -104,7 +104,7 @@ public async Task GHUpdateDevOpsMetricsSettingDAIntegrationTest()
owner, repo, branch, workflowName, workflowId, resourceGroupName, itemOrder, showSetting);

//Assert
Assert.IsTrue(result == true);
Assert.IsTrue(result);
}

[TestMethod]
Expand All @@ -127,7 +127,7 @@ public async Task GHUpdateSamsFeatureFlagsSettingDAIntegrationTest()
owner, repo, branch, workflowName, workflowId, resourceGroupName, itemOrder, showSetting);

//Assert
Assert.IsTrue(result == true);
Assert.IsTrue(result);
}

[TestMethod]
Expand All @@ -150,7 +150,7 @@ public async Task GHUpdateAzurePipelinesToGitHubActionsConverterWebSettingDAInte
owner, repo, branch, workflowName, workflowId, resourceGroupName, itemOrder, showSetting);

//Assert
Assert.IsTrue(result == true);
Assert.IsTrue(result);
}

}
Expand Down
6 changes: 0 additions & 6 deletions src/DevOpsMetrics.Web/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -481,19 +481,13 @@ public async Task<IActionResult> Logs(string projectId = null)
};
foreach (AzureDevOpsSettings item in azureDevOpsSettings)
{
//if (item.ShowSetting == true)
//{
string partitionKey = PartitionKeys.CreateAzureDevOpsSettingsPartitionKey(item.Organization, item.Project, item.Repository);
projects.Add(new KeyValuePair<string, string>(partitionKey, item.Project));
//}
}
foreach (GitHubSettings item in githubSettings)
{
//if (item.ShowSetting == true)
//{
string partitionKey = PartitionKeys.CreateGitHubSettingsPartitionKey(item.Owner, item.Repo);
projects.Add(new KeyValuePair<string, string>(partitionKey, item.Repo));
//}
}

List<ProjectLog> logs = new();
Expand Down
4 changes: 2 additions & 2 deletions src/DevOpsMetrics.Web/Services/ServiceAPIClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,10 @@ private static async Task<T> GetResponse<T>(HttpClient client, string url)
Console.WriteLine("Running url: " + client.BaseAddress.ToString() + url);
using (HttpResponseMessage response = await client.GetAsync(url))
{
if (response.IsSuccessStatusCode == true)
if (response.IsSuccessStatusCode)
{
string responseBody = await response.Content.ReadAsStringAsync();
if (string.IsNullOrEmpty(responseBody) == false)
if (!string.IsNullOrEmpty(responseBody))
{
obj = JsonConvert.DeserializeObject<T>(responseBody);
}
Expand Down
Loading

0 comments on commit 75df416

Please sign in to comment.