Skip to content

Commit df71ce2

Browse files
authored
Merge pull request #857 from DeveloperMetrics/AddRefreshLinkToWebsite
Add refresh link to website to troubleshoot slow processing
2 parents 186f2d8 + 5d54979 commit df71ce2

File tree

4 files changed

+117
-8
lines changed

4 files changed

+117
-8
lines changed

src/DevOpsMetrics.Web/Controllers/HomeController.cs

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using System.Diagnostics;
34
using System.Linq;
45
using System.Threading.Tasks;
56
using DevOpsMetrics.Core.DataAccess.TableStorage;
67
using DevOpsMetrics.Core.Models.AzureDevOps;
78
using DevOpsMetrics.Core.Models.Common;
89
using DevOpsMetrics.Core.Models.GitHub;
10+
using DevOpsMetrics.Service.Controllers;
911
using DevOpsMetrics.Web.Models;
1012
using DevOpsMetrics.Web.Services;
1113
using Microsoft.AspNetCore.Mvc;
1214
using Microsoft.AspNetCore.Mvc.Rendering;
15+
using Microsoft.CodeAnalysis;
1316
using Microsoft.Extensions.Configuration;
17+
using NuGet.Protocol;
1418

1519
namespace DevOpsMetrics.Web.Controllers
1620
{
@@ -23,18 +27,73 @@ public HomeController(IConfiguration configuration)
2327
Configuration = configuration;
2428
}
2529

26-
public async Task<IActionResult> Index()
30+
public async Task<IActionResult> Index(string projectId = null, string log = null)
2731
{
2832
//Get a list of settings
2933
ServiceApiClient serviceApiClient = new(Configuration);
3034
List<AzureDevOpsSettings> azureDevOpsSettings = await serviceApiClient.GetAzureDevOpsSettings();
3135
List<GitHubSettings> githubSettings = await serviceApiClient.GetGitHubSettings();
3236

3337
//Return the resultant list
34-
(List<AzureDevOpsSettings>, List<GitHubSettings>) result = (azureDevOpsSettings, githubSettings);
38+
IndexViewModel result = new()
39+
{
40+
AzureDevOpsSettings = azureDevOpsSettings,
41+
GitHubSettings = githubSettings,
42+
ProjectId = projectId,
43+
Log = log
44+
};
3545
return View(result);
3646
}
3747

48+
[HttpGet("RefreshMetric")]
49+
public async Task<IActionResult> RefreshMetric(string projectId)
50+
{
51+
ServiceApiClient serviceApiClient = new(Configuration);
52+
List<AzureDevOpsSettings> azureDevOpsSettings = await serviceApiClient.GetAzureDevOpsSettings();
53+
List<GitHubSettings> githubSettings = await serviceApiClient.GetGitHubSettings();
54+
bool foundRecord = false;
55+
string log = "";
56+
foreach (AzureDevOpsSettings item in azureDevOpsSettings)
57+
{
58+
if (item.RowKey == projectId)
59+
{
60+
foundRecord = true;
61+
DateTime startTime = DateTime.Now;
62+
await serviceApiClient.UpdateDORASummaryItem(item.Organization,
63+
item.Project, item.Repository, item.Branch,
64+
item.BuildName, item.BuildId,
65+
item.ProductionResourceGroup,
66+
30, 20, false);
67+
DateTime endTime = DateTime.Now;
68+
projectId = item.RowKey;
69+
log = $"Successfully refreshed {item.Organization} {item.Project} {item.Repository} in {(endTime - startTime).TotalSeconds} seconds";
70+
break;
71+
}
72+
}
73+
if (foundRecord == false)
74+
{
75+
foreach (GitHubSettings item in githubSettings)
76+
{
77+
if (item.RowKey == projectId)
78+
{
79+
foundRecord = true;
80+
DateTime startTime = DateTime.Now;
81+
await serviceApiClient.UpdateDORASummaryItem(item.Owner,
82+
"", item.Repo, item.Branch,
83+
item.WorkflowName, item.WorkflowId,
84+
item.ProductionResourceGroup,
85+
30, 20, true);
86+
DateTime endTime = DateTime.Now;
87+
projectId = item.RowKey;
88+
log = $"Successfully refreshed {item.Owner} {item.Repo} in {(endTime - startTime).TotalSeconds} seconds";
89+
break;
90+
}
91+
}
92+
}
93+
94+
return RedirectToAction("Index", "Home", new { projectId = projectId, log = log });
95+
}
96+
3897
[HttpPost]
3998
public IActionResult ProjectUpdate(string RowKey, int NumberOfDaysSelected = 30)
4099
{
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.Collections.Generic;
2+
using DevOpsMetrics.Core.Models.AzureDevOps;
3+
using DevOpsMetrics.Core.Models.GitHub;
4+
5+
namespace DevOpsMetrics.Web.Models
6+
{
7+
public class IndexViewModel
8+
{
9+
public List<AzureDevOpsSettings> AzureDevOpsSettings
10+
{
11+
get; set;
12+
}
13+
public List<GitHubSettings> GitHubSettings
14+
{
15+
get; set;
16+
}
17+
public string ProjectId
18+
{
19+
get; set;
20+
}
21+
public string Log
22+
{
23+
get; set;
24+
}
25+
}
26+
}

src/DevOpsMetrics.Web/Services/ServiceAPIClient.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,16 @@ public async Task<List<ProjectLog>> GetGitHubProjectLogs(string owner, string re
196196
return await GetResponse<List<ProjectLog>>(Client, url);
197197
}
198198

199+
public async Task<ProcessingResult> UpdateDORASummaryItem(
200+
string owner, string project, string repository,
201+
string branch, string workflowName, string workflowId,
202+
string resourceGroup, int numberOfDays, int maxNumberOfItems,
203+
bool isGitHub = true)
204+
{
205+
string url = $"/api/DORASummary/UpdateDORASummaryItem?owner={owner}&project={project}&repo={repository}&branch={branch}&workflowName={workflowName}&workflowId={workflowId}&resourceGroup={resourceGroup}&numberOfDays={numberOfDays}&maxNumberOfItems={maxNumberOfItems}&log=&useCache=true&isGitHub={isGitHub}";
206+
return await GetResponse<ProcessingResult>(Client, url);
207+
}
208+
199209
private static async Task<T> GetResponse<T>(HttpClient client, string url)
200210
{
201211
T obj = default;

src/DevOpsMetrics.Web/Views/Home/Index.cshtml

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@using DevOpsMetrics.Core.Models.AzureDevOps;
22
@using DevOpsMetrics.Core.Models.Common;
33
@using DevOpsMetrics.Core.Models.GitHub;
4-
@model (List<AzureDevOpsSettings>, List<GitHubSettings>)
4+
@model IndexViewModel
55
@{
66
ViewData["Title"] = "Home Page";
77
}
@@ -22,18 +22,32 @@
2222
<div class="col-md-12">
2323
View all metrics by project
2424
<ul>
25-
@foreach (AzureDevOpsSettings item in Model.Item1)
25+
@foreach (AzureDevOpsSettings item in Model.AzureDevOpsSettings)
2626
{
2727
if (item.ShowSetting)
2828
{
29-
<li><img src="~/images/AzureDevops-icon.png" style="width:32px;" alt="Azure DevOps icon" />&nbsp; <a href="@Url.Action("Project", "Home", new { projectId = item.RowKey } )">@item.Project</a> | <a href="" style="font-size:12px">Refresh metric</a></li>
29+
<li>
30+
<img src="~/images/AzureDevops-icon.png" style="width:32px;" alt="Azure DevOps icon" />&nbsp; <a href="@Url.Action("Project", "Home", new { projectId = item.RowKey } )">@item.Project</a> | <a href="@Url.Action("RefreshMetric", "Home", new { projectId = item.RowKey } )" style="font-size:12px">Refresh metric</a>
31+
@if (item.RowKey == Model.ProjectId)
32+
{
33+
<br>
34+
<span style="font-size:12px">@Model.Log</span>
35+
}
36+
</li>
3037
}
3138
}
32-
@foreach (GitHubSettings item in Model.Item2)
39+
@foreach (GitHubSettings item in Model.GitHubSettings)
3340
{
3441
if (item.ShowSetting)
3542
{
36-
<li><img src="~/images/GitHub-icon.png" style="width:32px;" alt="GitHub icon" />&nbsp; <a href="@Url.Action("Project", "Home", new { projectId = item.RowKey })">@item.Repo</a> | <a href="" style="font-size:12px">Refresh metric</a></li>
43+
<li>
44+
<img src="~/images/GitHub-icon.png" style="width:32px;" alt="GitHub icon" />&nbsp; <a href="@Url.Action("Project", "Home", new { projectId = item.RowKey })">@item.Repo</a> | <a href="@Url.Action("RefreshMetric", "Home", new { projectId = item.RowKey } )" style="font-size:12px">Refresh metric</a>
45+
@if (item.RowKey == Model.ProjectId)
46+
{
47+
<br>
48+
<span style="font-size:12px">@Model.Log</span>
49+
}
50+
</li>
3751
}
3852
}
3953
</ul>

0 commit comments

Comments
 (0)