Skip to content

Commit

Permalink
Merge pull request #845 from DeveloperMetrics/ReallySmallNumbersFix
Browse files Browse the repository at this point in the history
Adding Azure DevOps to nightly processing
  • Loading branch information
samsmithnz authored May 23, 2023
2 parents f13cfd4 + 361d7b2 commit c26aa46
Show file tree
Hide file tree
Showing 30 changed files with 330 additions and 190 deletions.
2 changes: 1 addition & 1 deletion GitVersion.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
next-version: 1.7.0
next-version: 1.8.0
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
Expand Down Expand Up @@ -397,10 +398,18 @@ public async Task<bool> UpdateProjectLogInStorage(TableStorageConfiguration tabl
}

public static async Task<bool> UpdateDORASummaryItem(TableStorageConfiguration tableStorageConfig,
string owner, string repo, DORASummaryItem DORASummaryItem)
string owner, string project, string repo, DORASummaryItem DORASummaryItem)
{
string partitionKey = owner;
string rowKey = repo;
string rowKey = "";
if (project != null)
{
rowKey = project;
}
else
{
rowKey = repo;
}
string json = JsonConvert.SerializeObject(DORASummaryItem);
AzureStorageTableModel newItem = new(partitionKey, rowKey, json);
TableStorageCommonDA tableDA = new(tableStorageConfig.StorageAccountConnectionString, tableStorageConfig.TableDORASummaryItem);
Expand Down
37 changes: 11 additions & 26 deletions src/DevOpsMetrics.Function/NightlyProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
using DevOpsMetrics.Core.Models.AzureDevOps;
using DevOpsMetrics.Core.Models.Common;
using DevOpsMetrics.Core.Models.GitHub;
//using DevOpsMetrics.Service;
//using DevOpsMetrics.Service.Controllers;
using Microsoft.Azure.KeyVault;
using Microsoft.Azure.Services.AppAuthentication;
using Microsoft.Azure.WebJobs;
Expand Down Expand Up @@ -48,45 +46,32 @@ public static async Task Run(
string clientId = Configuration["AppSettings:GitHubClientId"];
string clientSecret = Configuration["AppSettings:GitHubClientSecret"];
AzureTableStorageDA azureTableStorageDA = new();
//SettingsController settingsController = new(Configuration, azureTableStorageDA);
//DORASummaryController doraSummaryController = new(Configuration);
List<AzureDevOpsSettings> azSettings = await serviceApiClient.GetAzureDevOpsSettings();
List<GitHubSettings> ghSettings = await serviceApiClient.GetGitHubSettings();
//TableStorageConfiguration tableStorageConfig = Common.GenerateTableStorageConfiguration(Configuration);

//Loop through each setting to update the runs, pull requests and pull request commits
int numberOfDays = 30;
int maxNumberOfItems = 20;
int totalResults = 0;
foreach (AzureDevOpsSettings item in azSettings)
foreach (AzureDevOpsSettings azSetting in azSettings)
{
// (int, string) buildsUpdated = (0, null);
// (int, string) prsUpdated = (0, null);
// try
// {
log.LogInformation($"Processing Azure DevOps organization {item.Organization}, project {item.Project}");
// buildsUpdated = await api.UpdateAzureDevOpsBuilds(item.Organization, item.Project, item.Repository, item.Branch, item.BuildName, item.BuildId, numberOfDays, maxNumberOfItems);
// prsUpdated = await api.UpdateAzureDevOpsPullRequests(item.Organization, item.Project, item.Repository, numberOfDays, maxNumberOfItems);
// log.LogInformation($"Processed Azure DevOps organization {item.Organization}, project {item.Project}. {buildsUpdated.Item1} builds and {prsUpdated.Item1} prs/commits updated");
// totalResults += buildsUpdated.Item1 + prsUpdated.Item1;
// await api.UpdateAzureDevOpsProjectLog(item.Organization, item.Project, item.Repository, buildsUpdated.Item1, prsUpdated.Item1, buildsUpdated.Item2, prsUpdated.Item2, null, null);
// }
// catch (Exception ex)
// {
// string error = $"Exception while processing Azure DevOps organization {item.Organization}, project {item.Project}. {buildsUpdated.Item1} builds and {prsUpdated.Item1} prs/commits updated";
// log.LogInformation(error);
// await api.UpdateAzureDevOpsProjectLog(item.Organization, item.Project, item.Repository, buildsUpdated.Item1, prsUpdated.Item1, buildsUpdated.Item2, prsUpdated.Item2, ex.Message, error);
// }
log.LogInformation($"Processing Azure DevOps organization {azSetting.Organization}, project {azSetting.Project}");
ProcessingResult ghResult = await serviceApiClient.UpdateDORASummaryItem(
azSetting.Organization, azSetting.Project, azSetting.Repository,
azSetting.Branch, azSetting.BuildName, azSetting.BuildId,
azSetting.ProductionResourceGroup,
numberOfDays, maxNumberOfItems, false);
totalResults = ghResult.TotalResults;
}

foreach (GitHubSettings ghSetting in ghSettings)
{

log.LogInformation($"Processing GitHub owner {ghSetting.Owner}, repo {ghSetting.Repo}");
ProcessingResult ghResult = await serviceApiClient.UpdateDORASummaryItem(
ghSetting.Owner, ghSetting.Repo, ghSetting.Branch,
ghSetting.Owner, "", ghSetting.Repo, ghSetting.Branch,
ghSetting.WorkflowName, ghSetting.WorkflowId,
ghSetting.ProductionResourceGroup,
numberOfDays, maxNumberOfItems);
numberOfDays, maxNumberOfItems, true);
totalResults = ghResult.TotalResults;
}
log.LogInformation($"C# Timer trigger function complete at: {DateTime.Now} after updating {totalResults} records");
Expand Down
9 changes: 7 additions & 2 deletions src/DevOpsMetrics.Function/ServiceApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using DevOpsMetrics.Core.Models.Common;
using DevOpsMetrics.Core.Models.GitHub;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;

namespace DevOpsMetrics.Function
Expand Down Expand Up @@ -38,9 +39,13 @@ public async Task<List<GitHubSettings>> GetGitHubSettings()
return await GetResponse<List<GitHubSettings>>(Client, url);
}

public async Task<ProcessingResult> UpdateDORASummaryItem(string owner, string repository, string branch, string workflowName, string workflowId, string resourceGroup, int numberOfDays, int maxNumberOfItems)
public async Task<ProcessingResult> UpdateDORASummaryItem(
string owner, string project, string repository,
string branch, string workflowName, string workflowId,
string resourceGroup, int numberOfDays, int maxNumberOfItems,
bool isGitHub = true)
{
string url = $"/api/DORASummary/UpdateDORASummaryItem?owner={owner}&repository={repository}&branch={branch}&workflowName={workflowName}&workflowId={workflowId}&resourceGroup={resourceGroup}&numberOfDays={numberOfDays}&maxNumberOfItems={maxNumberOfItems}";
string url = $"/api/DORASummary/UpdateDORASummaryItem?owner={owner}&project={project}&repository={repository}&branch={branch}&workflowName={workflowName}&workflowId={workflowId}&resourceGroup={resourceGroup}&numberOfDays={numberOfDays}&maxNumberOfItems={maxNumberOfItems}&log=&useCache=true&isGitHub={isGitHub}";
return await GetResponse<ProcessingResult>(Client, url);
}

Expand Down
Loading

0 comments on commit c26aa46

Please sign in to comment.