From 6de2b520da5b2a9316bcf4c7b04da620c32a304e Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Fri, 14 Jun 2019 20:52:13 +0800 Subject: [PATCH] =?UTF-8?q?refactor(Gitee):=20=E5=A2=9E=E5=8A=A0=E8=B6=85?= =?UTF-8?q?=E6=97=B6=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bootstrap.Admin/Controllers/Api/GiteeController.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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();