diff --git a/Bootstrap.Admin/Controllers/Api/GiteeController.cs b/Bootstrap.Admin/Controllers/Api/GiteeController.cs index 0c8ed856..f4a58511 100644 --- a/Bootstrap.Admin/Controllers/Api/GiteeController.cs +++ b/Bootstrap.Admin/Controllers/Api/GiteeController.cs @@ -4,6 +4,7 @@ using System; using System.Linq; using System.Net.Http; using System.Text.RegularExpressions; +using System.Threading; using System.Threading.Tasks; namespace Bootstrap.Admin.Controllers.Api @@ -29,6 +30,7 @@ namespace Bootstrap.Admin.Controllers.Api public async Task Issues([FromServices]IHttpClientFactory httpClientFactory, [FromQuery]string userName = "LongbowEnterprise", [FromQuery]string repoName = "BootstrapAdmin", [FromQuery]string label = "custom badge", [FromQuery]string color = "orange") { var client = httpClientFactory.CreateClient(); + client.Timeout = TimeSpan.FromMilliseconds(2000); var ret = await GetJsonAsync(() => client.GetStringAsync($"https://gitee.com/{userName}/{repoName}/issues"), content => { var regex = Regex.Matches(content, "
([\\d]+)
", RegexOptions.IgnoreCase); @@ -52,6 +54,7 @@ namespace Bootstrap.Admin.Controllers.Api public async Task Pulls([FromServices]IHttpClientFactory httpClientFactory, [FromQuery]string userName = "LongbowEnterprise", [FromQuery]string repoName = "BootstrapAdmin", [FromQuery]string label = "custom badge", [FromQuery]string color = "orange") { var client = httpClientFactory.CreateClient(); + client.Timeout = TimeSpan.FromMilliseconds(2000); var ret = await GetJsonAsync(() => client.GetStringAsync($"https://gitee.com/{userName}/{repoName}/pulls"), content => { var regex = Regex.Matches(content, "
([\\d]+)
", RegexOptions.IgnoreCase); @@ -75,6 +78,7 @@ namespace Bootstrap.Admin.Controllers.Api public async Task Releases([FromServices]IHttpClientFactory httpClientFactory, [FromQuery]string userName = "LongbowEnterprise", [FromQuery]string repoName = "BootstrapAdmin", [FromQuery]string label = "custom badge", [FromQuery]string color = "orange") { var client = httpClientFactory.CreateClient(); + client.Timeout = TimeSpan.FromMilliseconds(2000); var ret = await GetJsonAsync(() => client.GetStringAsync($"https://gitee.com/{userName}/{repoName}/releases"), content => { var regex = Regex.Match(content, $"", RegexOptions.IgnoreCase); @@ -97,7 +101,7 @@ namespace Bootstrap.Admin.Controllers.Api public async Task Builds([FromServices]IHttpClientFactory httpClientFactory, [FromQuery]string userName = "ArgoZhang", [FromQuery]string projName = "bootstrapadmin", [FromQuery]string branchName = "master", [FromQuery]string label = "custom badge", [FromQuery]string color = "orange") { var client = httpClientFactory.CreateClient(); - var ret = await GetJsonAsync(() => client.GetAsJsonAsync($"https://ci.appveyor.com/api/projects/{userName}/{projName}/branch/{branchName}"), content => + var ret = await GetJsonAsync(() => client.GetAsJsonAsync($"https://ci.appveyor.com/api/projects/{userName}/{projName}/branch/{branchName}", null, new CancellationTokenSource(2000).Token), content => { return content == null ? "unknown" : content.Build.Version; }); @@ -106,7 +110,7 @@ namespace Bootstrap.Admin.Controllers.Api private async static Task GetJsonAsync(Func> requestUrl, Func callback) { - var ret = "unreachable"; + var ret = "unresponsive"; try { var resq = await requestUrl();