using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Linq;
using System.Net.Http;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace Bootstrap.Admin.Controllers.Api
{
///
///
///
[Route("api/[controller]/[action]")]
[ApiController]
[AllowAnonymous]
public class GiteeController : ControllerBase
{
///
///
///
///
///
///
///
///
///
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();
var content = await client.GetStringAsync($"https://gitee.com/{userName}/{repoName}/issues");
var regex = Regex.Matches(content, "([\\d]+)
", RegexOptions.IgnoreCase);
var labels = new string[] { "open", "closed", "rejected" };
var result = regex.Select((m, i) => $"{labels[i]} {m.Groups[1].Value}");
return new JsonResult(new { schemaVersion = 1, label, message = string.Join(" ", result), color });
}
///
///
///
///
///
///
///
///
///
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();
var content = await client.GetStringAsync($"https://gitee.com/{userName}/{repoName}/pulls");
var regex = Regex.Matches(content, "([\\d]+)
", RegexOptions.IgnoreCase);
var labels = new string[] { "open", "merged", "closed" };
var result = regex.Select((m, i) => $"{labels[i]} {m.Groups[1].Value}");
return new JsonResult(new { schemaVersion = 1, label, message = string.Join(" ", result), color });
}
///
///
///
///
///
///
///
///
///
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();
var content = await client.GetStringAsync($"https://gitee.com/{userName}/{repoName}/releases");
var regex = Regex.Match(content, $"", RegexOptions.IgnoreCase);
var result = regex.Groups[1].Value;
return new JsonResult(new { schemaVersion = 1, label, message = result, color });
}
///
///
///
///
///
///
///
///
///
public async Task Builds([FromServices]IHttpClientFactory httpClientFactory, [FromQuery]string userName = "ArgoZhang", [FromQuery]string projName = "bootstrapadmin", [FromQuery]string label = "custom badge", [FromQuery]string color = "orange")
{
var client = httpClientFactory.CreateClient();
var content = await client.GetAsJsonAsync($"https://ci.appveyor.com/api/projects/{userName}/{projName}");
return new JsonResult(new { schemaVersion = 1, label, message = content.Build.Version, color });
}
///
///
///
private class AppveyorBuildResult
{
///
///
///
public Build Build { get; set; }
}
///
///
///
private class Build
{
///
///
///
public string Version { get; set; }
}
}
}