public async Task <List <GitHubActionsRun> > GetGitHubActionRuns(string clientId, string clientSecret, TableStorageAuth tableStorageAuth, string owner, string repo, string workflowName, string workflowId, bool useCache) { List <GitHubActionsRun> runs = new List <GitHubActionsRun>(); Newtonsoft.Json.Linq.JArray list = null; if (useCache == true) { //Get the builds from Azure storage AzureTableStorageDA daTableStorage = new AzureTableStorageDA(); list = daTableStorage.GetTableStorageItems(tableStorageAuth, tableStorageAuth.TableGitHubRuns, daTableStorage.CreateBuildWorkflowPartitionKey(owner, repo, workflowName)); } else { //Get the builds from the GitHub API GitHubAPIAccess api = new GitHubAPIAccess(); list = await api.GetGitHubActionRunsJArray(clientId, clientSecret, owner, repo, workflowId); } if (list != null) { runs = JsonConvert.DeserializeObject <List <GitHubActionsRun> >(list.ToString()); //sort the final list runs = runs.OrderBy(o => o.created_at).ToList(); } return(runs); }
public async Task <int> UpdateGitHubActionRunsInStorage(string clientId, string clientSecret, TableStorageConfiguration tableStorageConfig, string owner, string repo, string branch, string workflowName, string workflowId, int numberOfDays, int maxNumberOfItems) { GitHubAPIAccess api = new GitHubAPIAccess(); JArray items = await api.GetGitHubActionRunsJArray(clientId, clientSecret, owner, repo, workflowId); Debug.WriteLine($"{items.Count} builds found for {owner}/{repo}/{workflowName}"); int itemsAdded = 0; TableStorageCommonDA tableBuildDA = new TableStorageCommonDA(tableStorageConfig, tableStorageConfig.TableGitHubRuns); TableStorageCommonDA tableChangeFailureRateDA = new TableStorageCommonDA(tableStorageConfig, tableStorageConfig.TableChangeFailureRate); //Check each build to see if it's in storage, adding the items not in storage foreach (JToken item in items) { GitHubActionsRun build = JsonConvert.DeserializeObject <GitHubActionsRun>(item.ToString()); //Save the build information for builds if (build.status == "completed") { string partitionKey = PartitionKeys.CreateBuildWorkflowPartitionKey(owner, repo, workflowName); string rowKey = build.run_number; AzureStorageTableModel newItem = new AzureStorageTableModel(partitionKey, rowKey, item.ToString()); if (await tableBuildDA.AddItem(newItem) == true) { itemsAdded++; } //Debug.WriteLine($"Processing build {build.run_number} with items adding={itemsAdded}"); //Save the build information for change failure rate ChangeFailureRateBuild newBuild = new ChangeFailureRateBuild { Id = build.run_number, Branch = build.head_branch, BuildNumber = build.run_number, StartTime = build.created_at, EndTime = build.updated_at, BuildDurationPercent = build.buildDurationPercent, Status = build.status, Url = build.html_url }; itemsAdded += await UpdateChangeFailureRate(tableChangeFailureRateDA, newBuild, PartitionKeys.CreateBuildWorkflowPartitionKey(owner, repo, workflowName)); //Debug.WriteLine($"UpdateChangeFailureRate for build {build.run_number} with items adding={itemsAdded}"); } } Debug.WriteLine($"{items.Count} builds updated for {owner}/{repo}/{workflowName}"); return(itemsAdded); }